include library.create; include library.factions; include library.utils; include ai.ai_combat; trigger OnAttach() { utils.removeScriptVar( self, "myWarriors" ); return SCRIPT_CONTINUE; } trigger OnSpeaking( string txt ) { if ( txt.equals("go") ) { if (!utils.hasScriptVar( self, "myWarriors" )) { spawnGroup( self, "group1", 20 ); spawnGroup( self, "group2", -20 ); } else { debugSpeakMsg( self, "already going" ); } } else if ( txt.equals("fight") ) { startFight( self ); } else if ( txt.equals("stop") ) { killWarriors( self ); } return SCRIPT_CONTINUE; } void spawnGroup( obj_id chris, string group, int offset ) { resizeable obj_id[] warriors = new obj_id[0]; if ( utils.hasScriptVar( chris, "myWarriors" )) warriors = utils.getResizeableObjIdArrayScriptVar( chris, "myWarriors" ); location groupLoc = new location( getLocation( chris )); groupLoc.x += offset; for ( int i = 0; i < 50; i++ ) { obj_id npc = create.object( "pirate", groupLoc ); warriors = utils.addElement( warriors, npc ); factions.setFaction( npc, group ); } utils.setScriptVar( chris, "myWarriors", warriors ); } void killWarriors( obj_id chris ) { if ( !utils.hasScriptVar( chris, "myWarriors") ) { debugSpeakMsg( chris, "none spawned" ); return; } obj_id[] warriors = utils.getObjIdArrayScriptVar( chris, "myWarriors" ); if ( warriors.length < 100 ) { debugSpeakMsg( chris, "not done spawning yet " + warriors.length ); return; } for ( int i = 0; i < warriors.length; i++ ) { if ( exists( warriors[i] )) { destroyObject( warriors[i] ); } } utils.removeScriptVar( chris, "myWarriors" ); } void startFight( obj_id chris ) { if ( !utils.hasScriptVar( chris, "myWarriors") ) { debugSpeakMsg( chris, "no warriors" ); return; } obj_id[] warriors = utils.getObjIdArrayScriptVar( chris, "myWarriors" ); if ( warriors.length < 100 ) { debugSpeakMsg( chris, "not done spawning yet" ); return; } for ( int i = 0; i < 50; i++ ) { if ( exists( warriors[i] ) && exists( warriors[i+50] ) ) { //factions.setFaction( warriors[i], factions.FACTION_IMPERIAL ); //factions.setFaction( warriors[i+50], factions.FACTION_REBEL ); startCombat( warriors[i], warriors[i+50] ); } } }