Store lua var on player.

I need to store the amount of points a player has serverside until the player disconnects. How do I do this?

get the player object and do
[lua]local ply = player_you_want
ply.variable = value_you_want_to_save[/lua]

I need to store it for everyone on the server.

Store it for what use?

use this :

MyPlayer:SetNWString( “myvaluename” , “oh hai!” )

MyPlayer:GetNWString( “myvaluename” ) – should return “oh hai!”

And if he wants a serverside only value? Or a value to be saved for next use? OP isn’t being descriptive enough.

I need to have a value for each player, serverside only, that only stays on the server until server quit (AKA not stored in a mysql database like DarkRP).

Then do what CmdrMatthew said.

So do I store it in an array or something?

The player variable is like a table.
You store a variable on it just like you would any other table.

[lua]for _,pl in pairs(player.GetAll()) do
pl.MyVariable = true;

I’ll just explain in full: I want to have a points system, like in Obsidian Conflict. I want a server side command to add and delete points. I need someway of storing the point value for every player serverside until disconnect

Learn basic lua first

The above code shows you how to store a value on the client then you simple make two console commands to do arithmetic that you desire on the value. If you are unable to do that I suggest you go to the request section, or you try and learn lua and not get everything handed to you on a silver platter.
Also if you are making a point system and you want the clients to be able to see how many points they have at a given time then your going to need to use Ningaglio’s code or Usermessages( You will most likely flame me for not just giving you the code and telling you where to put it but in the long run if you are serious about learning lua then your going to need to learn how to do things for your self.

On a side note if none of what I said applies to you then just rate me dumb and I will be on my way.

This adds one point every time a player kills another player, then prints the total number of points he has acquired when he leaves.
function MySpawnHook( ply )
ply.Points = 0

function KillHook( victim, weapon, ply )
ply.Points = ply.Points + 1

function SomeoneDisconnected( pl )
print( pl:GetName() … " racked up an amazing " … pl.Points … " points before leaving!" )

hook.Add( “PlayerInitialSpawn”, “SpawnHookName”, MySpawnHook )
hook.Add( “PlayerDeath”, “KillHookNameHere”, KillHook )
hook.Add( “PlayerDisconnected”, “CantBeBotheredToName”, SomeoneDisconnected )[/lua]


Thanks, that’s what I needed. Now I get how Entoros’s code could do what I want.

[editline]28th December 2010[/editline]

Really, stop being a dick. I’m just asking for some help with lua. That’s what this forum is about. Don’t make fun of people because they know less than you.