/* -----------------4/15/2002 10:42AM---------------- * This script is attached to all POI's in the * POI template. It waits for a message from the * spawning or mission system (whichever created * the POI) and then loads the POI's content * script. * --------------------------------------------------*/ /* -----------------4/15/2002 10:57AM---------------- * Each POI template must specify the following objvar: * * poi.script - the name of the content script. * * And may specify the following obvars: * * poi.difficulty - the difficulty rating of the poi * poi.faction - the faction type of the poi, if any * poi.factionValue - the faction value of completing the poi * poi.objective - used where a single poi script can * have multiple objectives. * --------------------------------------------------*/ inherits theme_park.poi.base; const string POI_SCRIPT = "poi.script"; // the name of the objvar in which the content script // name is stored. trigger OnAttach() { //do nothing. Wait for the message from the spawn/mission system. //temp hack: Launch thyself (remove when spawning\mission system takes over:) if (hasObjVar (self, POI_BASE_OBJECT)) { return SCRIPT_CONTINUE; } else { messageTo( self, "handle_Spawn_Setup_Complete", null, 20, isObjectPersisted( self) ); return SCRIPT_CONTINUE; } } trigger OnInitialize() { //do nothing. Wait for the message from the spawn/mission system. if (hasObjVar (self, POI_BASE_OBJECT)) { return SCRIPT_CONTINUE; } else { messageTo( self, "handle_Spawn_Setup_Complete", null, 20, isObjectPersisted( self) ); return SCRIPT_CONTINUE; } } messageHandler handle_Spawn_Setup_Complete() { if ( hasObjVar( self, "npc_lair.delayedLaunch" )) return SCRIPT_CONTINUE;//already been launched, k thx //LOG("spawning", self+" handling spawn setup complete"); if (hasObjVar (self, POI_BASE_OBJECT)) { LOG("spawning", self+" hasobjVar "+POI_BASE_OBJECT); return SCRIPT_CONTINUE; } if ( !hasObjVar( self, POI_SCRIPT) ) { LOG("spawning", self+" !hasobjVar "+POI_SCRIPT); return SCRIPT_CONTINUE; } if ( hasScript( self, "systems.spawning.spawn_template" )) { setObjVar( self, "npc_lair.delayedLaunch", true ); messageTo( self, "handleLairInRangeCheck", null, 2, false ); } else { launchPoi( self ); } return SCRIPT_CONTINUE; } void launchPoi( obj_id self ) { if (!isIdValid(self) || !hasObjVar(self, POI_SCRIPT)) { return; } string poiScript = getStringObjVar( self, POI_SCRIPT ); LOG("spawning", self+" script im looking for is "+poiScript); if ( hasScript( self, poiScript )) { LOG("spawning", self+" already got one script"); return; } setObjVar( self, POI_BASE_OBJECT, self ); LOG("spawning", self+" setObjVar"); attachScript( self, poiScript ); LOG("spawning", self+" attachScript poiscript above"); //must be attached AFTER the content script, so OnInitialize here runs first: if ( hasScript( self, POI_OBJECT_SCRIPT )) { LOG("spawning", self+" hasScirpt "+POI_OBJECT_SCRIPT); debugServerConsoleMsg( self, "WARNING: " + getName( self ) + " already has the POI OBJECT script attached. Don't." ); } else { LOG("spawning", self+" attaching Script "+POI_OBJECT_SCRIPT); attachScript( self, POI_OBJECT_SCRIPT ); } LOG("spawning", self+" returning"); } messageHandler handleLairInRangeCheck() { obj_id[] otherObjects = getAllObjectsWithTemplate(getLocation(self), 80.0f, "object/tangible/lair/npc_lair.iff"); if ( otherObjects == null || otherObjects.length < 2 ) { launchPoi( self ); } for ( int i = 0; i < otherObjects.length; i++ ) { if ( otherObjects[i] != self ) { if(hasScript(self, "systems.spawning.spawn_template")) { destroyObject( self ); return SCRIPT_CONTINUE; } else { if(hasScript(otherObjects[i], "systems.spawning.spawn_template")) { destroyObject(otherObjects[i]); } } } } launchPoi( self ); return SCRIPT_CONTINUE; } trigger OnDestroy() { if(hasObjVar(self, "objLocationReservation")) { destroyObject(getObjIdObjVar(self, "objLocationReservation")); removeObjVar(self, "objLocationReservation"); } return SCRIPT_CONTINUE; }