View Single Post
  #3  
Old 12-10-2011, 04:09 PM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

@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);
    }
sendScreenMessageTo is for HUD messages
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.
Reply With Quote