So I'm trying to get it so that it decreases food needs and such on think for player entities, but however it still isn't working Here is my code;
[lua]
local playTable=FindMetaTable("Player")
function playTable:AddBank(sum)
end
function playTable:TakeBank(amt)
end
function playTable:resetNeeds()
self:SetNWFloat("hunger",100)
self:SetNWFloat("rest",100)
self:SetNWFloat("thirst",100)
end
function playTable:Think()
self:SetNWFloat("hunger",self:GetNWFloat("hunger")-0.25)
self:SetNWFloat("thirst",self:GetNWFloat("thirst")-0.25)
self:SetNWFloat("rest",self:GetNWFloat("rest")-0.25)
return true
end
[/lua]
:wtc:
Use a timer. Even if this would work, you do not want to set an NWVar in a think hook.
[QUOTE=_nonSENSE;26257516]:wtc:
Use a timer. Even if this would work, you do not want to set an NWVar in a think hook.[/QUOTE]
Example please?
[lua]
timer.Create("hungThirRest"..pl:UniqueID(), 40, 0, function()
local h, t, r = pl:GetHunger(), pl:GetThirst(), pl:GetRest()
pl:SetHunger(h-0.25)
pl:SetThirst(t-0.25)
pl:SetRest(r-0.25)
end)
-- hook to PlayerSpawn or something
[/lua]
The Think() function is called every frame(?) by default.
Therefor you're setting it anywhere between what, 66-100 times a second?
You definitely don't want it to call in the Think function :p
[QUOTE=_nonSENSE;26257644][lua]
timer.Create("hungThirRest"..pl:UniqueID(), 40, 0, function()
local h, t, r = pl:GetHunger(), pl:GetThirst(), pl:GetRest()
pl:SetHunger(h-0.25)
pl:SetThirst(t-0.25)
pl:SetRest(r-0.25)
end)
-- hook to PlayerSpawn or something
[/lua][/QUOTE]
Thanks for pointing me in the general direction, you've saved me time as well. Thank you. :)
timer is the way forward.
Sorry, you need to Log In to post a reply to this thread.