#1
|
|||
|
|||
Scripting help needed
I need help with a couple of scripts for the stats/server manager program I am working on.
1st I need to check every 5 seconds to see of there is any commands in the queue to be processed. I have the queue stuff setup, just need the timing stuff. This is what I have so far based on examples I have seen, but it needs the timer number correctly: Code:
public override void OnTickGame() { if (Time.tickCounter() % 5000 == 50) { if (stats != null ) { newCmds = stats.getCommands(); if (newCmds.Count > 0) ProcessCommands(newCmds); } } } Code:
private void ProcessCommands(List<ServerCommand> newCmds) { try { foreach (ServerCommand sc in newCmds) { if (sc.CommandType.Equals("HUDmsg")) { if (sc.ToWho.Equals("All")) GamePlay.gpHUDLogCenter(sc.Command); else if (sc.ToWho.Equals("Red")) // Send message to Red Team ???? else if (sc.ToWho.Equals("Blue")) // Send message to Blue team ??? else { // Message is for a specific player based on player name in string sc.ToWho ???? } } } } catch (Exception ex) { System.Console.WriteLine("Stats.ProcessCommands - Exception: " + ex); } } WildWillie |
#2
|
|||
|
|||
Code:
int armyPlayer = GamePlay.gpPlayer().Army(); int armyRed = 1; int armyBlue = 2; Code:
namespace maddox.game { public interface Player { int Army(); // Player army bool AutopilotPrimary(); bool AutopilotSecondary(); int Channel(); string ConnectAddress(); int ConnectPort(); bool IsConnected(); bool IsExpelArmy(int army); bool IsExpelUnit(AiActor unit); string LanguageName(); string Name(); AiPerson PersonPrimary(); AiPerson PersonSecondary(); int Ping(); AiActor Place(); void PlaceEnter(AiActor actor, int indxPlace); void PlaceLeave(int indxPlace); int PlacePrimary(); int PlaceSecondary(); void SelectArmy(int army); } public interface IGamePlay { AiActor gpActorByName(string actorName); bool gpActorIsValid(AiActor actor); AiAirGroup gpAiAirGroup(int ID, int army); AiAirGroup[] gpAirGroups(int Army); AiAirport[] gpAirports(); int[] gpArmies(); //All armies string gpArmyName(int army); void gpAviPlay(string args); bool gpBattleIsRun(); void gpBattleStop(); AiBirthPlace[] gpBirthPlaces(); ISectionFile gpConfigUserFile(); ISectionFile gpCreateSectionFile(); ISectionFile gpCreateSectionFile(string line, out string firstWord); DifficultySetting gpDifficultyGet(); IRecalcPathParams gpFindPath(Point2d a, double ra, Point2d b, double rb, PathType type, int army); int gpFrontArmy(double x, double y); double gpFrontDistance(int army, double x, double y); bool gpFrontExist(); AiAction gpGetAction(string name); AiTrigger gpGetTrigger(string name); AiGroundGroup[] gpGroundGroups(int Army); void gpHUDLogCenter(string msg); void gpHUDLogCenter(Player[] to, string msg); void gpHUDLogCenter(Player[] to, string msg, object[] parms); void gpHUDLogCenter(Player[] to, string msg, object[] parms, double lifeTime); object[] gpInvoke(object[] args); bool gpIsServerDedicated(); bool gpIsServerSingle(); bool gpIsValidAccess(); LandTypes gpLandType(double x, double y); ISectionFile gpLoadSectionFile(string fileName); void gpLogServer(Player[] to, string format, object[] args); void gpLogServerArg(bool newArg, string format, object[] parms); void gpLogServerBegin(Player[] to, string format); void gpLogServerEnd(); AiAirGroup gpMakeAirGroup(AiAircraft[] items, AiAirWayPoint[] way); int gpNextMissionNumber(); Player gpPlayer(); void gpPostMissionLoad(ISectionFile file); void gpPostMissionLoad(string fileName); Player[] gpRemotePlayers(); string gpSectorName(double x, double y); void gpSetOrderMissionMenu(Player player, bool thisSubMenu, int ID, string[] keys, bool[] bSubMenu); ITime gpTime(); } } |
#3
|
|||
|
|||
@wildwillie:
To send a message to a specific army (1 red, 2 blue, -1 to all) Code:
private void sendScreenMessageTo(int army, string msg, object[] parms) { List<Player> Players = new List<Player>(); // on Dedi the server or for singleplayertesting if (GamePlay.gpPlayer() != null) { if (GamePlay.gpPlayer().Army() == army || army == -1) Players.Add(GamePlay.gpPlayer()); } if (GamePlay.gpRemotePlayers() != null || GamePlay.gpRemotePlayers().Length > 0) { foreach (Player p in GamePlay.gpRemotePlayers()) { if (p.Army() == army || army == -1) Players.Add(p); } } if (Players != null && Players.Count > 0) GamePlay.gpHUDLogCenter(Players.ToArray(), msg, parms); } private void sendChatMessageTo(int army, string msg, object[] parms) { List<Player> Players = new List<Player>(); // on Dedi the server: if (GamePlay.gpPlayer() != null) { if (GamePlay.gpPlayer().Army() == army || army == -1) Players.Add(GamePlay.gpPlayer()); } //rest of the crowd if (GamePlay.gpRemotePlayers() != null || GamePlay.gpRemotePlayers().Length > 0) { foreach (Player p in GamePlay.gpRemotePlayers()) { if (p.Army() == army || army == -1) Players.Add(p); } } if (Players != null && Players.Count > 0) GamePlay.gpLogServer(Players.ToArray(), msg, parms); } sendChatMessageTo send the message to the chat to use following sends a HudMessage "Hello red" to red Army sendScreenMessageTo(1, "Hello red", null); to all sendScreenMessageTo(-1, "Hello all", null); if you want show values etc. you can use int redpoints = 100; //example value sendScreenMessageTo(1, "Hello red, you have {0} points", new object[]{ redpoints}); so red gets the message "Hello red, you have 100 points" to a specific player: Code:
private void sendChatMessageTo(Player player, string msg, object[] parms) { if (player != null) GamePlay.gpLogServer(new Player[] { player }, msg, parms); } private void sendScreenMessageTo(Player player, string msg, object[] parms) { if (player != null) GamePlay.gpHUDLogCenter(new Player[] { player }, msg, parms); } for timing i use Stopwatch from.net, ontickgame is not very exact. example: Code:
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using maddox.game; using maddox.game.world; public class Mission : AMission { Stopwatch MissionTimer = new Stopwatch(); public override void OnBattleStarted() { base.OnBattleStarted(); MissionTimer.Start(); // start the stopwatch } public override void OnTickGame() { base.OnTickGame(); if (MissionTimer.Elapsed.TotalSeconds >= 50) // 50 seconds { MissionTimer.Restart(); // stopwatch reset to 0 and restart // Do something } } } Last edited by FG28_Kodiak; 12-10-2011 at 05:32 PM. |
#4
|
|||
|
|||
Another solution, based on the example above
Code:
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using maddox.game; using maddox.game.world; public class Mission : AMission { /// <summary> /// Returns a list of all users /// </summary> private List<Player> GetPlayers() { var result = new List<Player>(); if (GamePlay.gpRemotePlayers() != null) { result.AddRange(GamePlay.gpRemotePlayers()); } if (GamePlay.gpPlayer() != null) { result.Add(GamePlay.gpPlayer()); } return result; } /// <summary> /// Returns a list of all users of specified army /// </summary> private List<Player> GetPlayers(int army) { return (army < 0) ? GetPlayers() : GetPlayers().FindAll(player => player.Army().Equals(army)); } /// <summary> /// Sends a message to the screens of all users of specified army /// </summary> private void BroadcastScreenMessage(int army, string format, params object[] args) { GamePlay.gpHUDLogCenter(GetPlayers(army).ToArray(), format, args); } /// <summary> /// Sends a message to the logs of all users of specified army /// </summary> private void BroadcastLogMessage(int army, string format, params object[] args) { GamePlay.gpLogServer(GetPlayers(army).ToArray(), format, args); } public override void OnBattleStarted() { base.OnBattleStarted(); BroadcastScreenMessage(1, "Your army color: {0}, your side: {1}", "Red", "Allies"); BroadcastScreenMessage(2, "Your army color: {0}, your side: {1}", "Blue", "Axis"); BroadcastLogMessage(1, "Big group of german {0} heading to {1}.", "Bombers", "London"); BroadcastLogMessage(2, "Group of our {0} need to cover in their raid to {1}, rendezvous point at sector {2}.", "Heinkels", "London", "G9"); } } |
#5
|
|||
|
|||
Thank you for the quick replys. I'll work them in later this weekend.
|
|
|