PDA

View Full Version : With Mission_EventChat () script, how to prevent posting to all.



Miguel21
Jan-27-2014, 14:02
it is quite difficult to explain ...

I try to create a script where you can enter chat commands to AI. For example:

<way 65sqn AH,24 15000ft HUNTING

This would allow the 65th squadron "keep" the AH,24

It works with SetWay ()

WayPointTestAirgroup.SetWay (NewWaypoints.ToArray ());
http://forum.1cpublishing.eu/showthread.php?t=27533&highlight=SetWay


BUT ... I do not want this command appears on the enemy ...

With Mission_EventChat (), I can't block the display.
http://forum.1cpublishing.eu/showthread.php?t=34797&highlight=Mission_EventChat


And the chat box, if I write the "friend", it does not work (it works, but only if I'm alone in a dedicated server ...)


Does someone found a way to "lock" this "repetition" line?

SoW Reddog
Jan-27-2014, 17:55
I know what you're trying to do. Unfortunately I couldn't figure it out myself.

Nephilim
Jan-28-2014, 04:14
Send full code so i can see whats the problem....

Miguel21
Jan-28-2014, 15:40
This is the code

Please, no need to laugh, I'm not a programmer and I know my coding is really bad ^^.

With this code:
- start a dedicated server
- create a red plane
- write in chat:


<takeoff 64

- then, to intercept a flight of ennemi bomber, write:

<way 64 ay,23 10000ft bomber

or

<way 64 ay,23 10000ft hunting

You can also use and control all flight red, with "<sqn" command in chat gives you all numbers squadron flight

In short, this works, but not in a "chat friendly" if there are more than two players on the server....





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


//$reference parts/core/gamePlay.dll


public class Mission : AMission
{


AiAirGroup WayPointTestAirgroup;




public override void OnBattleInit()
{
base.OnBattleInit();


if (GamePlay is GameDef)
{
(GamePlay as GameDef).EventChat += new GameDef.Chat(Mission_EventChat);

}


}


public void Mission_EventChat(IPlayer from, string msg)
{
if(from.Army() == 2)
{
return;
}
string sqn = "";
string sector= "";


double curX = -1.00;

double curY = -1.00;


double sector_x = -1.00;
double sector_y = -1.00;
double[] sectorArray = new double [2];

double alti = -1.00;
string alti_str = "";
string setOrder = "";

double speed = 80.00; // m/s 80~=300km/h

string[] stringSeparators = new string[] {" "};
string[] result;

string airgroupN = "";

string sectorNameN = "" ;

string airgroup = "" ;

string airgroupAMI = "" ;

string sectorName = "" ;


List<AiWayPoint> NewWaypoints = new List<AiWayPoint>();

AiAirWayPoint aaWP;


msg = msg.ToLower();

if (msg.StartsWith("<help"))
{


Chat("// <takeoff [n°Sqn] // exemple: <takeoff 213" , from);
Chat("// <sqn // liste tous les Sqn en vol" , from);
Chat("// <way [n°Sqn] [sector] [altitude] [ordre]" , from);
Chat("//exemple: <way 213 AV,19 5000ft HUNTING" , from);


}
else if (msg.StartsWith("<takeoff"))
{

if (msg.StartsWith("<takeoff 64"))
{
Chat("Annoncez: Attention, SCRAMBLE à Ramsgate, libérez la piste dans 15s...", from);

Timeout(30, () =>
{
AiAction Action = GamePlay.gpGetAction("64");

//if (Action != null)
Action.Do();

Chat("64 Sqn au décollage", from);
});

}


}
else if (msg.StartsWith("<sqn"))
{

AiAirGroup[] WayAirgroups = base.GamePlay.gpAirGroups(1) ;


if (WayAirgroups != null)
{

foreach (AiAirGroup aag in WayAirgroups)
{

airgroup = aag.Name();

sectorName = GamePlay.gpSectorName(aag.Pos().x, aag.Pos().y);

Chat( airgroup + " Sector " + sectorName + "TASK: " + aag.getTask(), from);

}

}

}
else if (msg.StartsWith("<way"))
{

result = msg.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries);

sqn = result[1];
sqn = sqn.Replace("sqn", "");

sqn = sqn + "Sqn";

Chat(sqn + " Sqn pris en compte", from);


// cherche le sector

sectorName = result[2];
sectorName = sectorName.ToUpper();

sectorArray = strToXY(result[2]);

sector_x = sectorArray[0];

sector_y = sectorArray[1];


// cherche l'altitude
alti_str = result[3];

if( alti_str.IndexOf("ft")>=0)
{
alti_str= alti_str.Replace("ft", "");

try
{
alti = Double.Parse(alti_str);
}
catch (Exception e)
{
Console.WriteLine("Error lors de la recherche de l'ALTITUDE WAYPOINT");
Console.WriteLine(e.Message);

alti = 2000;
}

alti = alti * 0.3048;

}
else if( alti_str.IndexOf("m")>=0)
{
alti_str = alti_str.Replace("m", "");


try
{
alti = Double.Parse(alti_str);

}
catch (Exception e)
{
Console.WriteLine("Error lors de la recherche de l'ALTITUDE WAYPOINT");
Console.WriteLine(e.Message);
}

}
else
{

try
{
alti = Double.Parse(alti_str);
}
catch (Exception e)
{
Console.WriteLine("Error lors de la recherche de l'ALTITUDE WAYPOINT");
Console.WriteLine(e.Message);
}

}


// cherche l'ordre

if(result[4] != "")
{
string order = result[4];

order = order.ToUpper();


if( order.IndexOf("COVER")>=0 | order.IndexOf("COUVRIR")>=0) { setOrder = "COVER"; }

if( order.IndexOf("ESCORT")>=0 | order.IndexOf("ESCORT")>=0) { setOrder = "ESCORT"; }

if( order.IndexOf("HUNTING")>=0 | order.IndexOf("AFFUT")>=0) { setOrder = "HUNTING"; }

if( order.IndexOf("FIGHTER")>=0 | order.IndexOf("CHASSEUR")>=0) { setOrder = "AATTACK_FIGHTERS"; }

if( order.IndexOf("BOMBER")>=0 | order.IndexOf("BOMBARDIER")>=0) { setOrder = "AATTACK_BOMBERS"; }

if( order.IndexOf("TAKEOFF")>=0 | order.IndexOf("DECOLLAGE")>=0) { setOrder = "TAKEOFF"; }

if( order.IndexOf("NORMFLY")>=0 | order.IndexOf("VOL")>=0) { setOrder = "NORMFLY"; }

if( order.IndexOf("LANDING")>=0 | order.IndexOf("ATTERRI")>=0 | order.IndexOf("POSE")>=0) { setOrder = "LANDING"; speed = 45.00; }

Chat(setOrder + " order pris en compte", from);

}
else
{
setOrder = "HUNTING";
}

Chat(setOrder + " order pris en compte", from);

Point3d curPoint = new Point3d(sector_x, sector_y, alti); // 255232.47 234913.87

aaWP = new AiAirWayPoint(ref curPoint, speed);


AiAirGroup[] WayAirgroups = base.GamePlay.gpAirGroups(1) ; // Red camp


// Cherche la référence exacte du squadron
if (WayAirgroups != null)
{

foreach (AiAirGroup aag in WayAirgroups)
{
AiAircraft aircraft = aag.GetItems()[0] as AiAircraft;

airgroup = aag.Name();

if( airgroup.IndexOf(sqn)>=0 ) // if( airgroup.IndexOf("RAF_F_213Sqn")>=0 )
{
Chat(sqn + " trouvé", from);

// WayPointTestAirgroup = base.GamePlay.gpActorByName("3:BoB_RAF_F_213Sqn_Early.03") as AiAirGroup;

WayPointTestAirgroup = base.GamePlay.gpActorByName(airgroup) as AiAirGroup;

}

}

}


if( setOrder.IndexOf("HUNTING")>=0)
{

Point2d CurrentPoint2d = new Point2d(sector_x, sector_y);

NewWaypoints.Add(ajoutSimplePoint(CurrentPoint2d, alti, 80.0, AiAirWayPointType.HUNTING));

NewWaypoints.AddRange(WaitingWayPoints(CurrentPoin t2d, alti, 80.0, 5000.0, 5000.0, 20, AiAirWayPointType.HUNTING));

NewWaypoints.Add(ajoutSimplePoint(CurrentPoint2d, alti, 80.0, AiAirWayPointType.HUNTING));

}

if( setOrder.IndexOf("COVER")>=0) { aaWP.Action = AiAirWayPointType.COVER; }



if( setOrder.IndexOf("AATTACK_FIGHTERS")>=0)
{
//aaWP.Action = AiAirWayPointType.AATTACK_FIGHTERS;

Point2d CurrentPoint2d = new Point2d(sector_x, sector_y);

NewWaypoints.Add(ajoutSimplePoint(CurrentPoint2d, alti, 80.0, AiAirWayPointType.AATTACK_FIGHTERS));

NewWaypoints.AddRange(WaitingWayPoints(CurrentPoin t2d, alti, 80.0, 5000.0, 5000.0, 20, AiAirWayPointType.AATTACK_FIGHTERS));

NewWaypoints.Add(ajoutSimplePoint(CurrentPoint2d, alti, 80.0, AiAirWayPointType.AATTACK_FIGHTERS));
}

if( setOrder.IndexOf("AATTACK_BOMBERS")>=0)
{
//aaWP.Action = AiAirWayPointType.AATTACK_BOMBERS;

Point2d CurrentPoint2d = new Point2d(sector_x, sector_y);

NewWaypoints.Add(ajoutSimplePoint(CurrentPoint2d, alti, 80.0, AiAirWayPointType.AATTACK_BOMBERS));

NewWaypoints.AddRange(WaitingWayPoints(CurrentPoin t2d, alti, 80.0, 5000.0, 5000.0, 20, AiAirWayPointType.AATTACK_BOMBERS));

NewWaypoints.Add(ajoutSimplePoint(CurrentPoint2d, alti, 80.0, AiAirWayPointType.AATTACK_BOMBERS));

}

if( setOrder.IndexOf("TAKEOFF")>=0) { aaWP.Action = AiAirWayPointType.TAKEOFF; } // todo

if( setOrder.IndexOf("NORMFLY")>=0) { aaWP.Action = AiAirWayPointType.NORMFLY; }

if( setOrder.IndexOf("LANDING")>=0) // TODO: rechercher une base particuliere, exemple : <landing 128sqn Ramsgate
{
aaWP.Action = AiAirWayPointType.LANDING;
WayPointTestAirgroup.setTask(AiAirGroupTask.LANDIN G, null);


AiAirport NearestAirfield = null;
AiAirport[] airports = GamePlay.gpAirports();
Point3d StartPos = WayPointTestAirgroup.Pos();

if (airports != null)
{
foreach (AiAirport airport in airports)
{
if (NearestAirfield != null)
{
if (NearestAirfield.Pos().distance(ref StartPos) > airport.Pos().distance(ref StartPos))
NearestAirfield = airport;
}
else NearestAirfield = airport;
}
}

aaWP.Target = NearestAirfield;


Chat(sqn + " au AIRPORT suivant: " + NearestAirfield.Name() , from);

}


NewWaypoints.Add(aaWP);

WayPointTestAirgroup.SetWay(NewWaypoints.ToArray() );

Chat(sqn + " au Waypoint suivant", from);


} // if (msg.StartsWith("<way"))

//================================================== ================================================== =========================//


} //Mission_EventChat(IPlayer from, string msg)


public void Chat(string line, IPlayer to)
{
if (GamePlay is GameDef)
{
(GamePlay as GameDef).gameInterface.CmdExec("chat " + line + " TO " + to.Name());
}
}

private double[] strToXY(string sectorName)
{

string sector_x_str = "";
double sector_x = -1.00;
double sector_y = -1.00;

sectorName = sectorName.ToUpper();
string[] resultSector = sectorName.Split(','); // (AA,23) sépare AA de 23

sector_x_str = resultSector[0];

sector_x = strinToInt(sector_x_str.ToUpper());

sector_x = ((sector_x - 1) * 10000) + 10000 + 5000; // 10000 de décallage dans la grid + 5000 pour arriver au centre


try
{
sector_y = Double.Parse(resultSector[1]);

}
catch (Exception e)
{
Console.WriteLine("Error lors de la recherche du secteur WAYPOINT");
Console.WriteLine(e.Message);
}

sector_y = ((sector_y - 1) * 10000) + 20000 + 5000; // 20000 de décallage dans la grid + 5000 pour arriver au centre


string testSector = GamePlay.gpSectorName(sector_x , sector_y);


Console.WriteLine(testSector + " testSector");



return new double[] { sector_x, sector_y };
}

public Point2d GetXYCoord(AiActor actor)
{
Point2d CurrentPoint = new Point2d(actor.Pos().x, actor.Pos().y);
return CurrentPoint;
}

public AiWayPoint ajoutSimplePoint(Point2d CurrentPoint2d, double height, double speed, AiAirWayPointType wayPointType)
{
AiAirWayPoint aaWP = null;

Point3d CurrentPos = new Point3d(CurrentPoint2d.x, CurrentPoint2d.y, height);

aaWP = new AiAirWayPoint(ref CurrentPos, speed);
aaWP.Action = wayPointType;

return aaWP;
}

public AiWayPoint[] WaitingWayPoints(Point2d location, double height, double speed, double AreaWidthX, double AreaWidthY, int numberOfCycles, AiAirWayPointType wayPointType)
{
List<AiWayPoint> NewWaypoints = new List<AiWayPoint>();

Point3d curPoint = new Point3d(location.x - 3000, location.y - 3000, height);

AiAirWayPoint aaWP;

aaWP = new AiAirWayPoint(ref curPoint, speed);
aaWP.Action = wayPointType;

NewWaypoints.Add(aaWP);

for (int i = 0; i < numberOfCycles; i++)
{
curPoint.add(AreaWidthX, 0, 0);
aaWP = new AiAirWayPoint(ref curPoint, speed);
aaWP.Action = wayPointType;

NewWaypoints.Add(aaWP);

curPoint.add(0, AreaWidthY, 0);
aaWP = new AiAirWayPoint(ref curPoint, speed);
aaWP.Action = wayPointType;

NewWaypoints.Add(aaWP);

curPoint.add(-AreaWidthX, 0, 0);
aaWP = new AiAirWayPoint(ref curPoint, speed);
aaWP.Action = wayPointType;

NewWaypoints.Add(aaWP);

curPoint.add(0, -AreaWidthY, 0);
aaWP = new AiAirWayPoint(ref curPoint, speed);
aaWP.Action = wayPointType;

NewWaypoints.Add(aaWP);
}

return NewWaypoints.ToArray();
}

// Transforme 4 en AD pour afficher la zone de detection, exemple: avion situé en AD18
private string inToString(int pos_x)
{
string pos_x_str = "";
string pos_x_str1 = "";
//string pos_x_str2 = "";

int pos_x1 = 0;
int pos_x2 = 0;


if(pos_x > 26)
{
pos_x2 = (pos_x - 26) + 64;
pos_x_str1 = "B";

}
if(pos_x <= 26)
{
pos_x2 = pos_x + 64;
pos_x_str1 = "A";

}

string pos_x_str2 = ((char)pos_x2).ToString();


pos_x_str = pos_x_str1 + pos_x_str2;


return (string) pos_x_str;

}

// Transforme AD en 4 pour remplir en numérique le tableau
private int strinToInt(string sectorName)
{


char x_car_CharTmp1 = sectorName.Substring(0, 1)[0];

int x_car_tmp1 = (int)x_car_CharTmp1 ;
x_car_tmp1 = (x_car_tmp1 - 65) * 26; // A en ASCII est égal à 65


string x_car_stringTmp2 = sectorName.Substring(1, 1);
char x_car_CharTmp2 = x_car_stringTmp2[0];
int x_car_tmp2 = (int)x_car_CharTmp2 ;
x_car_tmp2 = x_car_tmp2 - 64; // A en ASCII est égal à 65



int x_car = x_car_tmp1 + x_car_tmp2;



return x_car;

}






}





[PARTS]
core.100
bob.100
[MAIN]
MAP Land$English_Channel_1940
BattleArea 10000 20000 340000 280000 10000
TIME 14.5
WeatherIndex 1
CloudsHeight 1500
BreezeActivity 10
ThermalActivity 10
[GlobalWind_0]
Power 3.759 1.368 0.000
BottomBound 0.00
TopBound 0.00
GustPower 10
GustAngle 44
[splines]
[AirGroups]
BoB_RAF_F_64Sqn_Early.33
BoB_LW_KG76_I.07
BoB_RAF_F_213Sqn_Early.03
[BoB_RAF_F_64Sqn_Early.33]
Flight0 1 2 3 4 5 6
Flight1 11 12 13 14 15 16
Class Aircraft.HurricaneMkI
Formation VIC3
CallSign 8
Fuel 100
Weapons 1
Scramble 1
SpawnFromScript 1
Skill 1 0.47 0.47 0.32 0.11 0.47 0.47 0.16
[BoB_RAF_F_64Sqn_Early.33_Way]
TAKEOFF 247909.78 258742.81 0 0
NORMFLY 252882.82 257761.23 500.00 300.00
[BoB_LW_KG76_I.07]
Flight0 1 2 3
Flight1 11 12 13
Flight2 21 22 23
Class Aircraft.Do-17Z-2
Formation VIC3
CallSign 12
Fuel 90
Weapons 1 1 1 1 1 1 4 2
Skill 1 0.47 0.47 0.32 0.11 0.47 0.47 0.16
[BoB_LW_KG76_I.07_Way]
NORMFLY 255285.52 212777.65 3000.00 280.00
NORMFLY 255326.49 253256.59 3000.00 280.00
NORMFLY 255029.60 273395.25 3000.00 280.00
NORMFLY 246336.00 275328.00 3000.00 280.00
NORMFLY 244800.00 286272.00 3000.00 280.00
NORMFLY 257088.00 286656.00 3000.00 280.00
NORMFLY 266304.00 285888.00 3000.00 280.00
NORMFLY 262848.00 277248.00 3000.00 280.00
NORMFLY 255552.00 273984.00 3000.00 280.00
NORMFLY 255168.00 252288.00 3000.00 280.00
NORMFLY 255744.00 206592.00 3000.00 280.00
[BoB_RAF_F_213Sqn_Early.03]
Flight0 1 2 3 4 5 6
Flight1 11 12 13 14 15 16
Class Aircraft.SpitfireMkI
Formation VIC3
CallSign 26
Fuel 100
Weapons 1
Skill 1 1 0.74 0.74 0.89 0.74 0.74 0.74
[BoB_RAF_F_213Sqn_Early.03_Way]
NORMFLY 229880.72 241899.47 3000.00 280.00
NORMFLY 237585.72 248368.38 3000.00 280.00
[CustomChiefs]
Vehicle.custom_chief68 $core/icons/tank.mma
[Vehicle.custom_chief68]
Car.Fordson_N
TrailerUnit.Towed_Bowser_UK1_Transport 1
[Stationary]
[Buildings]
[BuildingsLinks]
[Action]
64 ASpawnGroup 1 BoB_RAF_F_64Sqn_Early.33
[BirthPlace]
BirthPlace_0 1 248171 258885 0 50 1 1 gb RAF_Fighter_1939 BoB_RAF_F_64Sqn_Early
[BirthPlace0]
Aircraft.SpitfireMkI

ATAG_Colander
Jan-28-2014, 15:51
I think you can send the chat to a single person, in this case "Server" is the person you want to send the chat to.
If you do that, no one else will receive the chat message.

This is assuming you can actually send a chat to "Server"

Miguel21
Jan-28-2014, 16:35
Hmmm, no, I do not think we can send a message to one person with Clod or so, I don't know how to use that ...

ATAG_Lolsav
Jan-28-2014, 16:40
Hmmm, no, I do not think we can send a message to one person with Clod or so, I don't know how to use that ...

In old IL2 you could sent to a specific person. Wonder if it still works. In console try:

chat blablablabla TO placenameofpersonhere (caps do matter)

Miguel21
Jan-29-2014, 17:42
Thanks Lolsav

But unfortunately, even with the command:


chat blablablabla TO placenameofpersonhere

it is visible to all players ... that's too bad...

ATAG_Colander
Jan-29-2014, 19:16
If you do it from the console instead of from the chat window you can type:
chat MESSAGE_TEXT TO Nickname

ATAG_Lolsav
Jan-29-2014, 19:52
If you do it from the console instead of from the chat window you can type:
chat MESSAGE_TEXT TO Nickname

Wasnt this i suggested him to do?

ATAG_Colander
Jan-29-2014, 19:56
Wasnt this i suggested him to do?

:) sorry, didn't notice the "console" part

Nephilim
Jan-30-2014, 18:46
yes u can send message to anyone..

gpLogServer(maddox.game.Player[] to, string format, object[] args)

or

gpLogServerBegin(maddox.game.Player[] to, string format)

example:

GamePlay.gpHUDLogCenter(new Player[] { from as Player },"Your string. .. " );// this will send hud message to your self

check this:

http://forum.1cpublishing.eu/showthread.php?t=26523&page=3

Vogler

ATAG_Lolsav
Jan-30-2014, 19:29
yes u can send message to anyone..

gpLogServer(maddox.game.Player[] to, string format, object[] args)

He wants to send to a specific person ;)

Nephilim
Jan-30-2014, 20:07
...
with using this



public void Chat(string line, Player player)
{
if (GamePlay is GameDef)
{
(GamePlay as GameDef).gameInterface.CmdExec("chat " + line + " TO " + player.Name());
}
}




You can..



public string MessageToMe(Player player)
{
string Message= "";

return Message;
}

void Mission_EventChat(IPlayer from, string msg)
{
if (msg.StartsWith("<message"))
{
Chat(MessageToMe(from as Player), from);
}
}




then message should be visible only to you... that was the point I think

ATAG_Lolsav
Jan-30-2014, 20:18
Seems i misunderstood, i took "anyone" as "evryone".

SoW Reddog
Jan-31-2014, 11:33
I think what he wants to do is use the chat bar as a command input to pass parameters to a script. What he doesn't want to do is then broadcast that message.

If the console version of chat works and fires the "onchatsent" function (or whatever it's called) then that's what he needs to do. If it doesn't then I believe he's shit out of luck.