Jump to content
Sign in to follow this  
Kettlewell

addPublicVariableEventHandler questions

Recommended Posts

Hello everyone, I've been digging into addPublicVariableEventHandlers recently because I needed to get data from the client side to server side but I've been having issues and I hoped that you could help me.

I have 3 files:

server/init.sqf

"updateDeath" addPublicVariableEventHandler {[] spawn updateDeath};

server/updateDeath.sqf - This is compiled with this line in the server/compile.sqf,

updateDeath = compile preprocessFileLineNumbers "server\updateDeath.sqf";

server/updateDeath.sqf - Actual code

hint "Debug";
_name = _this select 0;
_number = _this select 1;

hint format["Debug: %1, %2", _name, _number];

//Set the new death at the end of the array
DeadCall set [count DeadCall,[_name,_number]];

client/onKilled.sqf - Called as an event handler when a player is killed.

updateDeath = [name _player,(_player getVariable "PlayerNumber")];
publicVariableServer "updateDeath";

The problem is that updateDeath.sqf isn't being called and I don't even know if the variables I pass as parameters even work and with no error messages in the RPT I've been stuck to looking through the forums for an answer but it seems my inexperience of these systems really shows.

Can anyone shed some light on how I achieve this please? Thank you.

Edited by Kettlewell

Share this post


Link to post
Share on other sites

Are you running on a dedicated or true client/server setup? If client/server then you are probably not seeing the debug messages because they are being displayed on the server or at least that is my guess if you are not seeing any errors in RPT.

Also, are you setting _player somewhere? Perhaps you wanted just "player".

Share this post


Link to post
Share on other sites
Are you running on a dedicated or true client/server setup? If client/server then you are probably not seeing the debug messages because they are being displayed on the server or at least that is my guess if you are not seeing any errors in RPT.

Also, are you setting _player somewhere? Perhaps you wanted just "player".

I'm running the mission on local right now for testing purposes and I'm not seeing a response or any debug code written to the RPT so it's as if the updateDeath isn't being called at all.

I define _player in the top of the onKilled event as, _player = _this select 0;.

It uses this handle, player addMPEventHandler ["MPKilled", {_this spawn onKilled;}];

Share this post


Link to post
Share on other sites

You're spawning updateDeath but the function is compiled as callDead?

Share this post


Link to post
Share on other sites
You're spawning updateDeath but the function is compiled as callDead?

That's my fault copying the incorrect line sorry, fixed.

Share this post


Link to post
Share on other sites

Hi, you are overriding the variable updateDeath.

On the server:

//Prepare the function
updateDeath = compile preprocessFileLineNumbers "server\updateDeath.sqf";

//Add event handler, ofc, it cannot have same name as the above function...and where your problem lies.
"paramsDeath" addPublicVariableEventHandler {
  //The valriable name and value are returned by the event handler
  _name = _this select 0; //This will return "paramsDeath"
  _params = _this select 1; //This will be the parameters received from the publicVariableServer

  _params spawn updateDeath;
};

And then, on the client:

paramsDeath = [name _player,(_player getVariable "PlayerNumber")];
publicVariableServer "paramsDeath";

Share this post


Link to post
Share on other sites
Hi, you are overriding the variable updateDeath.

On the server:

//Prepare the function
updateDeath = compile preprocessFileLineNumbers "server\updateDeath.sqf";

//Add event handler, ofc, it cannot have same name as the above function...and where your problem lies.
"paramsDeath" addPublicVariableEventHandler {
  //The valriable name and value are returned by the event handler
  _name = _this select 0; //This will return "paramsDeath"
  _params = _this select 1; //This will be the parameters received from the publicVariableServer

  _params spawn updateDeath;
};

And then, on the client:

paramsDeath = [name _player,(_player getVariable "PlayerNumber")];
publicVariableServer "paramsDeath";

Thank you, you nailed the issues fully and it's working amazingly. Almost done with the battle royale mission haha.

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  

×