PDA

View Full Version : New Scripting Possibilities in Release candidate patch.


FG28_Kodiak
09-30-2012, 06:23 PM
With the new patch its possible to get the Mission time.


double t = GamePlay.gpTimeofDay();

it's a double so you must convert it into time Format.

static string CreateTimeString(double num)
{
double hours = Math.Floor(num);
double minutes = (num - hours) * 60.0;
double seconds = (minutes - Math.Floor(minutes)) * 60.0;
int H = (int)Math.Floor(hours);
int M = (int)Math.Floor(minutes);
int S = (int)Math.Floor(seconds);
return H.ToString() + ":" + M.ToString() + ":" + S.ToString();
}



Also we get the possibility to set lables, but i had no luck to get it to work. So maybe others can give me a hint how to use it. :rolleyes:

theOden
09-30-2012, 07:39 PM
Regarding labels I've tried:


public override void OnUserCreateUserLabel(GPUserLabel ul)
{
//Player ulPlayer = ul.Player;
GamePlay.gpLogServer(null, "Marker: {0}", new object[] { ul.Text });
GamePlay.gpDrawUserLabel(ul);
}

public override void OnPlaceEnter(Player player, AiActor actor, int placeIndex)
{
base.OnPlaceEnter(player, actor, placeIndex);

//Point2d startPoint2d = new Point2d(actor.Pos().x, actor.Pos().y);
//GPUserLabel userLabel = GamePlay.gpMakeUserLabel(startPoint2d, player, player.Name(), GamePlay.gpTimeofDay(), 0);
//GamePlay.gpDrawUserLabel(player.Army(), userLabel);
//GamePlay.gpLogServer(new Player[] { player }, " Hello {0} in {1}!", new object[] { bobDesignation((actor as AiAircraft).InternalTypeName()), userLabel.Text });
//GamePlay.gpLogServer(null, " Hello {0} in {1}!", new object[] { bobDesignation((actor as AiAircraft).InternalTypeName()), userLabel.Text });
... etc


But no joy (I can use label properties but nothing visible on map).
(Also, pressing enter creating a new label in map window fires my guns :-| )

Hopefully someone nails the usage of the new label features.

41Sqn_Banks
10-07-2012, 12:22 AM
Didn't have luck with user labels too:(

salmo
10-07-2012, 01:10 AM
I tried scripting labels as well. No compiler errors, but no labels for ground object displayed in online mission. I wonder whether labels are only displayed with icons-on server settings?

41Sqn_Banks
10-07-2012, 06:54 AM
I tried scripting labels as well. No compiler errors, but no labels for ground object displayed in online mission. I wonder whether labels are only displayed with icons-on server settings?

I did a test with all icon stuff enabled, no success.

FG28_Kodiak
10-07-2012, 07:22 AM
Me too,

i got the OnUserCreateUserLabel Event in single player but not in Multiplayer and Dedi. In all cases no Icon was shown. So it seems to be a Bug. :rolleyes:

Ataros
10-09-2012, 07:32 AM
You may try test.zip sample from this post http://www.sukhoi.ru/forum/showthread.php?t=68629&page=28&p=1902755&viewfull=1#post1902755
or ask Naryv for details if it does not help.

41Sqn_Banks
10-11-2012, 10:47 AM
Response from naryv about user label: http://www.sukhoi.ru/forum/showthread.php?t=68629&p=1906802&viewfull=1#post1906802

FG28_Kodiak
10-11-2012, 10:51 AM
Ive tried it on a Dedi-Server without result, so ...

41Sqn_Banks
10-11-2012, 10:56 AM
Ive tried it on a Dedi-Server without result, so ...

Maybe it's working only with a player hosted server?

The example code of naryv doesn't use the gpMakeUserLabel method, it only shows a label created from a player to other players. I will try out naryv's example code, to see if the labels are displayed there. I only need a second player to test it ...

FG28_Kodiak
10-25-2012, 01:16 PM
Update: Labels working now ;)
Updated Update: Not in Multiplayer :(

My testscript use the Missionmenu to create the Labels:

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


public class Mission : AMission
{

class Recon
{
public Player ReconPlayer { get; internal set; }
public List<GPUserLabel> Labels = new List<GPUserLabel>();


public Recon(Player player, GPUserLabel userLabel)
{
ReconPlayer = player;
if (userLabel != null)
{
Labels.Add(userLabel);
}
}
}


List<Recon> ActiveRecons = new List<Recon>();


public override void OnPlaceEnter(Player player, AiActor actor, int placeIndex)
{
base.OnPlaceEnter(player, actor, placeIndex);

SetMainMenu(player);

}


enum MenuID
{
MainMenu,
ReconMenu,
}



public void SetMainMenu(Player player)
{
GamePlay.gpSetOrderMissionMenu(player, false, (int)MenuID.MainMenu, new string[] { "Recon" }, new bool[] { true });
}


public void SetReconMenu(Player player)
{
GamePlay.gpSetOrderMissionMenu(player, true, (int)MenuID.ReconMenu, new string[] { "Set AAA Mark", "Set Tank Mark", "Set Plane Mark", "Set Factory Mark", "Set Car Mark", "Set Label", "Set Ship Mark", "Set WayPoint Mark", "Delete Marks" }, new bool[] { false, false, false, false, false, false, false, false, false });
}




public override void OnOrderMissionMenuSelected(Player player, int ID, int menuItemIndex)
{
base.OnOrderMissionMenuSelected(player, ID, menuItemIndex);

if (ID == 0)
{
// main menu
if (menuItemIndex == 1)
{
SetReconMenu(player);
}
else
{
SetMainMenu(player);
}
}
else if (ID == (int)MenuID.ReconMenu)
{

switch (menuItemIndex)
{
case 1:
AddReconMark(player, GPUserIconType.AAGun);
SetMainMenu(player);
break;
case 2:
AddReconMark(player, GPUserIconType.Tank);
SetMainMenu(player);
break;
case 3:
AddReconMark(player, GPUserIconType.Plane);
SetMainMenu(player);
break;
case 4:
AddReconMark(player, GPUserIconType.Factory);
SetMainMenu(player);
break;
case 5:
AddReconMark(player, GPUserIconType.Car);
SetMainMenu(player);
break;
case 6:
AddReconMark(player, GPUserIconType.Label);
SetMainMenu(player);
break;
case 7:
AddReconMark(player, GPUserIconType.Ship);
SetMainMenu(player);
break;
case 8:
AddReconMark(player, GPUserIconType.Waypoint);
SetMainMenu(player);
break;
case 9:
RemoveMarks(player);
SetMainMenu(player);
break;
default:
SetMainMenu(player);
break;
}
}
}


private void RemoveMarks(Player player)
{
if (ActiveRecons.Exists(item => item.ReconPlayer == player))
{
Recon recon = ActiveRecons.Find(item => item.ReconPlayer == player);
recon.Labels.ForEach(item => GamePlay.gpDeleteUserLabel(item));
recon.Labels.Clear();
}

}


private void AddReconMark(Player player, GPUserIconType iconType)
{
AiActor actor = player.Place();
GPUserLabel newLable =null;

if (actor != null)
{
Point2d pos = new Point2d(actor.Pos().x, actor.Pos().y);

switch (iconType)
{
case GPUserIconType.AAGun:
newLable = GamePlay.gpMakeUserLabel(pos, player, "AAA", GamePlay.gpTimeofDay(), (int)GPUserIconType.AAGun);
break;
case GPUserIconType.Tank:
newLable = GamePlay.gpMakeUserLabel(pos, player, "Tanks", GamePlay.gpTimeofDay(), (int)GPUserIconType.Tank);
break;
case GPUserIconType.Plane:
newLable = GamePlay.gpMakeUserLabel(pos, player, "Planes", GamePlay.gpTimeofDay(), (int)GPUserIconType.Plane);
break;
case GPUserIconType.Factory:
newLable = GamePlay.gpMakeUserLabel(pos, player, "Factory", GamePlay.gpTimeofDay(), (int)GPUserIconType.Factory);
break;
case GPUserIconType.Car:
newLable = GamePlay.gpMakeUserLabel(pos, player, "Car", GamePlay.gpTimeofDay(), (int)GPUserIconType.Car);
break;
case GPUserIconType.Label:
newLable = GamePlay.gpMakeUserLabel(pos, player, "Label", GamePlay.gpTimeofDay(), (int)GPUserIconType.Label);
break;
case GPUserIconType.Ship:
newLable = GamePlay.gpMakeUserLabel(pos, player, "Ship", GamePlay.gpTimeofDay(), (int)GPUserIconType.Ship);
break;
case GPUserIconType.Waypoint:
newLable = GamePlay.gpMakeUserLabel(pos, player, "Waypoint", GamePlay.gpTimeofDay(), (int)GPUserIconType.Waypoint);
break;
}


if (newLable != null)
{
if (ActiveRecons.Exists(item => item.ReconPlayer == player))
ActiveRecons.Find(item => item.ReconPlayer == player).Labels.Add(newLable);
else
ActiveRecons.Add(new Recon (player, newLable));


GamePlay.gpDrawUserLabel(player.Army(), newLable);

}
}
}



static string CreateTimeString(double num)
{
double hours = Math.Floor(num);
double minutes = (num - hours) * 60.0;
double seconds = (minutes - Math.Floor(minutes)) * 60.0;
int H = (int)Math.Floor(hours);
int M = (int)Math.Floor(minutes);
int S = (int)Math.Floor(seconds);
return H.ToString("00") + ":" + M.ToString("00") + ":" + S.ToString("00");
}


public override void OnUserCreateUserLabel(GPUserLabel ul)
{
base.OnUserCreateUserLabel(ul);

GamePlay.gpLogServer(null, "OnUserCreateUserLabel: {0} created {1} Mark at {2} ", new object[] { ul.Player.Name(), ul.Text, CreateTimeString(ul.time) });

}
}

Ataros
10-25-2012, 06:10 PM
Congratulations!

What are labels used for? Are these map icons that show unit positions or something else?

FG28_Kodiak
10-25-2012, 06:12 PM
You can create recon missions, in multiplayer you can mark enemy positions etc. You will see the icons on the in game map and on the briefing screen map.

theOden
10-26-2012, 05:09 AM
You're the best Kodiak - will try again after work today.
:beer:

Edit: works in SP but NoGo in MP as far as I can see :/

FG28_Kodiak
10-26-2012, 11:01 AM
Argh forget to test it in multiplayer. :(
Ok then no recon missions in multiplayer, in singleplayer it makes not so much sense i think.

41Sqn_Banks
10-26-2012, 07:41 PM
It was a single-mission sample, i tryed step by step check :), but now it seems like i know what is the problem:. In multiplayer label will not sent to player which is author of this label - just to not doubling labels, exept case when labels sent to everybody. So, when you use that code you make label with player who enter the plane as author, sever will not send it to this player. But You can change the author of label, then it would be send to remote player, server is good candidate to be author(couse hi makes it really) like this :using maddox.game;
using maddox.game.world;
using maddox.GP;
using System.Collections.Generic;
using Math = System.Math;


public class Mission : AMission
{

public override void OnPlaceEnter(Player player, AiActor actor, int placeIndex)
{
base.OnPlaceEnter(player, actor, placeIndex);
Point2d p ;
p.x = actor.Pos().x;
p.y = actor.Pos().y;
GPUserLabel ul = GamePlay.gpMakeUserLabel(p, GamePlay.gpPlayer(), actor.Name(), GamePlay.gpTimeofDay(), (int)GPUserIconType.Plane);
GamePlay.gpDrawUserLabel(ul);
p.x -= 300;
ul.pos = p;
ul.Text = "Show player";
GamePlay.gpDrawUserLabel(new Player[] { player }, ul);

p.x += 600;
p.y += 300;
ul.pos = p;
ul.Text = "Show army";
GamePlay.gpDrawUserLabel(0,ul);
p.x += 300;
p.y += 300;
ul.pos = p;
GamePlay.gpDrawUserLabel(1, ul);
p.x += 300;
p.y += 300;
ul.pos = p;
GamePlay.gpDrawUserLabel(2, ul);
}

}
it should draw 3 labels - actor.Name, Show player and Show army , try it please.

Maybe this will help you to solve the problem.

In multiplayer gpDrawUserLabel doesn't draw user labels for the player who was used in gpMakeUserLabel. One should use GamePlay.gpPlayer() (which is the "server") instead for gpMakeUserLabel.

FG28_Kodiak
10-26-2012, 07:57 PM
Ok, will try it :rolleyes:

41Sqn_Banks
10-26-2012, 08:02 PM
Habs noch nicht probiert, aber navyr hats wohl erfolgreich auf nem Dedicated Server probiert und 3 Labels angezeigt bekommen.

FG28_Kodiak
10-27-2012, 04:41 AM
Wenn es funktioniert wäre es auch für die JFS interessant, man könnte in der Navigationsschulung so eine Art Schnitzeljagd veranstalten. Die Frage ist halt wenn ich GamePlay.gpPlayer() verwende, es auch in einer selber gehosteten Multiplayer Mission funktioniert, in dem Fall ist gpPlayer ja der Spieler der hostet.
Muss mal testen. :rolleyes:

theOden
10-27-2012, 06:20 AM
Thanks a tonne Banks, or should I say Danke Sehr? :)

Still a NoGo as host, guess it works for SP and from a ded.server as described (but we don't have a ded.server exe yet do we? just a second license install where the player runs to another computer flying?)

Tried with "null" as player but still no marker.

In Arma, where I come from, we have "IsMultiplayer" and "IsDedicated" along with a lot of player/server procedures to cope with remote players, hosted server player and dedicated server with no player at all - sure miss them here.

(I prefer flying singleplayer as multiplayer-host on locked server due to MP features - same as in ArmA)

Guess this will work in the "sequel" one day..

41Sqn_Banks
10-27-2012, 07:14 AM
Wenn es funktioniert wäre es auch für die JFS interessant, man könnte in der Navigationsschulung so eine Art Schnitzeljagd veranstalten. Die Frage ist halt wenn ich GamePlay.gpPlayer() verwende, es auch in einer selber gehosteten Multiplayer Mission funktioniert, in dem Fall ist gpPlayer ja der Spieler der hostet.
Muss mal testen. :rolleyes:

If hosted by a player I think the host will not get displayed the created label. IMHO the best way is to run the the dedicated server on the same PC and the host connects as a regular client.

But yes, has to be tested ...

salmo
10-27-2012, 07:20 AM
If hosted by a player I think the host will not get displayed the created label. IMHO the best way is to run the the dedicated server on the same PC and the host connects as a regular client.

But yes, has to be tested ...

That's what I used to do until the latest patch when I can no longer have 2 interations of the game running simultaneously on the same PC. See http://forum.1cpublishing.eu/showthread.php?t=35085