Files
dsrc/sku.0/sys.server/compiled/game/script/city/droid_spawner.script
T

173 lines
3.2 KiB
Plaintext

include library.create;
include library.utils;
include library.locations;
trigger OnAttach()
{
messageTo (self, "checkForStart", null, 30, true);
return SCRIPT_CONTINUE;
}
trigger OnInitialize()
{
if (hasObjVar (self, "current"))
{
killAll(self);
messageTo (self, "checkForStart", null, 30, true);
}
else
{
messageTo (self, "checkForStart", null, 30, true);
}
return SCRIPT_CONTINUE;
}
trigger OnHearSpeech(obj_id speaker, string text)
{
if ( !hasObjVar (speaker, "gm"))
{
return SCRIPT_OVERRIDE;
}
int stringCheck = text.indexOf("max");
string population = text.substring( text.indexOf(" ")+1, text.length() );
int maxPop = utils.stringToInt (population);
if (stringCheck > -1)
{
setObjVar (self, "pop", maxPop);
}
if (text == "killall")
{
killAll(self);
}
if (text == "restart")
{
messageTo (self, "startSpawning", null, 1, true);
}
return SCRIPT_CONTINUE;
}
messageHandler checkForStart()
{
if (hasObjVar (self, "pop"))
{
messageTo (self, "startSpawning", null, 10, true);
return SCRIPT_CONTINUE;
}
else
{
setObjVar (self, "pop", 3);
messageTo (self, "checkForStart", null, 30, true);
return SCRIPT_CONTINUE;
}
}
messageHandler startSpawning ()
{
obj_id spawner = getSelf();
int maxPop = getIntObjVar (self, "pop");
if (!hasObjVar (self, "current"))
{
setObjVar (self, "current", 1);
doSpawn(self);
}
else
{
int currentPop = getIntObjVar (self, "current");
if (currentPop <= maxPop)
{
doSpawn(self);
}
else
{
return SCRIPT_OVERRIDE;
}
}
return SCRIPT_CONTINUE;
}
void doSpawn (obj_id self)
{
int currentPop = getIntObjVar (self, "current");
int maxPop = getIntObjVar (self, "pop");
location me = getLocation(self);
location here = locations.getGoodLocationAroundLocation(me, 1f, 1f, 1.5f, 1.5f);
if (here == null)
{
debugServerConsoleMsg (self, "droid_spawner couldn't find a good location!");
return;
}
if (here == null)
{
debugServerConsoleMsg (self, "droid_spawner couldn't find a good location!");
return;
}
string spawn = npcToSpawn();
obj_id npc = create.object (spawn, here);
attachScript (npc, "city.droid_wander");
setInvulnerable(npc, true);
setObjVar (self, "spawn." + currentPop, npc);
setObjVar (npc, "spawnNum", "spawn."+currentPop);
currentPop = currentPop + 1;
setObjVar (self, "current", currentPop);
messageTo (self, "startSpawning", null, 10, true);
return;
}
void killAll (obj_id self)
{
int increment = 1;
int totalBodies = getIntObjVar (self, "pop");
while (increment <= totalBodies)
{
obj_id npcToKill = getObjIdObjVar( self, "spawn." + increment);
if ( npcToKill != null )
{
destroyObject (npcToKill);
removeObjVar (self, "spawn." + increment);
}
increment = increment + 1;
}
removeObjVar (self, "current");
removeObjVar (self, "spawn");
return;
}
string npcToSpawn()
{
int choice = rand (1,6);
string spawn = "commoner";
switch (choice)
{
case 1:
spawn = "cll8_binary_load_lifter";
break;
case 2:
spawn = "eg6_power_droid";
break;
case 3:
spawn = "r2";
break;
case 4:
spawn = "r3";
break;
case 5:
spawn = "r4";
break;
case 6:
spawn = "r5";
break;
}
return spawn;
}