Files
dsrc/sku.0/sys.server/compiled/game/script/working/jfreeman/creaturetest.script
T
2013-09-10 23:17:15 -07:00

89 lines
2.6 KiB
Plaintext

include library.utils;
include library.create;
const string CREATURE_TABLE = "datatables/mob/creatures.iff";
trigger OnAttach()
{
debugSpeakMsg( self, "attached" );
return SCRIPT_CONTINUE;
}
trigger OnSpeaking( string text )
{
if ( text.equals( "creaturetest" ) )
{
if ( utils.hasScriptVar( self, "creatureTest" ))
{
debugSpeakMsg( self, "creaturetest is already running" );
return SCRIPT_CONTINUE;
}
int startTime = getGameTime();
debugSpeakMsg( self, "beginning creatureTest " + startTime );
utils.setScriptVar( self, "startTime", startTime );
utils.setScriptVar( self, "creatureTest", 0 );
LOG( "creaturetest", "BEGIN " + startTime );
messageTo( self, "spawnNextCreature", null, 1, false );
}
else if ( text.equals( "creaturetest stop" ) )
utils.removeScriptVar( self, "creatureTest" );
return SCRIPT_CONTINUE;
}
messageHandler spawnNextCreature()
{
if ( !utils.hasScriptVar( self, "creatureTest" ))
return SCRIPT_CONTINUE;
int creatureNum = utils.getIntScriptVar( self, "creatureTest" );
int numRows = dataTableGetNumRows (CREATURE_TABLE);
if ( creatureNum >= numRows )
{
int startTime = utils.getIntScriptVar( self, "startTime");
debugSpeakMsg( self, "creaturetest " + startTime + " is DONE" );
utils.removeScriptVar( self, "creatureTest" );
utils.removeScriptVar( self, "startTime" );
LOG( "creaturetest", "END " + startTime );
return SCRIPT_CONTINUE;
}
string creatureName = dataTableGetString(CREATURE_TABLE, creatureNum, "creatureName");
if ( creatureName == "" || creatureName == null )
return SCRIPT_CONTINUE;
debugServerConsoleMsg( self, "CREATURE NAME IS " + creatureName + " - NUMBER: " + creatureNum );
utils.setScriptVar( self, "lastCreature", creatureName );
location spawnLoc = getLocation( self );
spawnLoc.x += 2;
spawnLoc.z += 2;
obj_id creature = create.object( creatureName, spawnLoc, false );
if ( !isIdValid(creature))
{
string templateName = dataTableGetString(CREATURE_TABLE, creatureName, "template");
LOG( "creaturetest", "UNABLE TO CREATE " + creatureName + " WITH TEMPLATE " + templateName + "DOES THIS TEMPLATE EXIST?");
LOG( "creaturetest", creatureName + ":" + templateName );
}
else
{
destroyObject( creature );
}
creatureNum++;
utils.setScriptVar( self, "creatureTest", creatureNum );
messageTo( self, "spawnNextCreature", null, 1, false );
return SCRIPT_CONTINUE;
}
trigger OnImmediateLogout()
{
string creatureName = utils.getStringScriptVar( self, "lastCreature" );
if ( creatureName != null )
{
LOG( "creaturetest", "CLIENT FATAL " + creatureName );
debugServerConsoleMsg(self, "CLIENT FATAL " + creatureName );
}
return SCRIPT_CONTINUE;
}