Set a variable for each player until Mapchange


as the title of this thread already spoils i want to set a variable for each player individually until the map change or the server restarts.
I need this because i think its the best way to make traitor passes for ttt that are limited on 1 round and i also couldn’t find a pre-made script for this.

ply.variable = true

Where ply is the player object, variable is the name of the variable and true is the data.

That’s a bad system, since getPlayer() doesn’t preserve custom userdata tags. You’ll want to use the Get/SetNW commands;

ply:SetNWBool(“variable”, true)
ply:SetNWString(“othervariable”, “text”)
print(ply:GetNWBool(“variable”) … " " … ply:GetNWString(“othervariable”))

getPlayer() isn’t a default Gmod function but in every other scenario (player.GetAll()) the custom tags are preserved. Not sure what you are talking about because there is no need to network a variable if you don’t have to

If getPlayer() isn’t a default garrysmod function, then where does it come from?

Ok this works now pretty stable thanks to Maurdekye.

Another question: i can test for the number of player with this script or?

	if #player.GetAll() <= 4 then
		return false, "Es muessen mindestens 5 Spieler auf dem Server sein."

It’s coming from one of your addons.

That is… well, shit. Guess I’ve never worked with improperly qualified languages before.

I’d better implement it myself, then.

[editline]13th April 2015[/editline]

Wait, I just realized that I did have it implemented myself…

What does your getPlayer() function even do? Sounds shit :v:

function getPlayer(name)
name = string.lower(name);
for _,v in pairs(player.GetAll()) do
if string.find(string.lower(v:Name()),name,1,true) != nil then
return v;

By Exho’s explanation, it should work with custom userdata tags, even though it doesn’t. Which is even weirder.

ähm… could someone say if i am fetching the player count right or not?

Yes that was correct.


No, it does work.
I am sure you just failed to test it properly / poorly implemented it