![]() |
|
#1
|
|||
|
|||
![]()
@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 04:32 PM. |
#2
|
|||
|
|||
![]()
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"); } } |
#3
|
|||
|
|||
![]()
Thank you for the quick replys. I'll work them in later this weekend.
|
![]() |
|
|