Fulqrum Publishing Home   |   Register   |   Today Posts   |   Members   |   UserCP   |   Calendar   |   Search   |   FAQ

Go Back   Official Fulqrum Publishing forum > Fulqrum Publishing > IL-2 Sturmovik: Cliffs of Dover > FMB, Mission & Campaign builder Discussions

Reply
 
Thread Tools Display Modes
  #1  
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
  #2  
Old 12-10-2011, 08:34 PM
Octocat Octocat is offline
Approved Member
 
Join Date: Dec 2011
Posts: 22
Default

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");  
  }
}
Reply With Quote
  #3  
Old 12-10-2011, 08:50 PM
wildwillie wildwillie is offline
Approved Member
 
Join Date: Aug 2010
Posts: 111
Default

Thank you for the quick replys. I'll work them in later this weekend.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:42 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 2007 Fulqrum Publishing. All rights reserved.