• How can I limit variables to be client side only.
    6 replies, posted
Ok, I'm very new to all this lua scripting stuff and I was wondering if there was anyone that might be able to help me figure this out. So I have certain variables right, and I'm using them to count how many times the player executes my command, there is just one small problem however; each person should be able to use the command a maximum of ten times, but when I go on multiplayer, I can only execute the command ten times for all the players combined, and not ten times for each individual player. How can I make the variables client side only so that [B]EACH[/B] player can enter the command ten times. Keep in mind that when I say variable I mean these things: "local count = 0 outof = 10"
Assign the variable to the player object like so local ply = Entity( 1 ) // This is your player object variable ply.MyCommandUseTimes = 0 // Assign a custom variable to player object. Keep in mind that for security purposes you [b]have[/b] to do these things [b]serverside[/b] and then network them to client if necessary. See also SetNW* functions on the wiki.
Here is an example: [CODE] function MyCommand(ply,cmd,args) ply.CommandUses = ply.CommandUses or 0 -- Create Varible. if ply.CommandUses < 10 then -- Check if its been used more than 10 times -- Run more than 10 times. return end ply:ConCommand("say hello") -- Do whatever. ply.CommandUses = ply.CommandUses + 1 -- Used the command so lets add one. end concommand.Add("hello_server", MyCommand) -- Create Command. [/CODE]
[QUOTE=Robotboy655;51564626]Assign the variable to the player object like so local ply = Entity( 1 ) // This is your player object variable ply.MyCommandUseTimes = 0 // Assign a custom variable to player object. Keep in mind that for security purposes you [b]have[/b] to do these things [b]serverside[/b] and then network them to client if necessary. See also SetNW* functions on the wiki.[/QUOTE] That you for your response! But I'm sorry, I don't quite understand what you're trying to show me. It's my fault, I'm very inexperienced when it comes to this whole scripting business. I'm trying to get variables to remain on the client side only and I really don't understand what assigning numbers to every entity will do because then I'd have to make a variable for each player on the server. I don't mean to be rude I'm just genuinely confused on the matter.
[QUOTE=Axon9000;51564742]That you for your response! But I'm sorry, I don't quite understand what you're trying to show me. It's my fault, I'm very inexperienced when it comes to this whole scripting business. I'm trying to get variables to remain on the client side only and I really don't understand what assigning numbers to every entity will do because then I'd have to make a variable for each player on the server. I don't mean to be rude I'm just genuinely confused on the matter.[/QUOTE] Variables don't just jump between the client and the server they have to be networked. If you mean you want it to save on the client then you do this by using ConVars. [url]http://wiki.garrysmod.com/page/Global/CreateClientConVar[/url]
Variables declared in files included by init.lua are on the server only Variables declared in files included by cl_init.lua are on the client only Variables declared in shared.lua exist on both the client and the server (unless you block them off using code like) [code] if SERVER then -- variables end if CLIENT then -- variables end [/code] ... but if you change their value, the value won't be changed anywhere else, unless [i]you send[/i] that value to the server or to the client (respectively).
[QUOTE=Axon9000;51564742]I really don't understand what assigning numbers to every entity will do because then I'd have to make a variable for each player on the server. I don't mean to be rude I'm just genuinely confused on the matter.[/QUOTE] That's exactly it. It's not making it "client side", it's having a unique count for each player.
Sorry, you need to Log In to post a reply to this thread.