include library.create; include library.ai_lib; include library.city; include library.utils; const boolean TRAINERS_OFF = true; //------------------------------------------------ // OnInitialize //------------------------------------------------ trigger OnInitialize() { if ( TRAINERS_OFF ) { return SCRIPT_CONTINUE; } string spawn = getStringObjVar( self, "spawns" ); if ( spawn == null ) return SCRIPT_OVERRIDE; if ( getIntObjVar( self, "city_id" ) > 0 ) city.validateSpecialStructure( self ); messageTo( self, "spawnTrainer", null, 1.f, false ); return SCRIPT_CONTINUE; } //------------------------------------------------ // OnDestroy //------------------------------------------------ trigger OnDestroy() { if ( getIntObjVar( self, "city_id" ) > 0 ) { obj_id trainer = utils.getObjIdScriptVar( self, "trainer" ); destroyObject( trainer ); city.removeSkillTrainer( self ); } return SCRIPT_CONTINUE; } //------------------------------------------------ // OnUnloadedFromMemory // // This will prevent duplicate skill trainers by unloading the trainers when the spawner unloads // A code solution is still in progress, but should give us what we need. - cmayer //------------------------------------------------ trigger OnUnloadedFromMemory() { if ( getIntObjVar( self, "city_id" ) > 0 ) { obj_id trainer = utils.getObjIdScriptVar( self, "trainer" ); destroyObject( trainer ); utils.removeScriptVar( self, "trainer" ); } return SCRIPT_CONTINUE; } //------------------------------------------------ // spawnTrainer //------------------------------------------------ messageHandler spawnTrainer() { if ( utils.hasScriptVar( self, "trainer" ) ) return SCRIPT_CONTINUE; string spawn = getStringObjVar( self, "spawns" ); if ( spawn == null ) return SCRIPT_OVERRIDE; if(!isTrainerAllowed(spawn)) { return SCRIPT_CONTINUE; } obj_id trainer = create.object( spawn, getLocation(self) ); if ( trainer == null || !isIdValid( trainer ) ) { obj_id creator = getObjIdObjVar( self, "creator" ); sendSystemMessage( creator, new string_id( "city/city", "st_fail" ) ); destroyObject( self ); return SCRIPT_CONTINUE; } setInvulnerable( trainer, true ); setCreatureStatic( trainer, true ); ai_lib.setDefaultCalmBehavior( trainer, ai_lib.BEHAVIOR_SENTINEL ); if ( getIntObjVar( self, "city_id" ) > 0 ) { setYaw( trainer, getYaw( self ) ); setObjVar( trainer, "spawner", self ); utils.setScriptVar( self, "trainer", trainer ); attachScript( trainer, "npc.skillteacher.civic_skillteacher" ); //setName( self, spawn ); string spawn_r = "st" + spawn.substring( spawn.indexOf('_'), spawn.length() ); //setName( self, new string_id( "city/city", spawn_r ) ); } return SCRIPT_CONTINUE; } //------------------------------------------------ // requestDestroy //------------------------------------------------ messageHandler requestDestroy() { obj_id trainer = utils.getObjIdScriptVar( self, "trainer" ); destroyObject( trainer ); destroyObject( self ); return SCRIPT_CONTINUE; } boolean isTrainerAllowed(string strTrainer) { if(utils.checkConfigFlag("ScriptFlags","noEliteTrainers")) { string[] strAllowedTrainers = { "trainer_artisan", "trainer_brawler", "trainer_entertainer", "trainer_marksman", "trainer_medic", "trainer_scout" }; for(int intI = 0; intI < strAllowedTrainers.length; intI++) { string strTest = strAllowedTrainers[intI]; // just in case that fucking preprocessor bug hits if(strTrainer.equals(strTest)) { return true; } } return false; } return true; }