Setting variables to 0 on disconnect..?
#1

I've noticed that many people in their gamemodes set player variables to 0 when they disconnect. Let's say there's a variable named "Muted". It's set to 0 on onplayerconnect. Still many people sets it back to 0 on onplayerdisconnect. As far as I know, I think that's completely unnecessary. But I'd like to hear your opinion about that. Why do people do that?
Reply
#2

I'm setting everything to 0 when the player disconnects. I don't see the point of resetting it again under OnPlayerConnect
Reply
#3

Oh uh! Nevermind this! I thought that player variables would go back to 0 upon reconnect even though not set back to 0!
Reply
#4

They probably just have no idea what they're doing, and really aren't experienced scripters. Or, maybe there's a reason dependent on that certain script, how-ever I personally wouldn't reset them both on both of those conditions.
Reply
#5

Im not 100% sure but its logical to me they set variable at 0 onplayerdisconnect because of this;

Lets say your playerid is 5
your playerid '5' is for example set to a variable like Myvar[playerid] = 1; (so actually Myvar[5] =1;

If id 5 disconnects the player will be gone but playerid 5 will stay as an empty slot untill a new player comes online.
The new player will have also id 5 because that slot was empty because that player disconnected right ?
Yes! so..the new player suddenly has Myvar[5] =1; and you probably dont want that..
so thats why mostly players reset variables at disconnect.
SetPVar however..are deleted automaticly.

I hope i explained it clear enough im kind of known by my chaotic explaining
Reply
#6

Quote:
Originally Posted by AIped
Посмотреть сообщение
Im not 100% sure but its logical to me they set variable at 0 onplayerdisconnect because of this;

Lets say your playerid is 5
your playerid '5' is for example set to a variable like Myvar[playerid] = 1; (so actually Myvar[5] =1;

If id 5 disconnects the player will be gone but playerid 5 will stay as an empty slot untill a new player comes online.
The new player will have also id 5 because that slot was empty because that player disconnected right ?
Yes! so..the new player suddenly has Myvar[5] =1; and you probably dont want that..
so thats why mostly players reset variables at disconnect.
SetPVar however..are deleted automaticly.

I hope i explained it clear enough im kind of known by my chaotic explaining
You pretty much explained it everything! I had to give it a try and created a simple CMD to set Muted to 1 and another CMD to detect whether Muted is 0 or 1. After setting Muted to 1, I reconnected and it was still 1. Kaboom solved! Thanks to ya'll! Rep will be given to ya'll for atleast coming by and stating your opinion.
Reply
#7

is because they not understand whats works your code. If is configured the value to default on OnPlayerDisconnect is not necessary the setting again on OnPlayerConnect
Reply
#8

Quote:
Originally Posted by ******
Посмотреть сообщение
It depends on what you want the default values to be. Most variables are 0 by default, so when the first players connect there is no need to set those values to 0 in OnPlayerConnect. Of course, they still need resetting at some point - hence OnPlayerDisconnect.

On the other hand, if the variables shouldn't be 0 by default then you may need to set them in OnPlayerConnect, in which case there is an argument for doing them all there for consistency.
Then again for consistency of data if the player is not connected you might want any values cleared as well in on OPD although you could check if the player is connected anyways. It's probably six of one, half a dozen of the other for the most part.
Reply
#9

Setting the variables to 0 in "OnPlayerDisconnect" is just to clarify the player's stats reset (when not logged in). That way it doesn't say something like you have "5 Score" on a connection.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)