Jump to content
Sign in to follow this  
spitfire007

Trying to get addPublicVariableEventHandler to work. Very simple example.

Recommended Posts

Really stuck here.

I have no idea what I am doing.

All I am trying to do is pass the player who is using the script back to the server and output the result to systemchat.

Here is what I have got.

init.sqf

"packet" addPublicVariableEventHandler {
       _playerUID = _this select 1;
       systemChat format["Player Server %1", _playerUID];          
   };


_myaction = player addAction ["Call Hint", "addaction.sqf"];

addaction.sqf

packet = [player, getPlayerUID player]; 
	publicVariableServer "packet";
	systemChat format["Player Client %1",packet];

I was expecting that when the eventhandler was triggered it would spit out the playerUID.

But ... computer says no.

Share this post


Link to post
Share on other sites

you cannot see messages displayed on server because they are server side. it could work in local but here is what the wiki says about addPublicVariableEventHandler :

"EH will not fire on the machine that executed broadcast command, only on the machines that receive the broadcast."

you have to callback a new brodcast to every players.

You could try something like this :

// client side - what client should do on recieve
ME_fnc_test = {
   systemChat format["Player Server %1", _this]; 
}; 

// server side - what server should do on recieve
ME_fnc_test = {
  // no systemChat because nobody will see it
}; 

// client side, when you want to broadcast
[[player, getPlayerUID player], "ME_fnc_test", true, false] call BIS_fnc_MP; // this will run ME_fnc_test on my machine too

BIS_fnc_MP is very usefull, you can filter the destination :

["hello", "ME_fnc_test", true, false] call BIS_fnc_MP; // server, players
["hello", "ME_fnc_test", false, false] call BIS_fnc_MP; // server only
["hello", "ME_fnc_test", nil, false] call BIS_fnc_MP; // players only, even me
["hello", "ME_fnc_test", _obj1, false] call BIS_fnc_MP; // to the machine where _obj1 is local
...

https://community.bistudio.com/wiki/BIS_fnc_MP

Edited by Zigomarvin

Share this post


Link to post
Share on other sites

Thanks for looking Zigomarvin,

It is a dedicated server that I am trying to run it with but it's not working.

I have really tried to dumb it down so that I can see what I am doing wrong but I just can't see it.

Here is what I have now.

init.sqf

"packet" addPublicVariableEventHandler {
       _playerUID = _this select 1;
        };

_myaction = player addAction ["Call Hint", "addaction.sqf"];  

sleep 60;

diag_log format ["Player Server %1", _playerUID];

addaction.sqf

packet = [player, getPlayerUID player]; 
publicVariable "packet";
systemChat format["Player Client %1",packet];

This is the error I get from RPT.

17:59:06 "Player Server any"
17:59:06 Error in expression <;

diag_log format ["Player Server %1", _playerUID];>
17:59:06   Error position: <_playerUID];>
17:59:06   Error Undefined variable in expression: _playeruid
17:59:06 File mpmissions\__cur_mp.Altis\init.sqf, line 9

As you can see Player Server is "any" not the UID of the player that called the action.

I put the sleep 60 in so I could use the player action and was hoping to see the player UID in the report.

Edited by spitfire007

Share this post


Link to post
Share on other sites

this is because _playerUID will live only during EH execution, his scope is local to EH, try to store uid in a global var then log it

Share this post


Link to post
Share on other sites

I think I understand.

But I only get the player UID when the addaction.sqf is executed.

So I will have the same problem passing the global back to the server ?

Share this post


Link to post
Share on other sites

publicVariable : "Limitations: Cannot use reserved names, such as "player" or "west" or "side", etc. It is also not possible to transfer references to entities which are local, like scripts, displays, or local objects. Team Member is also not supported."

maybe its the reason of your problem

Share this post


Link to post
Share on other sites

Will this work on Arma 2 OA? 

 

I am having trouble using publicVariableServer/Client commands and also the BIS_fnc_MP seems not to work. Can anyone please provide help how to setup the init.sqf as an example to init the handlers?

 

I am trying to setup a server-client communication for an DayZ Epoch server script.

 

My Example Code:

if(isServer || isDedicated) {
	
	// Server?
	"packetServer" addPublicVariableEventHandler { 
		packetClient = [];
		publicVariableClient "packetClient"; 
	};
	
}
else {
	
	// Client?
	
	"packetClient" addPublicVariableEventHandler {
		hint "MSG FROM SERVER";
	};
	publicVariableServer = "packetServer";
	systemChat "Executed test.sqf";
	
};

Cheers,

SKO85

Share this post


Link to post
Share on other sites

As long as your OA install is patched to at least 1.62 publicVariableServer/Client should work.

 

BIS_fnc_MP, and this particular forum, is only for ArmA 3 but for the same type of usage for ArmA 2 you can check out the Multiplayer Framework.

Share this post


Link to post
Share on other sites

FAR out.

So I am stuffed.

Thanks for your help dude

Move diag_log inside publicvariableeventhandler, right after _playerUID

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  

×