Jump to content
Lorenz94

publicVariable Client/Server

Recommended Posts

Hello,

I'm trying to give players joining a server a variable based on what the server has as reply from a query to a database.

 

The query is fine, I've got my value out of it. What I would like to do, is to change the value of this variable freely on the server, so that a player only needs to re-connect to have its value updated (in this particular case, the variable allows players to fly CAS aircrafts).

 

What I've done so far works, just for the first connection! If a player reconnects (without a server restart), the value of the variable is no more assigned on client, because, from what I understand, addPublicVariableEventHandlers triggers only when the variable changes. So I don't know how to work around this "issue", avoiding the need of telling players they need to wait for a complete server restart to fly.

 

Code:

Spoiler

//DEDICATED - function called FROM a PlayerConnected EH, so params are passed; uid needed for the query

params ["_uid", "_owner"];

_isWhitelisted = //my query result

isWhitelisted = _isModerator;
_owner publicVariableClient "isWhitelisted";

/////

//CLIENT

"isWhitelisted" addPublicVariableEventHandler {
   _value = _this select 1;
   player setVariable ["CAS", _value];
};

//Testing from debug console once connected
//Variable assigned only on first connection, reconnecting hints "nope!"

_var = player getVariable ["CAS", "nope!"];
hintSilent str _var; //First connection gives true/false, reconnection give nope!

 


Thank you for the precious help!

Edited by Lorenz94
updated

Share this post


Link to post
Share on other sites

I think the solution would be to use something like "initPlayerServer.sqf" where the query is done and variable send to client. everytime player joins the server initPlayerServer.sqf should be automatically executed

Share this post


Link to post
Share on other sites
Just now, gc8 said:

I think the solution would be to use something like "initPlayerServer.sqf" where the query is done and variable send to client. everytime player joins the server initPlayerServer.sqf should be executed

Hello gc8,

this is exactly that the PlayerConnected MEH does! So I don't think would change the result

Share this post


Link to post
Share on other sites
2 minutes ago, Lorenz94 said:

Hello gc8,

this is exactly that the PlayerConnected MEH does! So I don't think would change the result

 

Sorry I missed that.

 

But your params list is wrong in the PlayerConnected. They should be:

 

params ["_id", "_uid", "_name", "_jip", "_owner"];

 

The one you have there now ( params [_uid, _owner]; ) I think it's not a valid syntax

Share this post


Link to post
Share on other sites
3 minutes ago, gc8 said:

 

Sorry I missed that.

 

But your params list is wrong in the PlayerConnected. They should be:

 


params ["_id", "_uid", "_name", "_jip", "_owner"];

 

The one you have there now ( params [_uid, _owner]; ) I think it's not a valid syntax

Probably my example code has been not well explained, sorry! I updated it. The two params are at the beginning of a function called from inside the EH, so they are fine 🙂

Share this post


Link to post
Share on other sites
3 minutes ago, Lorenz94 said:

Probably my example code has been not well explained, sorry! I updated it. The two params are at the beginning of a function called from inside the EH, so they are fine 🙂

 

Ok but make sure you put those params inside quotes or it wont work

Share this post


Link to post
Share on other sites
4 hours ago, gc8 said:

 

Ok but make sure you put those params inside quotes or it wont work

Was a typo! As I stated before, the query is ok and the variable IS being transmitted on first connection. If someone exits from the server and rejoins (without a server restart), the variable is no more casted.

 

The problem is my poor understanding of the "ping-pong" made with publicVariableClient/Server, the issue to me seems to be that the variable doesn't change value and so the variableEH does not get triggered, so I'm kindly asking here hoping to have confirms / denials about this fact and my code.

 

Thank you all

Share this post


Link to post
Share on other sites

A PVEH is only ever triggered when the assigned variable is broadcasted via the publicVariableXXX command family.

 

If you need to ping pong info back and forth there needs to be a separate PVEH on the server and the client where the client requests the info and the server sends it.

 

Basically the client PVs to the server saying “hey I need this info and here is my unique ID” server queries it and sends it back to the requesting client via publicVariableClient.

 

On my phone or I would throw an example up.

  • Like 2

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

×