Jump to content

Recommended Posts

Hi there, 

I noticed some very strange problems when I tested my mission with two instances of ArmA running.

 

Nr 1 was Player and Server

Nr 2 was Player 

 

As expected everything worked fine on Nr 1, 

but when I played around with Nr 2 some scripts wouldn't really work.

 

I have two guesses:

1) Nr 2 can't access all the mission config data (sounds weird, ik: dialogs are loading but it won't create a HUD with cutRsc -> all working fine on Nr1)

2) Nr 2 can't access the missionNamespace (for example there's a script that needs an array of locations create by initServer.sqf and stored in the mission namespace. When calling it it just returns ANY)

 

These problems are driving me crazy.

Do you have any ideas or is it definitely a problem made by me?

Share this post


Link to post
Share on other sites

3) some scripts are executing on the server only

 

Impossible to say until you share them.

  • Like 2

Share this post


Link to post
Share on other sites

Well let's go... that's going to be a lot!

 

initServer.sqf (just the important stuff -> SL_CENTER is defined in JF_fnc_Options)

[] call JF_fnc_Options;

[SL_CENTER] call JF_fnc_SortLocations;

 

the script executed by an addaction to call the dialog:

createDialog "JF_Teleport";
private _isLeader = player getVariable "isLeader";
if (_isLeader == "true") then {
	[getPos player] call JF_fnc_SortLocations;
} else {
	private _locations = [getPos player] call JF_fnc_SortLocationsLocal;
	[_locations] call JF_fnc_Location_ListBox_Fill;
};

 

JF_fnc_SortLocations:

params ["_center"];

private _locations = getMissionConfig "JF_Locations";
private _allLocations = [];

for [{_p = 0}, {_p < count _locations}, {_p = _p+1}] do {
  private _loc = _locations select _p;
  private _name = getText (_loc >> "name");
  private _air = getText (_loc >> "air");
  private _land = getText (_loc >> "land");
  private _coordinates = getText (_loc >> "coordinates");
  private _style = getText (_loc >> "style");
  private _pos = parseSimpleArray _coordinates;
  private _distance = _center distance2D _pos;

  _allLocations pushBack [_name, _air, _land, _coordinates, _style, _distance];

};

private _sortedLocations = [_allLocations, [], {_x select 5}, "ASCEND"] call BIS_fnc_sortBy;


missionNamespace setVariable ["sorted_locations", _sortedLocations];

 

JF_fnc_SortLocationsLocal:

params ["_center"];

private _locations = getMissionConfig "JF_Locations";
private _allLocations = [];

for [{_p = 0}, {_p < count _locations}, {_p = _p+1}] do {
  private _loc = _locations select _p;
  private _name = getText (_loc >> "name");
  private _air = getText (_loc >> "air");
  private _land = getText (_loc >> "land");
  private _coordinates = getText (_loc >> "coordinates");
  private _style = getText (_loc >> "style");
  private _pos = parseSimpleArray _coordinates;
  private _distance = _center distance2D _pos;

  _allLocations pushBack [_name, _air, _land, _coordinates, _style, _distance];

};

private _sortedLocations = [_allLocations, [], {_x select 5}, "ASCEND"] call BIS_fnc_sortBy;

_sortedLocations;

 

Location_ListBox_Fill: (function to fill a listbox)

disableSerialization;
params ["_locations"];

private _parent = uiNamespace getVariable "JF_Teleport";
private _ctrl = _parent displayctrl 50001;
lbClear _ctrl;

 for [{_i = 0}, {_i < count _locations}, {_i = _i+1}] do {
   private _loc = _locations select _i;
  _ctrl lbAdd format ["%1", _loc select 0];
};

_ctrl lbSetCurSel 0;

 

Location_ListBox_GetInfo: (displays some information in the dialog (just the important part)

disableSerialization;
params ["_lb", "_index"];

private _parent = uiNamespace getVariable "JF_Teleport";
private _ctrl = _parent displayctrl 50002;
private _bt_land = _parent displayctrl 50003;
private _bt_air = _parent displayctrl 50004;
private _map = _parent displayctrl 50005;
_locations = missionNamespace getVariable "sorted_locations";

private _loc = _locations select _index;

private _air = _loc select 1;
private _land = _loc select 2;
private _coordinates = _loc select 3;

_ctrl ctrlSetText format ["air = %1 | land = %2 | coordinates = %3", _air, _land, _coordinates];

 

 

Now to the problem:

-When Nr 2 spawns as a "non leader" character, the ListBox is filled (because JF_fnc_SortLocationsLocal is called), but the dialog doesn't show the extra information (because the "sorted_locations" are stored in the missionNamespace [they really are, i checked it with Nr 1s debug console] and Nr 2 propably can't access them)

 

-When Nr 2 spawns as a "leader" character , the ListBox is filled just after the second time he opens the dialog (the first time the "sorted_locations" are stored in the missionNamespace -> he can't access it?!, than he calls JF_fnc_SortLocations and stores them himself), after the second time everything is working.

 

That makes me think, that the missionNamespace (used by the server) can't be accessed (or is unknown) by the client.

Share this post


Link to post
Share on other sites
missionNamespace setVariable ["sorted_locations", _sortedLocations];

creates the global variable sorted_locations on the machine where that line is executed.

To get it a public variable (known by all machines) you have to set the third parameter of setVariable to true as stated in biki and shown in Example 1 there.

 

therefore u should use this to get it public:

missionNamespace setVariable ["sorted_locations", _sortedLocations, true];

 

but I did not verify if that solves your problems...

  • Like 2

Share this post


Link to post
Share on other sites
8 minutes ago, sarogahtyp said:

missionNamespace setVariable ["sorted_locations", _sortedLocations];

creates the global variable sorted_locations on the machine where that line is executed.

To get it a public variable (known by all machines) you have to set the third parameter of setVariable to true as stated in biki and shown in Example 1 there.

 

therefore u should use this to get it public:


missionNamespace setVariable ["sorted_locations", _sortedLocations, true];

 

but I did not verify if that solves your problems...

 

Solved the problem, thanks!

 

 

Es sind auch wirklich immer solche Kleinigkeiten, die einem so unglaublich viel Aufwand bescheren. Ich könnte heulen ^^

  • Like 1

Share this post


Link to post
Share on other sites

MP scripting is the higher level. One has to read the biki entries for each command carefully to get it done.

  • Sad 1

Share this post


Link to post
Share on other sites

Maybe the second problem is something similar:

 

description.ext (just the important information😞

class RscTitles {
  #include "Core\Headers\Gui\Cooldown.hpp"
};

 

Cooldown.hpp:

#define JF_TELE_X (safeZoneXAbs)
#define JF_TELE_Y (safeZoneY + safeZoneH *.97)
#define JF_TELE_W (safeZoneWAbs)
#define JF_TELE_H (safeZoneH *.03)

class JF_Cooldown {
  idd = -1;
  duration = 99999999999;
  onLoad = "uiNamespace setVariable ['JF_Cooldown', _this select 0]";

  class controls {
    class JF_Txt: RscText {
      idc = 70001;

      x = JF_TELE_X;
      y = JF_TELE_Y;
      w = JF_TELE_W;
      h = JF_TELE_H;

	    SizeEx = GUI_TEXT_SIZE_SMALL;
      style = ST_CENTER;
      colorBackground[] = {0,0,0,0};
    };
  };
};

 

JF_fnc_LeaderTest (= called in OnPlayerRespawn.sqf): 

params [];
player setVariable ["isLeader", "false"];

private _config = getMissionConfig "JF_SquadLeader";

for [{_i = 0}, {_i < count _config}, {_i = _i+1}] do {
  if ((getText ((_config select _i) >> "name")) == (getDescription player) select 0) then {
    player setVariable ["isLeader", "true"];
    ("TAG_myLayer" call BIS_fnc_rscLayer) cutRsc ["JF_Cooldown", "PLAIN"];
  };
};

 

Problem:

As i have mentioned before, JF_fnc_LeaderTest is called on every client in OnPlayerRespawn.sqf.

The HUD (it shows the cooldown of some special abilitys of the squad leader) should only be displayed if the unit is a "leader".

 

Same game as before: The HUD won't show on Nr 2.

Is there any need to remoteExec a function and create the HUD within?

 

 

Edited by Smart Games
The HUD was created all the time. I jsut had to remoteexec update it

Share this post


Link to post
Share on other sites

Interesting way with getMissionConfig I didn't know, even if I don't understand why cooldown.hpp is not enough.

("JF_SquadLeader" ???)

Do you want to create a simple filter for leaders (easy)
or do you want to broadcast some leader's data to subordinate? In this case the missionNamespace setVariable ["sorted_locations", _sortedLocations, true]; could be OK on local HUDs.

Share this post


Link to post
Share on other sites

@pierremgi, it checks wheter the unit is a squad leader. That's important for some other scripts as well. I used a Config to make it easier to work with in the future, as I plan to use it as a template.

 

I already fixed the problem. I had to use remoteExec but now it's working fine. 

Share this post


Link to post
Share on other sites

@pierremgi, I had to write the cutRsc command in a separate function to make it work. 

For sure it's not efficient, but it's working. 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×