Jump to content
Sign in to follow this  
kaski

Transfering variables client/server

Recommended Posts

I want to transfer some variables from client to server. I already found this thread. I don't want to use CBA addon so I'm trying to do this with variables found here.

I have this in my client side:

	playerDeathTime = 1;
publicVariableServer "playerDeathTime";

And this in my server files:

_deathTime = playerDeathTime;

But the value is never transfered to the server.. How to use publicVariableServer properly?

Share this post


Link to post
Share on other sites

I'm sure the value is successfully transferred to the server, but the way you check on the variable is wrong.

You assign playerDeathTime to some local variable at any time in your server files, which will result that (in case the variable is a POD) the content of playerDeathTime will be copied to the variable you assign it to.

Now you set playerDeathTime in some client and send the value to the server - what do you expect to happen now? :D Well, nothing, playerDeathTime gets updated but the value in _deathTime won't, because you have to assign it another time to update _deathTime;

Either you have to use playerDeathTime directly without assigning it to another variable or use addPublicVariableEventHandler to react to every change of playerDeathTime .

Share this post


Link to post
Share on other sites

Still not working, however now server atleast gets something I guess. I'm having for loop for 10 seconds (runs once every second) which will update this variable on every run to value.

_timeOutDead = 11;
_btnAbort ctrlEnable false;
for [{_i=1}, {_i<_timeOutDead}, {_i=_i+1}] do
{
playerDeathTime = _i;
publicVariableServer "playerDeathTime";
   sleep 1;
};
playerDeathTime = 0;
publicVariableServer "playerDeathTime";
_btnAbort ctrlEnable true;

When player disconnects, following script will run:

if (playerDeathTime > 0) then {
diag_log format["LOGGED OUT TOO EARLY: %1 ", _playerName];
}
else
{
};

I did connect fast enough and I don't see any entries in .RPT file. I added this above if:

diag_log format["PLAYERDEATHTIME: %1 ", playerDeathTime];

And now I'm getting this on log:

20:54:08 "PLAYERDEATHTIME: any "

What I am doing wrong?

Share this post


Link to post
Share on other sites

Well the first thing would be: Why in the name of god do you count a value in one client and publish the counter to the server every second?

Furthermore I hope you know that if this is for MP, you're gonna have massive headaches because if every player counts that variable and sends the value to the server, you'll get a big chaos serverside :D

As far as I can see you're trying to log every player who ALT+F4's off of your server BEFORE the 10 seconds are passed; what you need is to use the PVEH in combination with a slight more complex playerDeathTime.

I have another approach I'd like to present to you:

  1. disable the abort-button
  2. set a variable of the player which shows that he attempts to logout
  3. count down till zero
  4. enable abort button
  5. set the variable again that the player waited for ten seconds
  6. on disconnect, check the variable for successful value

The thing is: I don't know anymore if you can access the player's object when in onPlayerDisconnected - if the player's object is gone before getting into that event handler, my approach would be void.

BIKI says that three variables are implicitely set, but none of them sound useful for this case.

Another approach would be:

  1. disable the abort-button
  2. set playerDeathTime = getPlayerUID player and send it to the server
  3. the server receives the new value in the PVEH and waits for another event with the same value.
  4. count down till zero
  5. enable abort button
  6. send playerDeathTime to the server again
  7. now the server can check if the response was within (timelimit * 1.5) when the player disconnects

Why did I meantion timelimit * 1.5 you might ask? Well, you have to take network load into consideration which could delay your message (normally nothing more than a fraction of a second) so you have to make sure that the response is given some tolerance.

I really, really, really (!) hope that there is a more elegant and easier way to do this, so let's hope that K_K enters the fray and saves the day :b

Share this post


Link to post
Share on other sites

"PLAYERDEATHTIME: any "

reads like its not being broadcast. setup a PVEH like animus said and you should be good. and just to hit on what animus said about the alt - f4 ing. if that's what your trying to detect, you could use a displayEventHandler for those keys.

add this to every player. thru init or where ever.

waitUntil {!(isNull (findDisplay 46))};
menu = (findDisplay 46) displayAddEventHandler ["KeyDown", "_this call cheating_SOB"];

cheating_SOB - being the script name it calls on :)

then in that script

private["_handled", "_ctrl", "_dikCode", "_shift", "_ctrlKey", "_alt"];
 _ctrl = _this select 0;
 _dikCode = _this select 1;
 _shift = _this select 2;
 _ctrlKey = _this select 3;
 _alt = _this select 4;

if (_alt && _dikCode == 62) then
 {
run whatever code
 };

and anytime that key combo is hit it will run your code.

you'll still have to setup your PVEH to transfer whatever data over the network though.

its just another way to keep track of button pushes.

Edited by Nimrod_Z

Share this post


Link to post
Share on other sites

Yeah, the easiest approaches are the most effective ones, I tend to forget these until someone barges in and shows us the way xD (like nimrod did here :D)

But what if the player uses Alt + Tab to tab out and uses the TaskManager to kill the process?

I mean you can't do anything like punishing the user just because he tabs out of a game :D

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  

×