PDA

View Full Version : OnPlayerDisconnect


Janoz12
20/06/2019, 03:02 PM
I have a problem with the OnPlayerDisconnect callback.

The issue is that I have variables and objects for the players, these variables are restarted when leaving and the objects destroyed when leaving, but there is a problem that happens with the users who are still on the server.

For example, a user puts an object, and any other user leaves the server and that object is erased to the user who is still inside, the function is defined with MAX_PLAYERS and [playerid] so I do not understand why that happens.

The same happens with the variables is very annoying because sometimes that's the reason why there are players who are affected by not being able to use certain things from the server because the variables are reset.

public OnPlayerDisconnect(playerid, reason)
{

DestroyDynamicObject(cone[playerid]);
DestroyObject(stop[playerid]);
variable[playerid] = 0;
KillTimer(test[playerid]);
red[playerid]= 0;
blue[playerid]= 0;
green[playerid]= 0;

return 1;
}

Threshold
21/06/2019, 05:00 AM
You're not resetting the variables 'cone' and 'stop'. So they retain their values.

public OnPlayerDisconnect(playerid, reason)
{

if(IsValidDynamicObject(cone[playerid]) DestroyDynamicObject(cone[playerid]);
cone[playerid] = INVALID_OBJECT_ID;
if(IsValidObject(stop[playerid]) DestroyObject(stop[playerid]);
stop[playerid] = INVALID_OBJECT_ID;
variable[playerid] = 0;
KillTimer(test[playerid]);
red[playerid] = 0;
blue[playerid] = 0;
green[playerid] = 0;
return 1;
}

I've used INVALID_OBJECT_ID as a default value for these variables, you can use any value you want so long as it doesn't represent an actual object in-game. The rest of your script should follow suit with the value that you choose.