Setting values for 1 person only

So this is just something I would like to use for many different things, and I just don’t know how to make it work. What I mean, for example, if a player type “!makemyvalueone” then for that player it would be value = 1 and then they type “!makemyvaluezero” then it would do value = 0. I have set this up before, but it applies to everyone, not just that one person. I would like to do things like

if value = 1 then
blah blah

and I can use this for many things. How can I set this up so it only applies to that one person?

ply.value = 1
print(ply.value)

Where ply is a player object.

Make sure your values are unique and don’t collide with values from other addons.

Such values** ARE NOT TRANSMITTED TO CLIENT FROM SERVER AND FROM SERVER TO CLIENT.**

If you want to share it between server and client, on the server, use NW vars. If on the server only you can just do ply.<var> or ply:SetVar(“varname”,value)

Theres alot of ways, depents what you want. Lets say that you want to do it on server side.

I’ll make a command so we already know who ply is:




concommand.Add("SetPlyValue", function(ply, cmd, args)

	//If the value is nill then set it, otherwise, print it.
	if !IsValid(ply.AwesomeValue) then
		ply.AwesomeValue = "Hello there!"
	else
		print(ply.AwesomeValue)
	end

end)


You shouldn’t be using IsValid like that. That’s a pointless call. Use not, !, or
[lua]player.value = player.value or “Default”[/lua]

Here’s a very light-weight version of my networking / data system: https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/simple_networking_system/sh_basic_networking_and_data_system.lua.html remove .html to view .lua - place in addons/acecool/lua/autorun/ – I haven’t tested this yet so if you run into any problems let me know…

And it’ll support setting values to entities / players / weapons / npcs / etc…

You can call data:GetFlag( _id, _flag, _default, _private ); or data:SetFlag( _id, _flag, _value, _private ); where _id can be an entity or the EntIndex of an entity, _flag should be a string identifier ( case sensitive ), _default is the default value to use in Get, _value is the value to set in Set ( Additionally, the networking to client(s) is only processed if the value differs from the current value ) and _private is a boolean true/false which defines whether or not the data is private…

Alternatively, you can use _ent:GetFlag( _flag, _default, _private ); or _ent:SetFlag( _flag, _value, _private ); where everything is the same as above except _ent is the variable you use as a reference to an entity / player / etc…

In short… If you SetFlag on the server then the server will always know the value. If it gets networked depends on a few factors…
If the _private value is not used or false then EVERYONE knows the value.
If the _private value is used as true then it depends on the type of entity used to determine networking ( If player entity then the SERVER and the PLAYER will know it, but no one else will… If non-player entity is used then only the SERVER knows it )…

Likewise, if you use SetFlag on the client, then only the LocalPlayer will have access to those variables and they won’t be networked… This was done so the server can send updates but the client won’t have that ability to update the server…

Hopefully this is clear enough; if you decide to use this and have questions, feel free to add me on Steam or message me here.

If you wat to make it yourself search about NWVars, or if you want more optimized just look for net messages.

Because if that’s for one player with no need that everyone can read the value, then use :



util.AddNetworkString("MyValueSender")
local myInt = 2
function IDontKnow(ent)
   net.Start("MyValueSender")
   //That depends on the value type, if it's bool then WriteInt, int WriteInt, byte WriteData, string WriteString, assume we have an int to write
   net.WriteInt(2, 4) //4 is the byte number, here we don't need much bytes to write a 2 integer.
   net.Send(ent)
end


If you don’t for the bits number, then i can’t realy help you, but i can just redirect you to informatic base programming book, because it’s how C language is working…

Here’s something on Bit counting to go with Yuris’ post: https://dl.dropboxusercontent.com/u/26074909/tutoring/networking/bit_counting.lua.html

WriteInt is signed meaning 1 bit is used to denote + or - so you’ll want +1 bit for the number range unless you use WriteUInt ( unsigned Integer meaning no bit describing +/- ).