Jump to content

Recommended Posts

I ve some vehicles with variables in their variable space and I want to have them broadcasted betwenn headless client (HC) and server.

_squad  setVariable["respawtime", 300];

I know that i could set the parameter public to true to broadcast it to all.

_squad  setVariable["respawnable", 300, true];

But thats more network traffic than I need.

Is there a way to use  publicVariableServer and publicVariableClient to broadcast that variable?

 

Or is the variable also transferred if I use setOwner to transfer the ownership between server and HC?

 

Thanks a lot for any advice.

Share this post


Link to post
Share on other sites

The publicVariable... commands only affect variables in the Mission namespace, not object-variables.

 

So for what you want to achieve you could either put those variables in mission space or make a function for changing the variables and use it with remoteExec.

 

Or is the variable also transferred if I use setOwner to transfer the ownership between server and HC?

I doubt it.

Share this post


Link to post
Share on other sites

I know that i could set the parameter public to true to broadcast it to all.

_squad  setVariable["respawnable", 300, true];

But thats more network traffic than I need.

 

What makes you say that? Are you going to be setting this variable every frame or something like that? If you are setting this value infrequently, the network traffic that you'd be introducing would be negligible. 

Share this post


Link to post
Share on other sites

What makes you say that? Are you going to be setting this variable every frame or something like that? If you are setting this value infrequently, the network traffic that you'd be introducing would be negligible. 

It adds up quickly.

 

 

Oh anyway, whats the reason to have those variables on both the HC and the server?

 

Would probably be cleaner to handle whatever you're doing only on one or the other. Without transmitting stuff back and forth.

Share this post


Link to post
Share on other sites

It adds up quickly.

 

 

Oh anyway, whats the reason to have those variables on both the HC and the server?

 

Would probably be cleaner to handle whatever you're doing only on one or the other. Without transmitting stuff back and forth.

 

From experience, I can tell you that with simple variables like this, it really doesn't. There is so much information being broadcast all the time just to keep the simulation running; the state of one object variable is nothing by comparison. I still recommend just broadcasting it globally using the optional third parameter of setVariable as this is definitely the most pragmatic solution.

 

But if you really insist...

 

You could use a public variable event handler to achieve your goal: 

 

init.sqf:

if (isServer || (!hasInterface && !isDedicated)) then
{
    var_serverCode = {}; // this variable will serve as a holder for code we want run only on the server and HC
    "var_serverCode" addPublicVariableEventHandler {call (_this select 1)};
};

Now, whenever you want to change your object variable, instead of doing it normally, do this:

_codeToPass = compile format ["%1 setVariable ['respawnable',300]",_squad];
var_serverCode = _codeToPass;
publicVariable "var_serverCode"; // send it to HC or server (whichever one this isn't)
call _codeToPass; // execute code locally

This is overly complicated and totally unnecessary, but there you go.

  • Like 1

Share this post


Link to post
Share on other sites

thank u for ur answers guys i ll think about the whole thing and decide if i choose the solution of dux2.

the code posted at first post was an example only.

my intention is to have all information pinned at objects to easy run needed stuff at HC if it gets reconnected after disconnect.

the main reason is an issue with linux hc/server connection as u can see here:

http://feedback.arma3.com/view.php?id=27172

but u should use google cache to read it cause feedback tracker is down.

 

DEV container for WIP:

Spoiler

if (!isServer) exitWith {true};
/*
	Author: Sarogahtyp
	Title: SSSS - Sarogahtyps Simple Server Statistics

	Description:

	Arguments:
	number - refresh time in seconds

	Return value:
	boolean - true if script has been finished
*/

_report_HC_base_string = "Saro_HC_stats_report_";
_report_plyr_base_string = "Saro_HC_stats_report_";
_report_HC_reply_timeout = 5;
_report_plyr_reply_timeout = 10;
_admin_check = [];
_admin_obj = objNull;

while {true} do
{
 // wait for a logged in admin
 waitUntil
 {
  sleep (20 + random 20);
  _admin_check = (allPlayers - entities "HeadlessClient_F") select {(admin owner _x) != 0};
  (count _admin_check > 0)
 };

 _admin_obj = admin_check select 0;

 //throw infos as long as admin is logged in
 while {(admin owner _admin_obj) != 0} do
 {
  // collect server infos
  _s_fps = str diag_fps; // frames per second
  _s_just_players = allPlayers - entities "HeadlessClient_F"; // all player objects
  _s_plyr_num = count _just_players; // number of players
  _s_just_HCs = entities "HeadlessClient_F"; // all HC objects
  _s_HC_num = count _just_HCs; // number of headless clients

  _s_a_grp_num = {local _x and {alive _x} count units _x > 0} count allGroups; // all groups where alive units in
  _s_e_grp_num = {local _x and (count units _x) == 0 } count allGroups; // empty groups
  _s_d_grp_num = {local _x and ({alive _x} count units _x) == 0}count allGroups; //groups where only deads in
  _s_unit_num = {local _x} count allUnits; // living units
  _s_vec_num = {local _x} count (vehicles - entities "WeaponHolderSimulated"); // living vecs
  _s_wh_num = {local _x} count (entities "WeaponHolderSimulated") //weapons on ground
  _s_al_ent_num = {local _x} count entities [[], [], true, true]; // alive entities
  _s_de_ent_num = {local _x} count entities [[], ["Logic"], true]; //dead entities except logic

  //request not local on server available infos from HCs and players remotely

  //send request to all players
  for "_i" from 0 to (_s_plyr_num - 1) do 
  {
   _str = format ["%1%2", _report_plyr_base_string, _i];
   missionNamespace setVariable [_str, []];
   [_str] remoteExecCall ["Saro_fnc_report_stats_to_server", (_s_just_players select _i)];
  };

  if (_s_HC_num > 0) then
  {
  // send request to all headless clients
   for "_i" from 0 to (_s_HC_num - 1) do 
   {
    _str = format ["%1%2", _report_HC_base_string, _i];
    missionNamespace setVariable [_str, []];
    [_str] remoteExecCall ["Saro_fnc_report_stats_to_server", (_s_just_HCs select _i)];
   };

   //wait for reply of all HCs or break after timeout

   _break_time = diag_tickTime + _report_HC_reply_timeout;

   waitUntil
   {
    sleep (0.1 + random 0.1);
    _sum = 0;
    for "_i" from 0 to (_s_HC_num - 1) do 
    {
     _str = format ["%1%2", _report_HC_base_string, _i];
    
     if (count (missionNamespace getVariable _str) > 0) then
     {
      _sum =  _sum + 1;
     };
     (_sum == _s_HC_num or diag_tickTime  > _break_time)
    };
   }; //waitUntil end
  }; // HC_num > 0 end

  //wait for reply of all players or break after timeout

  _break_time = diag_tickTime + _report_plyr_reply_timeout;

  waitUntil
  {
   sleep (0.5 + random 0.5);
   _sum = 0;
   for "_i" from 0 to (_s_plyr_num - 1) do 
   {
    _str = format ["%1%2", _report_plyr_base_string, _i];
   
    if (count (missionNamespace getVariable _str) > 0) then
    {
     _sum =  _sum + 1;
    };
    (_sum == _s_plyr_num or diag_tickTime  > _break_time)
   };
  }; //waitUntil end

  //get local on server available infos for HCs and players
  //get local HC infos

  if (_s_HC_num > 0) then
  {
   for "_i" from 0 to (_s_HC_num - 1) do 
   {
    _str = format ["%1%2", _report_HC_base_string, _i];
    _tmp_array = missionNamespace getVariable _str;
    _owner_ID = owner (_s_just_HCs select _i);
    _tmp_array pushBack {groupOwner _x == _owner_ID and {alive _x} count units _x > 0} count allGroups; // all groups where alive units in
    _tmp_array pushBack {groupOwner _x == _owner_ID and (count units _x) == 0 } count allGroups; // empty groups
    _tmp_array pushBack {groupOwner _x == _owner_ID and ({alive _x} count units _x) == 0 }count allGroups; //groups where only deads in
    _tmp_array pushBack {owner _x == _owner_ID} count allUnits; // living units
    _tmp_array pushBack {owner _x == _owner_ID} count (vehicles - entities "WeaponHolderSimulated"); // living vecs
    _tmp_array pushBack {owner _x == _owner_ID} count (entities "WeaponHolderSimulated") //weapons on ground
    _tmp_array pushBack {owner _x == _owner_ID} count entities [[], [], true, true]; // alive entities
    _tmp_array pushBack {owner _x == _owner_ID} count entities [[], ["Logic"], true]; //dead entities except logic
    missionNamespace setVariable [_str, _tmp_array];
   };
  }; // HC_num > 0 end

  for "_i" from 0 to (_s_plyr_num) do 
  {
   _str = format ["%1%2", _report_plyr_base_string, _i];
   _tmp_array = missionNamespace getVariable _str;
   _owner_ID = owner (_s_just_players select _i);
   _tmp_array pushBack {groupOwner _x == _owner_ID and {alive _x} count units _x > 0} count allGroups; // all groups where alive units in
   _tmp_array pushBack {groupOwner _x == _owner_ID and (count units _x) == 0 } count allGroups; // empty groups
   _tmp_array pushBack {groupOwner _x == _owner_ID and ({alive _x} count units _x) == 0 }count allGroups; //groups where only deads in
   _tmp_array pushBack {owner _x == _owner_ID} count allUnits; // living units
   _tmp_array pushBack {owner _x == _owner_ID} count (vehicles - entities "WeaponHolderSimulated"); // living vecs
   _tmp_array pushBack {owner _x == _owner_ID} count (entities "WeaponHolderSimulated") //weapons on ground
   _tmp_array pushBack {owner _x == _owner_ID} count entities [[], [], true, true]; // alive entities
   _tmp_array pushBack {owner _x == _owner_ID} count entities [[], ["Logic"], true]; //dead entities except logic
   missionNamespace setVariable [_str, _tmp_array];
  };

  sleep (15 + random 15);
 }; // info while end


}; // endless while (end)



/*
	Author: Sarogahtyp
	Title: SSSS - Sarogahtyps Simple Server Statistics
	Function Name:  Saro_fnc_report_stats_to_server;

	Description: function used via remote execution by server to recieve some statistical infos

	Arguments:
	String - name of global variable which should returned to server by publicVariableServer

	Return value:
	true
*/

params ["_ret_string"];
 
_tmp_info_array = [];
_tmp_info_array pushBack str player;
_tmp_info_array pushBack diag_fps;
 
missionNamespace setVariable [_ret_string, _tmp_info_array];
 
publicVariableServer _ret_string;

true

 

 

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
Sign in to follow this  

×