mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-31 00:15:54 -04:00
161 lines
4.3 KiB
Plaintext
161 lines
4.3 KiB
Plaintext
include library.space_utils;
|
|
include library.planetary_map;
|
|
include library.create;
|
|
include library.objvar_mangle;
|
|
include library.utils;
|
|
include java.lang.Math;
|
|
include library.hue;
|
|
|
|
// npc spawner
|
|
|
|
trigger OnInitialize()
|
|
{
|
|
requestPreloadCompleteTrigger(self);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnPreloadComplete()
|
|
{
|
|
//LOG("spawn", "ONINTIAILIZE");
|
|
string strTest = ""+self;
|
|
|
|
location locTest = getLocation(self);
|
|
string strPlanet = locTest.area;
|
|
|
|
dictionary dctSpawnInfo = dataTableGetRow("datatables/spawning/ground_spawning/static/"+strPlanet+".iff", strTest);
|
|
|
|
if(dctSpawnInfo==null)
|
|
{
|
|
//LOG("space", "NO ENTRY FOR "+self);
|
|
obj_id objTest = createObject("object/tangible/gravestone/gravestone01.iff", getLocation(self));
|
|
setName(objTest, "BAD NPC SPAWNER IS HERE!, NO ENTRY IN Ground SPawning "+strPlanet+" NPC SPAWNERS DATATABLE");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
// are we spawning a type or a specific
|
|
string strType = dctSpawnInfo.getString("strType");
|
|
string strMob = dctSpawnInfo.getString("strMob");
|
|
string strName = dctSpawnInfo.getString("strName");
|
|
//LOG("spawn", "strName Raw is "+strName);
|
|
|
|
float fltMinSpawnTime= dctSpawnInfo.getFloat("fltMinSpawnTime");
|
|
float fltMaxSpawnTime = dctSpawnInfo.getFloat("fltMaxSpawnTime");
|
|
|
|
resizeable string[] strScripts = new string[0];
|
|
string strMobToSpawn = "";
|
|
if(strType!="")
|
|
{
|
|
string strFileName = "datatables/spawning/ground_spawning/types/"+strType+".iff";
|
|
string[] strSpawnList = dataTableGetStringColumnNoDefaults(strFileName, "strItem");
|
|
if((strSpawnList==null)||(strSpawnList.length==0))
|
|
{
|
|
obj_id objTest = createObject("object/tangible/gravestone/gravestone01.iff", getLocation(self));
|
|
setName(objTest, "for object "+self+" bad entry of "+strType+" and planet "+strPlanet);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
utils.setScriptVar(self, "strSpawnList", strSpawnList);
|
|
}
|
|
else
|
|
{
|
|
string[] strSpawnList = new string[1];
|
|
strSpawnList[0] = strMob;
|
|
utils.setScriptVar(self, "strSpawnList", strSpawnList); // for later use
|
|
}
|
|
for(int intI = 1; intI<5; intI++)
|
|
{
|
|
string strScript= dctSpawnInfo.getString("strScript"+intI);
|
|
if(strScript!="")
|
|
{
|
|
strScripts = utils.addElement(strScripts, strScript);
|
|
}
|
|
}
|
|
if(strScripts.length>0)
|
|
{
|
|
utils.setScriptVar(self, "strScripts", strScripts);
|
|
}
|
|
|
|
if(strType!="")
|
|
{
|
|
utils.setScriptVar(self, "strName", "");
|
|
}
|
|
else
|
|
{
|
|
utils.setScriptVar(self, "strName", strName);
|
|
}
|
|
utils.setScriptVar(self, "fltMinSpawnTime", fltMinSpawnTime);
|
|
utils.setScriptVar(self, "fltMaxSpawnTime", fltMaxSpawnTime);
|
|
makeMob(self);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
|
|
void makeMob(obj_id self)
|
|
{
|
|
location locTest = getLocation(self);
|
|
string strPlanet = locTest.area;
|
|
|
|
string[] strSpawnList = utils.getStringArrayScriptVar(self, "strSpawnList");
|
|
string[] strScripts = utils.getStringArrayScriptVar(self, "strScripts");
|
|
string strName = utils.getStringScriptVar(self, "strName");
|
|
//LOG("spawn", "Name is "+strName);
|
|
float fltMinSpawnTime = utils.getFloatScriptVar(self, "fltMinSpawnTime");
|
|
float fltMaxSpawnTime = utils.getFloatScriptVar(self, "fltMaxSpawnTime");
|
|
string strMob = strSpawnList[rand(0, strSpawnList.length-1)];
|
|
obj_id objNPC = null;
|
|
|
|
boolean spawnFailed = false;
|
|
|
|
try
|
|
{
|
|
objNPC = create.object(strMob, getLocation(self));
|
|
}
|
|
catch (Throwable err)
|
|
{
|
|
spawnFailed = true;
|
|
}
|
|
|
|
if (!isIdValid(objNPC) || spawnFailed)
|
|
{
|
|
locTest.x = locTest.x+1;
|
|
obj_id objTest = createObject("object/tangible/gravestone/gravestone01.iff", locTest);
|
|
setName(objTest, "For "+self.toString()+" Bad NPC Type of type "+strMob+" on planet "+ strPlanet);
|
|
return;
|
|
}
|
|
|
|
setYaw(objNPC, getYaw(self));
|
|
//LOG("spawn", "Name is "+strName);
|
|
if(strName!="")
|
|
{
|
|
//LOG("spawn", "Setting Name");
|
|
setName(objNPC, "");
|
|
setName(objNPC, strName);
|
|
}
|
|
if((strScripts!=null)&&(strScripts.length>0))
|
|
{
|
|
for(int intI = 0; intI < strScripts.length; intI++)
|
|
{
|
|
if(strScripts[intI]!="")
|
|
{
|
|
if(!hasScript(objNPC, strScripts[intI]))
|
|
{
|
|
attachScript(objNPC, strScripts[intI]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//LOG("spawn", "ATTACHING to "+objNPC);
|
|
|
|
attachScript(objNPC, "systems.spawning.mob_spawn_tracker");
|
|
//LOG("spawn","intReturn is "+intReturn);
|
|
utils.setScriptVar(objNPC, "objParent", self);
|
|
utils.setScriptVar(objNPC, "fltRespawnTime", rand(fltMinSpawnTime, fltMaxSpawnTime));
|
|
return;
|
|
}
|
|
|
|
messageHandler respawnMob()
|
|
{
|
|
makeMob(self);
|
|
return SCRIPT_CONTINUE;
|
|
}
|