• Send amount from client to server
    3 replies, posted
Hello, how to send an amount from a cl_init.lua to a init.lua ? for exemple: cl_init.lua [CODE] local amount = 10 RunConsoleCommand("_sendamount", amount) [/CODE] init.lua [CODE] function GotIt(ply, amount) ply:AddMoney(amount) end concommand.Add("_sendamount",GotIt) [/CODE] So what i want here, is to send the amount (10) from cl_init.lua to init.lua and then Add this amount to the player. But it doesnt work. Can you explain me the right way to proceed ?
Try not to use console commands unless you want users to use them outside of Lua. Instead, try: [LUA] --SERVERSIDE: util.AddNetworkString("sendamount") net.Receive("sendamount", function(length, ply) ply:AddMoney(net.ReadInt()) end) --CLIENTSIDE: local amount = 50 net.Start("sendamount") net.WriteInt(amount) net.SendToServer() [/LUA] That'll prevent players from running the console command when you don't want them to.
Getting this error [CODE] bad argument #2 to 'WriteInt' (number expected, got no value) [/CODE] ---------------------- EDIT -------------------------- I found the solution, thx for help.
concommands pass 3 arguments: player, command, args Player is, obviously, the player that ran the command. Command is the command you added (in this case, "_sendamount") Args is a table filled with strings- anything that comes after the command. In this case, use the first index of args instead of "amount". Keep in mind, relying on the client for adding money is a [i]very very very very[/i] bad idea.
Sorry, you need to Log In to post a reply to this thread.