Jump to content
Naiss

HandleDisconnect with remoteExec

Recommended Posts

Im trying to make the stats save once the player dc but nothing is working for me atm and i understand that remoteExec is not working because the player is nil.

 

Is there anyway to execute a function to the player before it turn into nil so i can save some variables like inventory, etc

 

 

My code:

 

addMissionEventHandler ["HandleDisconnect",{
_unit = _this select 0;
_uid = _this select 2;
[_uid] remoteExec ["extDB_Disconnect",_unit];
deleteVehicle _unit;
diag_log format ["saved: %1 | %2",_unit,_uid];
}];

 

RPT Error message:

A nil object passed as a target to RemoteExec(Call) 'extdb_disconnect'

Share this post


Link to post
Share on other sites

What's the format for extdb_disconnect?

 

You're trying to run this where _unit is local?

extDB_Disconnect _uid; // or _uid extDB_Disconnect

Can't find any docs about extDB sql commands, so.. not sure.

Share this post


Link to post
Share on other sites

The unit is no longer accessible by the owner command once they disconnect. Their corpse and public variables stored in their corpse namespace will be accessible but can't send them anything once they have left.

Share this post


Link to post
Share on other sites

What's the format for extdb_disconnect?

 

You're trying to run this where _unit is local?

extDB_Disconnect _uid; // or _uid extDB_Disconnect

Can't find any docs about extDB sql commands, so.. not sure.

 

its just a function i made that saves the stats for the player

Share this post


Link to post
Share on other sites

I believe the problem is with the use of the remoteExec command within the event handler. If the player has disconnected, how are they able to remoteExec the function?

Share this post


Link to post
Share on other sites

You are trying to remote execute function on the computer that has already disconnected

Share this post


Link to post
Share on other sites

i know i just tried to check if it worked but ofc it did not work so im stuck here now on getting the player stats saved when a player disconnect.

 

 

Is there no way to get a variable from the client that is disconnecting at all?

Share this post


Link to post
Share on other sites

You are using remoteExec wrong.

// Runs:  [_user, _uid] call extDB_Disconnect; only on the server.
[_user, _uid] remoteExec ["extDB_Disconnect", 2];

// Runs:  [_uid] call extDB_Disconnect; only where _unit is local (ie, nowhere since it's disconnected)
[_uid] remoteExec ["extDB_Disconnect", _unit];

Share this post


Link to post
Share on other sites

 

You are using remoteExec wrong.

// Runs:  [_user, _uid] call extDB_Disconnect; only on the server.
[_user, _uid] remoteExec ["extDB_Disconnect", 2];

 

This makes even less sense, since "handledisconnect"  is server only

Share this post


Link to post
Share on other sites

Ahh, so he just needs to run his function and not remoteExec anything. :)

Share this post


Link to post
Share on other sites

It still wouldn't work if he made it call a function. He wants the function to be run on the client whereas the event handler is server side. An alternative is to hook the exit button on the main menu for the client. However, this does not account for those who disconnect via other means.

Share this post


Link to post
Share on other sites

The Handledisconnect is running from serverside thats why im executing it back to the client but the client is not on so ye wont work.

Share this post


Link to post
Share on other sites

Use a key Down event handler and capture the press of esc key.

Unless the client alt+f4 out of game this will allow you to save stats before they disconnect.

The remote exec you are using can clean up the players body and equipment to stop duping of gear.

Assuming life wasteland style mission here.

  • Like 1

Share this post


Link to post
Share on other sites

The Handledisconnect is running from serverside thats why im executing it back to the client but the client is not on so ye wont work.

Are you saving stuff on client?

Share this post


Link to post
Share on other sites

Use a key Down event handler and capture the press of esc key.

Unless the client alt+f4 out of game this will allow you to save stats before they disconnect.

The remote exec you are using can clean up the players body and equipment to stop duping of gear.

Assuming life wasteland style mission here.

im making my own framework from scratch thats why i need this :P

 

 

Are you saving stuff on client?

 

Yes i need stuff saved on the client, i got a loop that will save every x minutes but if the dc before it saves they lose stuff and i don't want that to happen

Share this post


Link to post
Share on other sites

You shouldn't save stuff on the client, the server should save it. Otherwise the player may be able to edit their data from their computer.

Share this post


Link to post
Share on other sites

well first it will start at the client to get the variables details etc etc and then i will return that to the serverside witch will save it

Share this post


Link to post
Share on other sites

well first it will start at the client to get the variables details etc etc and then i will return that to the serverside witch will save it

 

That's still the same problem.  Lets say moneyAmount is one of your values.  I log in and play, earn $2000 and log off and you save $2000 to my client.  I pop into my vars.Arma3Profile file or whatever it is, change that to 2000000.  Log back in, your server pulls my data, assigns me 2 million bucks and off I go.  

 

You cannot trust anything from a client.

Share this post


Link to post
Share on other sites

That's still the same problem.  Lets say moneyAmount is one of your values.  I log in and play, earn $2000 and log off and you save $2000 to my client.  I pop into my vars.Arma3Profile file or whatever it is, change that to 2000000.  Log back in, your server pulls my data, assigns me 2 million bucks and off I go.  

 

You cannot trust anything from a client.

thats not how im saving stats and store the variables, all the client variables are server sided and return them to the client after loadup.

 

Im saving the stats with extDB2 and they can't change there stats that way.

Share this post


Link to post
Share on other sites

You could probably run a loop on the server that saves player data to the database once a minute.

 

I'd probably try that rather than try to intercept all the ways they can disconnect (alt f4, pull router cable out, use the in game menu etc)

Share this post


Link to post
Share on other sites

i got a loop that is saving every 1 minute but i don't really like running loops because that's whats going to lower the server fps and yes i know that some stuff you just need to run a loop on :P

 

How about when they click ESC it will save the stats? but what if they spawn ESC can that cause problem with the database?

Share this post


Link to post
Share on other sites

Loops are fine if done correctly. If you have a loop which saves every connected client's stats all at once then yes, performance will take a hit. If you pace them out then the performance will not be affected.

  • Like 2

Share this post


Link to post
Share on other sites

Sounds good but how about the ESC button as well for saving?

Share this post


Link to post
Share on other sites

is this a mission or a mod? if it's a mod you could hack the menu UI and have your own cool down timer on ESC and stuff. i mean sure there's still alt+F4 and game crashes but to that i'd say "shit happens" :lol:

  • Like 1

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

×