mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-08-03 03:15:55 -04:00
43 lines
1.2 KiB
Plaintext
43 lines
1.2 KiB
Plaintext
include library.utils;
|
|
include library.create;
|
|
|
|
//change to OnInitialize for live:
|
|
trigger OnInitialize()
|
|
{
|
|
//convert the obj_id set via console to a real obj_id:
|
|
respawnNpc( self );
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
messageHandler handleNpcRespawn()
|
|
{
|
|
obj_id messageFrom = params.getObjId( "object" );
|
|
obj_id lastSpawned = getObjIdObjVar( self, "pathing.lastSpawned" );
|
|
if ( messageFrom != lastSpawned )
|
|
return SCRIPT_CONTINUE;
|
|
|
|
respawnNpc( self );
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
void respawnNpc( obj_id self )
|
|
{
|
|
if (!hasObjVar( self, "npc" ))
|
|
return;
|
|
|
|
string creatureName = getStringObjVar( self, "npc" );
|
|
obj_id npc = create.object( creatureName, getLocation( self ) );
|
|
if ( !isIdValid(npc) )
|
|
{
|
|
debugServerConsoleMsg( self, "WARNING: city/city_pathing: could not spawn " + creatureName );
|
|
debugServerConsoleMsg( self, "WARNING: city/city_pathing: bad creatureName on " + self + " at " + getLocation( self ) );
|
|
return;
|
|
}
|
|
setObjVar( self, "pathing.lastSpawned", npc );
|
|
create.addDestroyMessage( npc, "handleNpcRespawn", 60.0f, self );
|
|
utils.setScriptVar( npc, "pathing.currentStop", self );
|
|
utils.setScriptVar( npc, "pathing.homeStop", self );
|
|
attachScript( npc, "city.city_pathing_npc" );
|
|
}
|
|
|