• Stamina Not working right
    5 replies, posted
Hi.. again, well I created a stamina function err multiple stamina functions out of my ass, I attempted to re-write it but yeah it's still coming out clusterfuckish. I don't see why it's not working though... There's no errors either. :/ Init.lua: [lua] timer.Create("sprint",3,0,function() for _,v in pairs(player.GetAll()) do if v:KeyDown(IN_RUN) and v:GetVelocity():Length() > 1 then v:EditStamina(Take,1) end end end) timer.Create("addstamina",2,0,function() for _,v in pairs(player.GetAll()) do if v:GetVelocity():Length() == 0 then v:EditStamina(Add,1) end end end) function Print(ply) PrintMessage(HUD_PRINTTALK,"Stamina: "..ply:GetStamina()) end concommand.Add("stamina",Print) timer.Create("checksprint",1,0,function() for _,v in pairs(player.GetAll()) do if v:GetStamina() <= 0 then v:SetRunSpeed(100) v:SetWalkSpeed(105) elseif v:GetStamina() <= 10 then v:SetRunSpeed(125) v:SetWalkSpeed(115) elseif v:GetStamina() >= 25 then v:SetRunSpeed(DEFAULT[2]) v:SetWalkSpeed(DEFAULT[3]) end end end) [/lua] sh_meta.lua: [lua] function meta:GetStamina() return self.Stamina end function meta:SetStamina(amt) self.Stamina = amt --umsg.Start("sendExp") --umsg.Long(amt) --umsg.End() self:SetPData("Stamina",amt) end function meta:EditStamina(typ,amt) if typ == "Take" then self:SetStamina(math.Max(0,self:GetExp()-amt)) end if typ == "Add" then self:SetStamina(self:GetStamina()+amt) end end [/lua]
your edit stamina function is useless, you can just use SetStamina() to take away or add just thought I'd let you know
Debug it with print's to find out what's going wrong.
Well, found out it's the checking function, don't know what it is though...
Just print GetStamina() each time you use it to see if its what is expected
I fixed it, the key was IN_SPEED.
Sorry, you need to Log In to post a reply to this thread.