PDA

View Full Version : HUD Log Script?


king1hw
06-28-2012, 03:10 PM
Would this work?

using System;
using maddox.game;
using maddox.game.world;
using System.Collections.Generic;

public class Mission : AMission
{

public override void OnTrigger(int missionNumber, string shortName, bool active)
{
base.OnTrigger(missionNumber, shortName, active);

if ("Trigger2All".Equals(shortName) && active)
{
AiAction action = GamePlay.gpGetAction("Trigger2All");
if (action != null)
{
action.Do();
}
GamePlay.gpGetTrigger(shortName).Enable = false;

List<Player> players = new List<Player>();
if (GamePlay.gpPlayer() != null)
players.Add(GamePlay.gpPlayer());
if (GamePlay.gpRemotePlayers() != null)
players.AddRange(GamePlay.gpRemotePlayers());

Player[] Reds = players.FindAll(item => item.Army() == 1).ToArray();
Player[] Blues = players.FindAll(item => item.Army() == 2).ToArray();
}

if (("ScoreBlue50".Equals(shortName) && active) && (MissionTimer1M1.Elapsed.Minutes <= 58) ) //Trigger 1 Message
{
GamePlay.gpHUDLogCenter("The LW succeeded and inflicted heavy damage on Port of Dover");
GamePlay.gpGetTrigger(shortName).Enable = false;
}

if ("ScoreRed51".Equals(shortName) && active) //Trigger 1 Message
{
GamePlay.gpHUDLogCenter("The RAF inflicted heavy losses on the LW bombers");
GamePlay.gpGetTrigger(shortName).Enable = false;
}

if ("ScoreRed49".Equals(shortName) && active) //Trigger 2 Message
{
GamePlay.gpHUDLogCenter("The RAF inflicted heavy losses on the LW bombers");
GamePlay.gpGetTrigger(shortName).Enable = false;
}

if (("Trigger2ALL".Equals(shortName) && active) && (Reds.Length > 0) ) //Trigger 2 Message
{
GamePlay.gpHUDLogCenter(Reds,"German build-up over Calais plotted, heading N!", new object[] { }, 3);
GamePlay.gpGetTrigger(shortName).Enable = false;
}

}

public override void OnTickGame()
{
if (Time.tickCounter() % 864000 == 63000) // 864000 = 8 hour repeat, 63000 = 35 min delay.
{
GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/July1940_v10/Missionen/Mission2.mis");

if (Reds.Length > 0)
{
GamePlay.gpHUDLogCenter(Reds, "RAF- Fly CAP between Calais and Dover", new object[] { }, 5);
GamePlay.gpLogServer(Reds, "RAF- Fly CAP between Calais and Dover", new object[] { });
}
if (Blues.Length > 0)
{
GamePlay.gpHUDLogCenter(Blues, "LW- Meet a flight of HE111's 5000m over Calais. Escort them to Dover!", new object[] { }, 5);
GamePlay.gpLogServer(Blues, "LW- Meet a flight of HE111's 5000m over Calais.\n In appr. 10 minutes into mission! Escort them to Dover!", new object[] { });
}
}
}

//Section 4 : AI remove

public override void OnActorCreated(int missionNumber, string shortName, AiActor actor)
{
base.OnActorCreated(missionNumber, shortName, actor);
if (actor is AiGroundActor)
Timeout(3599, () =>
{
if (actor != null)
{ (actor as AiGroundActor).Destroy(); }
}
);
}

}

FG28_Kodiak
06-28-2012, 04:29 PM
No it would not to many errors :rolleyes:


I ve corrected your script:

using System;
using maddox.game;
using maddox.game.world;
using System.Collections.Generic;

public class Mission : AMission
{

public Player[] AllPlayers()
{
List<Player> players = new List<Player>();

if (!GamePlay.gpIsServerDedicated())
if (GamePlay.gpPlayer() != null)
players.Add(GamePlay.gpPlayer());

if (GamePlay.gpRemotePlayers() != null)
players.AddRange(GamePlay.gpRemotePlayers());

return players.ToArray();
}


public Player[] Red()
{
List<Player> players = new List<Player>();

if (AllPlayers() != null)
{
players.AddRange(AllPlayers());
return players.FindAll(item => item.Army() == 1).ToArray();
}
return null;
}


public Player[] Blue()
{
List<Player> players = new List<Player>();

if (AllPlayers() != null)
{
players.AddRange(AllPlayers());
return players.FindAll(item => item.Army() == 2).ToArray();
}
return null;
}


public void SendChatMessageTo(Player[] players, string msg, params object[] args)
{
if (players == null) return;

GamePlay.gpLogServer(players, msg, args);
}


public void SendScreenMessageTo(Player[] players, string msg, params object[] args)
{
if (players == null) return;

GamePlay.gpHUDLogCenter(players, msg, args);
}



public override void OnTrigger(int missionNumber, string shortName, bool active)
{
base.OnTrigger(missionNumber, shortName, active);

if ("Trigger2All".Equals(shortName) && active)
{
AiAction action = GamePlay.gpGetAction("Trigger2All");
if (action != null)
{
action.Do();
}
GamePlay.gpGetTrigger(shortName).Enable = false;
}

if ("ScoreBlue50".Equals(shortName) && active) //Trigger 1 Message
{
GamePlay.gpHUDLogCenter("The LW succeeded and inflicted heavy damage on Port of Dover");
GamePlay.gpGetTrigger(shortName).Enable = false;
}

if ("ScoreRed51".Equals(shortName) && active) //Trigger 1 Message
{
GamePlay.gpHUDLogCenter("The RAF inflicted heavy losses on the LW bombers");
GamePlay.gpGetTrigger(shortName).Enable = false;
}

if ("ScoreRed49".Equals(shortName) && active) //Trigger 2 Message
{
GamePlay.gpHUDLogCenter("The RAF inflicted heavy losses on the LW bombers");
GamePlay.gpGetTrigger(shortName).Enable = false;
}

if ("Trigger2ALL".Equals(shortName) && active) //Trigger 2 Message
{
SendScreenMessageTo(Red(), "German build-up over Calais plotted, heading N!");
GamePlay.gpGetTrigger(shortName).Enable = false;
}

}

public override void OnTickGame()
{
if (Time.tickCounter()%864000 == 63000) // 864000 = 8 hour repeat, 63000 = 35 min delay.
{
GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/July1940_v10/Missionen/Mission2.mis");

SendScreenMessageTo(Red(), "RAF- Fly CAP between Calais and Dover");
SendChatMessageTo(Red(), "RAF- Fly CAP between Calais and Dover");

SendScreenMessageTo(Blue(), "LW- Meet a flight of HE111's 5000m over Calais. Escort them to Dover!");
SendChatMessageTo(Blue(), "LW- Meet a flight of HE111's 5000m over Calais. Escort them to Dover!");
}

}

//Section 4 : AI remove

public override void OnActorCreated(int missionNumber, string shortName, AiActor actor)
{
base.OnActorCreated(missionNumber, shortName, actor);
if (actor is AiGroundActor)
Timeout(3599, () =>
{
if (actor != null)
{
(actor as AiGroundActor).Destroy();
}
}
);
}

}


Explanations:

with AllPlayers() you get all players in the game.
with Red() only the red players.
with Blue() only the blue.

if created two method
public void SendChatMessageTo(Player[] players, string msg, params object[] args)
and
public void SendScreenMessageTo(Player[] players, string msg, params object[] args)

the first sends the message to the chat window and the second to the screen, to use them use:

to all players in game
SendChatMessageTo(AllPlayers(), "Your Message");
to the red side
SendChatMessageTo(Red(), "Your Message");
to the blue side:
SendChatMessageTo(Blue(), "Your Message");

if you would like to show variables, points for example you can use:
int redpoints = 50;
SendChatMessageTo(Red(), "Red Side gets {0} points", redpoints);

btw in the string {0} is a placeholder for the first variable, {1} for the second, {2} for the third and so on..
you should take care that the number of placeholders and the number of the variables are the same.
For example this will work:
SendChatMessageTo(Red(), "Red Side gets {0}/{1} points", redpoints, overallPoints);

this will also work, but the value of the second variable is not shown
SendChatMessageTo(Red(), "Red Side gets {0} points", redpoints, overallPoints);

but this will get an error:
SendChatMessageTo(Red(), "Red Side gets {0}/{1} points", redpoints);

hope it helps ;)