// This script contains useful utility scripts for performing common actions. if( Util == null ) { // Store it neatly under a global table. global Util = table(); /////////////////////////////////////////////////////////////////////////////// Util.MakeRGBA = function(r, g, b, a) { assert( typeName(r) == "int" ); assert( typeName(g) == "int" ); assert( typeName(b) == "int" ); // alpha is optional alpha = 255; if(a) { assert( typeName(a) == "int" ); alpha = a; } return (((alpha)<<24) | ((b)<<16) | ((g)<<8) | (r)); }; /////////////////////////////////////////////////////////////////////////////// Util.WaypointAutoSaveInfo = table(); Util.WaypointAutoSaveInfo.TimeBetweenSaves = 10; /////////////////////////////////////////////////////////////////////////////// Util.WaypointAutoSaveFunction = function(_delay) { print("Will auto-save waypoints every", _delay, "seconds."); // Loop as long as waypoint mode is on. while( IsWaypointViewOn() ) { ExecCommand( "waypoint_save" ); sleep( delay ); } print("Waypoint auto saving disabled."); }; /////////////////////////////////////////////////////////////////////////////// Util.EnableWaypointAutoSave = function( _enable, _time ) { if( _enable ) { // Default time between saves. Change this value if you want the save duration something different. timeBetweenSaves = 10.0; print("Executing my waypoint function"); ExecCommand("waypoint_view 1"); Util.WaypointAutoSaveInfo.SaveThreadId = thread( Util.WaypointAutoSaveFunction, _time ); } else { // Kill the thread if it exists, and null the if( Util.WaypointAutoSaveInfo.SaveThread != null ) { threadKill( Util.WaypointAutoSaveInfo.SaveThreadId ); Util.WaypointAutoSaveInfo.SaveThreadId = null; } } }; /////////////////////////////////////////////////////////////////////////////// // Util.GetPlayerEntity = function() { playerEnt = 0; if ( !GetEntityName( 0 ) ) { playerEnt = 1; } return playerEnt; }; /////////////////////////////////////////////////////////////////////////////// // Util.GetMapGoalPosition = function( _params ) { Goalname = _params; Goal = GetGoal( Goalname ); if ( Goal ) { GoalPos = Goal.GetPosition(); if ( GoalPos == Vector3( 0.0, 0.0, 0.0 ) ) { GoalEnt = Goal.GetEntity(); EntPos = GetEntPosition( GoalEnt ); if ( EntPos != GoalPos ) { GoalPos = EntPos; } } return GoalPos; } else { print("Util.GetMapGoalPosition: No such goal"); return null; } }; /////////////////////////////////////////////////////////////////////////////// // Util.WithinRange = function( bot, range ) { playerEnt = Util.GetPlayerEntity(); playerPos = GetEntPosition( playerEnt ); botPos = bot.GetPosition(); while ( bot.DistanceTo( playerPos ) > range ) { playerPos = GetEntPosition( playerEnt ); yield(); } return; }; /////////////////////////////////////////////////////////////////////////////// // Util.AddBotKickWhenDead = function( team, class, name ) { AddBot( team, class, name ); sleep( 1 ); bot = Util.GetBotPointer( name ); bot.AddSignalThread(threadId(), false); block( EVENT.DEATH ); KickBot( name ); }; /////////////////////////////////////////////////////////////////////////////// // Util.IsBotGone = function( name ) { foreach ( id and bot in BotTable ) { if ( bot.Name == name ) { return false; } } return true; }; /////////////////////////////////////////////////////////////////////////////// // Util.WaitUntilBotGone = function( name ) { bot_gone = false; while( !bot_gone ) { if ( Util.Skip ) { return; } foreach ( id and bot in BotTable ) { if ( bot.Name == name ) { bot_gone = false; break; } bot_gone = true; } yield(); } }; /////////////////////////////////////////////////////////////////////////////// // Util.WaitUntilBotSpawned = function( name ) { bot_spawned = false; while( !bot_spawned ) { foreach ( id and bot in BotTable ) { if ( bot.Name == name ) { bot_spawned = true; break; } bot_spawned = false; } yield(); } }; /////////////////////////////////////////////////////////////////////////////// // Util.GetWpNamePosition = function( _params ) { WpName = _params; wptable = table(); Wp = Wp.GetWaypointByName( WpName, wptable ); if ( Wp ) { return wptable.position; } else { print("Util.GetWpNamePosition: No such goal"); return null; } }; /////////////////////////////////////////////////////////////////////////////// // Util.WaitForPlayerSpawn = function() { sleep( 1 ); // Wait for player playerEnt = Util.GetPlayerEntity(); playerPos = GetEntPosition( playerEnt ); while ( !playerPos || playerPos == Vector3( 0.0, 0.0, 0.0 ) ) { sleep( 1 ); playerPos = GetEntPosition( playerEnt ); } return playerPos; }; /////////////////////////////////////////////////////////////////////////////// // Util.BotTurnToPosition = function( bot, Pos ) { while ( !bot.TurnToPosition( Pos ) ) { yield(); } }; /////////////////////////////////////////////////////////////////////////////// // Util.BotTurnToPlayer = function( bot ) { Pos = GetEntPosition( Util.GetPlayerEntity() ); Util.BotTurnToPosition( bot, Pos ); }; /////////////////////////////////////////////////////////////////////////////// // Util.GetWPPoss = function( wps ) { wpPoss = table(); foreach ( index and wp in wps ) { wpPoss[ index ] = Util.GetWpNamePosition( wp ); } return wpPoss; }; /////////////////////////////////////////////////////////////////////////////// // Util.Distance = function( Pos1, Pos2 ) { return ( Pos2 - Pos1 ).Length(); }; /////////////////////////////////////////////////////////////////////////////// // Util.GetClosestWP = function( entPos, wp1, wp2 ) { wp1Pos = Util.GetWpNamePosition( wp1 ); dist1 = Util.Distance( entPos, wp1Pos ); wp2Pos = Util.GetWpNamePosition( wp2 ); dist2 = Util.Distance( entPos, wp2Pos ); if ( dist1 < dist2 ) { return wp1; } else { return wp2; } }; /////////////////////////////////////////////////////////////////////////////// // Util.GetClosestRoute = function( entPos, route1, route2 ) { route1Pos = Util.GetWpNamePosition( route1[ 0 ] ); dist1 = Util.Distance( entPos, route1Pos ); route2Pos = Util.GetWpNamePosition( route2[ 0 ] ); dist2 = Util.Distance( entPos, route2Pos ); if ( dist1 < dist2 ) { return route1; } else { return route2; } }; /////////////////////////////////////////////////////////////////////////////// // Util.GetClosestRouteToPlayer = function( route1, route2 ) { playerPos = GetEntPosition( Util.GetPlayerEntity() ); route = Util.GetClosestRoute( playerPos, route1, route2 ); return route; }; /////////////////////////////////////////////////////////////////////////////// // Util.BotWaitAndSay = function( bot, time, dialog ) { if ( time ) { sleep( time ); } bot.Say( dialog ); }; /////////////////////////////////////////////////////////////////////////////// // Util.BotSayAndWait = function( bot, dialog, time ) { bot.Say( dialog ); if ( time ) { sleep( time ); } }; /////////////////////////////////////////////////////////////////////////////// // Util.AddBotInstructor = function( team, class, name ) { // Kick any previous bots KickAll(); sleep( 1 ); // Add Instructor bot AddBot(team, class, name); bot = Util.GetBotPointer( name ); bot.AddSignalThread(threadId(), false); bot.SetScriptControlled(true); sleep( 2 ); return bot; }; /////////////////////////////////////////////////////////////////////////////// // Util.WithinBounds = function( entPos, minx, miny, maxx, maxy ) { if ( entPos.x < minx || entPos.x > maxx || entPos.y < miny || entPos.y > maxy ) { return false; } return true; }; /////////////////////////////////////////////////////////////////////////////// // Util.DialogOff = false; /////////////////////////////////////////////////////////////////////////////// // Util.Dialog = function( bot, paragraph, time ) { if ( Util.DialogOff ) { return; } foreach ( index and sentence in paragraph ) { if ( Util.Skip ) { return; } Util.BotSayAndWait( bot, sentence, time ); } }; /////////////////////////////////////////////////////////////////////////////// // Util.FollowWaypoints = function( bot, waypoints, range ) { if ( Util.Skip ) { return; } Util.WithinRange( bot, range ); if ( Util.Skip ) { return; } wpPoss = Util.GetWPPoss( waypoints ); start = 0; end = tableCount( waypoints ); botPos = bot.GetPosition(); for ( i = 0 ; i < end - 1 ; i = i + 1 ) { dist1 = Util.Distance( botPos, wpPoss[ start ] ); dist2 = Util.Distance( botPos, wpPoss[ i + 1 ] ); if ( dist2 < dist1 ) { start = i + 1; } } //~ foreach ( index and waypoint in waypoints ) for ( i = start ; i < end ; i = i + 1 ) { mapPos =wpPoss[ i ]; botFacing = GetEntFacing( 2 ); bot.GoTo( mapPos, botFacing ); if ( block(EVENT.GOAL_SUCCESS, EVENT.GOAL_FAILED) == EVENT.GOAL_FAILED ) { print(GetMapName(), "_training: follow route: ", waypoints[ i ], " failed" ); return 0; } if ( Util.Skip ) { return; } Util.WithinRange( bot, range ); if ( Util.Skip ) { return; } } }; /////////////////////////////////////////////////////////////////////////////// // Util.PatrolStatus = false; /////////////////////////////////////////////////////////////////////////////// // Util.Patrol = function( bot, waypoints, time, startdelay ) { if ( startdelay ) { for ( i = 0 ; i < startdelay ; i = i + 1 ) { if ( Util.Skip ) { break; } sleep( 1 ); } } wpPoss = Util.GetWPPoss( waypoints ); Util.PatrolStatus = true; vec = Vector3(); bot.AddSignalThread(); numfailures = 0; while ( Util.PatrolStatus ) { foreach ( index and mapPos in wpPoss ) { if ( !Util.PatrolStatus ) { break; } bot.GoTo( mapPos, vec.ZERO ); if ( block(EVENT.GOAL_SUCCESS, EVENT.GOAL_FAILED) == EVENT.GOAL_FAILED ) { numfailures = numfailures + 1; if ( numfailures > 2 ) { print(GetMapName(), "_training: bot: ", bot, " patrol wp: ", index + 1, " failed" ); //~ return; } yield(); continue; } else { numfailures = 0; } if ( !Util.PatrolStatus ) { break; } if ( tableCount( wpPoss ) == 1 ) { bot.ClearWatchEntity(); Util.PatrolOff( bot ); } sleep( time ); } } bot.RemoveSignalThread(); }; /////////////////////////////////////////////////////////////////////////////// // Util.PatrolOff = function( bot ) { Util.PatrolStatus = false; bot.ResetSubGoals(); }; /////////////////////////////////////////////////////////////////////////////// // Util.GetBotPointer = function( name ) { foreach ( id and bot in BotTable ) { if ( bot.Name == name ) { return bot; } } return null; }; /////////////////////////////////////////////////////////////////////////////// // Util.GetBotId = function( name ) { foreach ( id and bot in BotTable ) { if ( bot.Name == name ) { return id; } } return null; }; /////////////////////////////////////////////////////////////////////////////// // Util.BotDebug = false; Util.EnableBotDebug = function( status ) { print( "Enabling debug console" ); Util.BotDebug = status; }; /////////////////////////////////////////////////////////////////////////////// // Util.Skip = false; Util.SetSkip = function() { Util.Skip = true; }; /////////////////////////////////////////////////////////////////////////////// // Util.ResetSkip = function() { Util.Skip = false; }; /////////////////////////////////////////////////////////////////////////////// // Util.StartAllBots = function() { foreach ( id and bot in BotTable ) { bot.SetScriptControlled(false); bot.SetScriptControlledWeapons( false ); bot.EnableItemUse( true ); bot.RemoveSignalThread(); } }; /////////////////////////////////////////////////////////////////////////////// // Util.StopAllBots = function() { foreach ( id and bot in BotTable ) { bot.AddSignalThread(threadId(), false); bot.SetScriptControlled(true); bot.SetScriptControlledWeapons( true ); bot.EnableItemUse( false ); bot.ResetSubGoals(); } }; /////////////////////////////////////////////////////////////////////////////// // Util.ResetTeamClassGoals = function( teamtable, classtable ) { foreach ( index1 and team in teamtable ) { foreach ( index2 and class in classtable ) { foreach ( gameId and bot in BotTable ) { if ( bot && ( bot.GetTeam() == team ) && ( bot.GetClass() == class ) ) { bot.ResetSubGoals(); } } } } }; /////////////////////////////////////////////////////////////////////////////// // Util.ResetTeamGoals = function( team ) { foreach ( gameId and bot in BotTable ) { if ( bot ) { if ( bot.GetTeam() == team ) { bot.ResetSubGoals(); } } } }; /////////////////////////////////////////////////////////////////////////////// // Util.ResetGoals = function() { foreach ( gameId and bot in BotTable ) { if ( bot ) { bot.ResetSubGoals(); } } }; /////////////////////////////////////////////////////////////////////////////// // Util.SetBiasTeamClassGoal = function( team, class, goal, value ) { foreach ( gameId and bot in BotTable ) { if ( bot ) { if ( bot.GetTeam() == team ) { if ( bot.GetClass() == class ) { bot.SetGoalProperty( goal, "Bias", value ); } } } } }; /////////////////////////////////////////////////////////////////////////////// // Util.SetPropertyTeamClassGoal = function( property, team, class, goal, value ) { foreach ( gameId and bot in BotTable ) { if ( bot ) { if ( bot.GetTeam() == team ) { if ( bot.GetClass() == class ) { bot.SetGoalProperty( goal, property, value ); } } } } }; /////////////////////////////////////////////////////////////////////////////// // Util.SetMaxUsersAttacking = function( Users, GoalNames ) { Goals = table(); GetGoals( Goals, 0, GoalNames ); foreach ( index and Goal in Goals ) { Goal.MaxUsers_Attacking( Users ); } }; /////////////////////////////////////////////////////////////////////////////// // Util.SetMaxUsersDefending = function( Users, GoalNames ) { Goals = table(); GetGoals( Goals, 0, GoalNames ); foreach ( index and Goal in Goals ) { Goal.MaxUsers_Defending( Users ); } }; /////////////////////////////////////////////////////////////////////////////// // Util.SetGoalOffset = function( x, y, z, GoalName ) { Goal = GetGoal( GoalName ); if(Goal) { Goal.SetPosition( Goal.GetPosition() + Vector3( x, y, z ) ); Goal.DynamicPosition = false; } }; /////////////////////////////////////////////////////////////////////////////// //deprecated Util.SetOffsetGoal = function( x, y, z, GoalName ) { Goal = GetGoal( GoalName ); if(Goal) { Goal.SetPosition( Goal.GetPosition() + Vector3( x, y, z ) ); Goal.DynamicPosition = false; } }; /////////////////////////////////////////////////////////////////////////////// // Util.SetGoalPosition = function( x, y, z, GoalName ) { Goal = GetGoal( GoalName ); if(Goal) { Goal.SetPosition( Vector3( x, y, z ) ); Goal.DynamicPosition = false; } }; /////////////////////////////////////////////////////////////////////////////// // Util.SetGoalBounds = function( bounds, GoalName ) { Goal = GetGoal( GoalName ); if(Goal) { Goal.SetBounds( bounds ); } }; /////////////////////////////////////////////////////////////////////////////// // Util.SetMaxUsersInProgress = function( Users, GoalNames ) { Goals = table(); GetGoals( Goals, 0, GoalNames ); foreach ( index and Goal in Goals ) { Goal.MaxUsers_InProgress( Users ); } }; /////////////////////////////////////////////////////////////////////////////// // Util.SetMaxUsersInUse = function( Users, GoalNames ) { Goals = table(); GetGoals( Goals, 0, GoalNames ); foreach ( index and Goal in Goals ) { Goal.MaxUsers_InUse( Users ); } }; /////////////////////////////////////////////////////////////////////////////// // Util.AddToTable = function( table1, value1 ) { table1[ tableCount( table1 ) ] = value1; }; /////////////////////////////////////////////////////////////////////////////// // Util.AddTable = function( table1, table2 ) { table1and2 = table(); table1len = tableCount( table1 ); for ( i = 0 ; i < table1len ; i = i + 1 ) { table1and2[ i ] = table1[ i ]; } table2len = tableCount( table2 ); for ( i = 0 ; i < table2len ; i = i + 1 ) { table1and2[ i + table1len ] = table2[ i ]; } return table1and2; }; /////////////////////////////////////////////////////////////////////////////// // Util.BotGoToName = function( bot, wpname, faceplayer ) { botPos = Util.GetWpNamePosition( wpname ); botFacing = Vector3( 0.0, 0.0, 0.0 ); bot.GoTo( botPos, botFacing ); if ( block(EVENT.GOAL_SUCCESS, EVENT.GOAL_FAILED) == EVENT.GOAL_FAILED ) { print("Util.BotGoToName : bot:", bot, "wpname:", wpname, " failed" ); return; } if ( faceplayer ) { Util.BotTurnToPlayer( bot ); } }; /////////////////////////////////////////////////////////////////////////////// // Util.BotGoRoute = function( bot, wpPoss, start, end, walk ) { if ( walk ) { bot.HoldButton( BTN.WALK, -1 ); } for ( index = start ; index < end ; index = index + 1 ) { if ( Util.Skip ) { break; } botFacing = Vector3( 0.0, 0.0, 0.0 ); bot.GoTo( wpPoss[ index ], botFacing ); if ( block(EVENT.GOAL_SUCCESS, EVENT.GOAL_FAILED) == EVENT.GOAL_FAILED ) { print(GetMapName(), "_training: BotGoRoute failed" ); return; } } if ( walk ) { bot.ReleaseButton( BTN.WALK ); } }; /////////////////////////////////////////////////////////////////////////////// // // This function runs an infinite loop of adding and kicking bots. It is used to illustrate // how custom script functions can be run continuously to provide custom control over // things like the number of bots. Additional behaviors like forcing bots to 1 team can be // implemented by starting a similar function to this from a custom command. Util.StressTest = function() { sleep(10.0); dowhile(1) { //DumpGlobals("globals.txt"); ran = UnitRandom(); if(ran > 0.98) { //KickAll(); } else if(ran < 0.5) { AddBot(); } else { foreach ( gameId and bot in BotTable ) { if(bot) { print(bot); KickBot(bot.Name); break; } } } // Pause for 10 seconds between loop iterations. sleep(RandRange(0.0, 3.0)); } }; /////////////////////////////////////////////////////////////////////////////// // Util.GetNearestVehicle = function( bot ) { if ( bot == null ) { return null; } Util.VehiclesInMap(); Team = bot.GetTeam(); dist = 10000.0; foreach ( vehEntity and Goal in Util.VehicleGoals ) { if ( bot.DistanceTo( vehEntity ) < dist && Goal.IsAvailable( Team ) ) { return vehEntity; } } return null; }; /////////////////////////////////////////////////////////////////////////////// // Util.IsVehicleAvailable = function( bot, entity ) { if ( bot == null ) { return null; } Util.VehiclesInMap(); if ( Util.VehicleGoals[ entity ] ) { Team = bot.GetTeam(); if ( Util.VehicleGoals[ entity ].IsAvailable( Team ) ) { return true; } } return false; }; /////////////////////////////////////////////////////////////////////////////// // Util.IsVehicleDead = function( entity ) { if ( GetEntClass(entity) == CLASS.VEHICLE_NODAMAGE ) { return false; } if ( Map && Map.InvVehicle && Map.InvVehicle[ entity ] ) { return false; } if ( GetEntFlags(entity, ENTFLAG.DEAD) ) { return true; } return false; }; /////////////////////////////////////////////////////////////////////////////// // Util.VehiclesInMap = function() { if ( Util.VehicleGoals == null ) { Util.VehicleGoals = table(); Goals = table(); GetGoals( Goals, 0, "MAP_MOVER_.*" ); foreach ( id and Goal in Goals ) { vehEntity = Goal.GetEntity(); Util.VehicleGoals[ vehEntity ] = Goal; } } if ( tableCount( Util.VehicleGoals ) ) { return true; } return false; }; /////////////////////////////////////////////////////////////////////////////// // Util.DisplayGoalThread = null; Util.NumberOfGoals = 0; Util.GoalNames = table(); Util.GoalStatuses = table(); /////////////////////////////////////////////////////////////////////////////// // Util.DisplayGoalOutput = function() { while ( true ) { for ( i = 0 ; i < Util.NumberOfGoals ; i = i + 1 ) { if ( Util.GoalStatuses[ i ] ) { GoalName = Util.GoalNames[ i ]; GoalPos = Util.GetMapGoalPosition( GoalName ); Goal = GetGoal( GoalName ); GoalEnt = Goal.GetEntity(); GoalFacing = GetEntFacing( GoalEnt ); print( GoalName, GoalPos, GoalFacing ); } } sleep( Util.NumberOfGoals ); } }; /////////////////////////////////////////////////////////////////////////////// // Util.DisplayGoal = function( goalname, status ) { if ( !Util.DisplayGoalThread ) { Util.DisplayGoalThread = thread( Util.DisplayGoalOutput ); } else { if ( !goalname ) { threadKill( Util.DisplayGoalThread ); Util.DisplayGoalThread = null; Util.NumberOfGoals = 0; return; } } if ( !status || status == "false" ) { for ( i = 0 ; i < Util.NumberOfGoals ; i = i + 1 ) { if ( Util.GoalNames[ i ] == goalname ) { Util.GoalStatuses[ i ] = false; } } return; } else { haveit = false; for ( i = 0 ; i < Util.NumberOfGoals ; i = i + 1 ) { if ( Util.GoalNames[ i ] == goalname ) { Util.GoalStatuses[ i ] = true; haveit = true; } } if ( haveit ) { return; } if ( Util.GetMapGoalPosition( goalname ) ) { Util.GoalNames[ Util.NumberOfGoals ] = goalname; Util.GoalStatuses[ Util.NumberOfGoals ] = true; Util.NumberOfGoals = Util.NumberOfGoals + 1; } } }; /////////////////////////////////////////////////////////////////////////////// // Util.KillTeam = function( team ) { foreach ( id and bot in BotTable ) { if ( bot.GetTeam() == team) { bot.ExecCommand( "kill" ); } } }; /////////////////////////////////////////////////////////////////////////////// // Util.OnTriggerPosition = function( goalname, wpname, tolerance, wpfunction ) { if ( typeId( goalname ) == 5 ) { goal = GetGoal( goalname ); } else { goal = goalname; } position = Util.GetWpNamePosition( wpname ); if ( goal && position ) { if ( typeId( goalname ) == 5 ) { entity = goal.GetEntity(); } else { entity = goal; } thread( Util.CheckForEntityAtPosition, wpname, entity, position, tolerance, wpfunction ); } }; /////////////////////////////////////////////////////////////////////////////// // Util.CheckForEntityAtPosition = function( signame, entity, position, tolerance, wpfunction ) { while ( 1 ) { entposition = GetEntPosition( entity ); distance = Distance( entposition, position ); if ( distance < tolerance ) { signal( signame ); if ( wpfunction ) { wpfunction(); } return; } yield(); } }; /////////////////////////////////////////////////////////////////////////////// // Util.UpdateSwitchData = function() { foreach ( i and switchTable in Map.Switches ) { switchTable.Waypoint = table(); if ( Wp.GetWaypointByName( switchTable.WaypointName, switchTable.Waypoint ) ) { print( "Switch Data Suceeded, Waypoint:", switchTable.WaypointName ); if ( switchTable.Waypoint.facing.IsZero() ) { print( "Error: No Facing Defined, Waypoint:", switchTable.WaypointName ); } } else { print( "Error: Switch Data Failed, Waypoint:", switchTable.WaypointName ); } } }; /////////////////////////////////////////////////////////////////////////////// // Util.BotsWithGoal = function( params ) { numbots = 0; foreach ( id and bot in BotTable ) { if ( bot.scriptgoal == params ) { numbots = numbots + 1; } } return numbots; }; /////////////////////////////////////////////////////////////////////////////// // Util.SetPositionGoal = function( goalname1, goalname2 ) { goal1 = GetGoal( goalname1 ); goal2 = GetGoal( goalname2 ); if ( !goal1 || !goal2 ) { print( "Null goal(s)", goal1, goal2 ); return; } goal1.DynamicPosition = false; goal1.DynamicBounds = false; goal1.SetPosition( goal2.GetPosition() ); return; }; /////////////////////////////////////////////////////////////////////////////// // Util.AliveCount = function ( team, class ) { count = 0; foreach ( id and bot in BotTable ) { if ( ( bot.GetTeam() == team ) && ( bot.GetClass() == class ) ) { ent = bot.GetGameEntity(); if ( !GetEntFlags( ent, ENTFLAG.DEAD ) ) { count += 1; } } } return count; }; /////////////////////////////////////////////////////////////////////////////// // Util.ShowEntityInfo = function () { playerEnt = Util.GetPlayerEntity(); eyePos = GetEntEyePosition( playerEnt ); endPos = eyePos + GetEntFacing( playerEnt ) * 1024; DrawDebugLine( eyePos, endPos, COLOR.GREEN, 20 ); tr = TraceLine( eyePos, endPos, 0, TRACE.SHOT, playerEnt, false ); if ( tr.entity == null ) { displaytime = 3; output = "No entity found"; } else { DrawEntityAABB( tr.entity, 20, COLOR.GREEN ); id = GetGameIdFromEntity( tr.entity ); s = format( "%d", id ); displaytime = 20; output = "Entity found:" + s; } print( output ); EchoToScreen( playerEnt, displaytime, output ); }; /////////////////////////////////////////////////////////////////////////////// // Util.AddUsePtFromWp = function(GoalName, wpname) { wpInfo = {}; if(Wp.GetWaypointByName(wpname, wpInfo)) { goal = GetGoal(GoalName); if(goal && wpInfo.position) { goal.AddUsePoint(wpInfo.position); } } }; /////////////////////////////////////////////////////////////////////////////// // Util.AddGoalRoute = function(goalname, startname, endname, weight) { g = GetGoal(goalname); if(g) { return g.AddRoute(startname, endname, weight); } else { print("Goal", goalname, "not found!"); } return false; }; /////////////////////////////////////////////////////////////////////////////// // Util.RouteTo = function(goalname, routepath) { nodes = routepath.Tokenize("."); numNodes = tableCount(nodes); for(i = 1; i < numNodes; i += 1) { //print("Adding Route:", nodes[i-1], nodes[i]); Util.AddGoalRoute(goalname, nodes[i-1], nodes[i]); } }; /////////////////////////////////////////////////////////////////////////////// // Util.GoalRoutes = function(goalname, startname, goalroutes) { foreach ( childname and child in goalroutes ) { if(childname != "Weight") { //print("Goal Route:", goalname, startname, childname); Util.AddGoalRoute(goalname, startname, childname, child.Weight); Util.GoalRoutes(goalname, childname, child); } } }; /////////////////////////////////////////////////////////////////////////////// // Util.Routes = function(routetable) { // Loop through all the top level nodes, these are the goal names. foreach ( goalname and goalroutes in routetable ) { foreach ( name and route in goalroutes ) { Util.GoalRoutes(goalname, name, route); } } }; /////////////////////////////////////////////////////////////////////////////// // Util.DistanceViewOn = true; /////////////////////////////////////////////////////////////////////////////// // Util.DistanceView = function() { displaytime = 5; playerEnt = Util.GetPlayerEntity(); while ( Util.DistanceViewOn ) { eyePos = GetEntEyePosition( playerEnt ); endPos = eyePos + GetEntFacing( playerEnt ) * 50000; tr = TraceLine( eyePos, endPos, 0, TRACE.SHOT, playerEnt, false ); DrawDebugLine( eyePos, tr.end, COLOR.GREEN, displaytime ); distance = Distance( eyePos, tr.end ); s = format( "%f", distance ); output = "Distance:" + s; print( output ); EchoToScreen( playerEnt, displaytime, output ); sleep( displaytime ); } }; /////////////////////////////////////////////////////////////////////////////// // Util.DefaultMovers = { "MAP_MOVER_tank", "MAP_MOVER_truck", "MAP_MOVER_train1", "MAP_MOVER_train2", "MAP_MOVER_boat", "MAP_MOVER_train", }; /////////////////////////////////////////////////////////////////////////////// // Util.ProcessMoversCalled = false; /////////////////////////////////////////////////////////////////////////////// // Util.ProcessMovers = function() { if ( Util.ProcessMoversCalled ) { return; } Util.ProcessMoversCalled = true; HaveTable = false; if ( Map && Map.ShowMovers ) { return; } Util.VehiclesInMap(); if ( Map && Map.Movers ) { HaveTable = true; } foreach ( vehEntity and Goal in Util.VehicleGoals ) { CurrentGoalName = Goal.GetName(); deletegoal = true; foreach ( id and GoalName in Util.DefaultMovers ) { if ( !CurrentGoalName.Compare( GoalName ) ) { deletegoal = false; break; } } if ( HaveTable && deletegoal ) { foreach ( id and GoalName in Map.Movers ) { if ( !CurrentGoalName.Compare( GoalName ) ) { deletegoal = false; break; } } } if ( deletegoal ) { //~ print("Deleted:", CurrentGoalName); Goal.SetRemoveFlag(true); } } Util.VehicleGoals = null; Util.VehiclesInMap(); //~ GoalTable = table(); //~ GetGoals( GoalTable, 0, "MAP_MOVER.*" ); //~ foreach ( index and Goal in GoalTable ) //~ { //~ print("GoalName:", Goal.GetName() ); //~ } }; /////////////////////////////////////////////////////////////////////////////// // Util.RemoveGoal = function( goalname ) { Goal = GetGoal( goalname ); if ( !Goal ) { print("RemoveGoal: goal:", goalname, "does not exist" ); } else { Goal.SetRemoveFlag( true ); } }; /////////////////////////////////////////////////////////////////////////////// // Util.SetGoal = function( goalname, team ) { if ( typeId( goalname ) == 0 ) { print( "SetGoal: No goal name specified" ); return; } if ( typeId( team ) == 0 ) { SetAvailableMapGoals( 1, true, goalname ); SetAvailableMapGoals( 2, true, goalname ); SetAvailableMapGoals( 3, true, goalname ); SetAvailableMapGoals( 4, true, goalname ); } else { SetAvailableMapGoals( team, true, goalname ); } }; /////////////////////////////////////////////////////////////////////////////// // Util.ClearGoal = function( goalname, team ) { if ( typeId( goalname ) == 0 ) { print( "SetGoal: No goal name specified" ); return; } if ( typeId( team ) == 0 ) { SetAvailableMapGoals( 1, false, goalname ); SetAvailableMapGoals( 2, false, goalname ); SetAvailableMapGoals( 3, false, goalname ); SetAvailableMapGoals( 4, false, goalname ); } else { SetAvailableMapGoals( team, false, goalname ); } }; /////////////////////////////////////////////////////////////////////////////// // Util.GetGoalEnt = function( goalname ) { Goal = GetGoal( goalname ); if ( !Goal ) { print("GetGoalEnt: goal:", goalname, "does not exist" ); } else { return Goal.GetEntity(); } }; }