I have a ulx command that lets players buy grenades, but I'm having trouble resetting the variable.
How would I go about resetting it?
Players are only allowed to buy 2 per round, so I need the reset at the start or end of each round.
I tried using hook.Add with OnRoundStart, but it did nothing.
Partial code example
[lua]
local hasboughtnades = 0
for i=1,num do
hasboughtnades = ( hasboughtnades + 1 ) -- This runs when a players buy one
end
[/lua]
If you want to limit the players to buy stuff, instead of localizing a variable, you should store a variable IN the player, as so:
[CODE]
player.Variable = SOMETHING
[/CODE]
Then, in a hook as hook.Add you could do something like
[CODE]
hook.Add("OnRoundStart", "ResetAllPlysData", function()
for k, v in pairs(player.GetAll()) do
v.Variable = 0
end
end)
[/CODE]
That didn't change anything. Still not able to reset the value.
Using prop hunt. There's OnRoundStart and RoundStart.. neither of them work with it.
[QUOTE=covey88;51941471]Using prop hunt. There's OnRoundStart and RoundStart.. neither of them work with it.[/QUOTE]
How are you resetting the variables? Can we see your code?
Well the code is kinda torn apart right now due to testing other stuff with it, but I'll post it if needed when I get it back together.
But, I've never had to store to a player before and I think I'm just doing it the wrong way.
I've tried following examples I found in different threads but they've just disabled the code altogether.
Could I get an example of how to store a var to a player and to reset it? or at least point me to a good example of it.
So would it be something like this?
[lua]
function apples(ply)
if ply.apples <= 2 then
ply.apples = (ply.apples + 1)
end
end
hook.Add("OnRoundStart", "removeapples", function(ply)
ply.apples = 0
end)
[/lua]
Yeah. Also, just a general tip; localize your functions too when making them. Most of the time, they don't need to be global.
I can't get it to work
This is basically what I have (I removed a lot of irrelevant code)
What am I doing wrong?
[lua]
-snip-
[/lua]
Nevermind, had other issues that conflicted with it. It is now working fine, thanks for all the help.
Sorry, you need to Log In to post a reply to this thread.