Hi, i've recently find a stamina code on PasteBin.
Everything works, exept a very important thing.
The stamina isn't refueled to the player.
Here's the code :
[QUOTE]autorun/stamina.lua[/QUOTE]
[lua]
if CLIENT then
if not FStaminaToggled then
function FStamina_Draw()
if LocalPlayer():GetNWInt( "FStamina" ) then
if LocalPlayer():Alive() then
local Fx = ( ScrH()/23.272727272727272727272727272727 )
local Fy = ( ScrH()/1.0385395537525354969574036511156 )
local Fx = ( ScrW()/6.7368421052631578947368421052632 )
local Fy = ( ScrH()/146.28571428571428571428571428571 )
draw.RoundedBox( 4, Fx, Fy, Fx, Fy, Color( 90, 90, 90, 255 ) )
if LocalPlayer():GetNWInt( "FStamina" ) > 1 then
draw.RoundedBox( 4, Fx, Fy, Fx*( LocalPlayer():GetNWInt( "FStamina" )/100 ), Fy, Color( 255, 242, 0, 255 ) )
end
end
end
end
hook.Add( "HUDPaint", "FStamina_Draw", FStamina_Draw )
end
end
if SERVER then
if not FStaminaToggled then
function FStamina_Spawn( ply )
ply:SetNWInt( "FStamina", 100 )
end
hook.Add( "PlayerSpawn", "FStamina_Spawn", FStamina_Spawn )
function FStamina_MainThink()
for k, ply in pairs( player.GetAll() ) do
if ply:GetNWInt( "FStamina" ) < 0 then ply:SetNWInt( "FStamina", 0 ) end
if ply:GetNWInt( "FStamina" ) > 100 then ply:SetNWInt( "FStamina", 100 ) end
if ply.LastHealth and ply.LastHealth > ply:Health() then
local damage = ( ply.LastHealth - ply:Health() )*2
ply.LastHealth = ply:Health()
ply:SetNWInt( "FStamina", ply:GetNWInt( "FStamina" ) - damage )
elseif not ply.LastHealth then
ply.LastHealth = ply:Health()
end
if ply:GetMoveType() ~= MOVETYPE_NOCLIP then
if ( ply:KeyDown( IN_SPEED ) or ply:KeyPressed( IN_SPEED ) ) and ply:GetNWInt( "FStamina" ) > 0 then
ply:SetNWInt( "FStamina", ply:GetNWInt( "FStamina" )-( ( ply:GetRunSpeed()/12000 ) ) )
ply.LastFStamina = CurTime() + 3
if ply:KeyPressed( IN_JUMP ) and ply:GetNWInt( "FStamina" ) > 0 then
ply:SetNWInt( "FStamina", ply:GetNWInt( "FStamina" )-10 )
ply.LastFStamina = CurTime() + 3
end
if ply:WaterLevel() == 3 then
ply:SetNWInt( "FStamina", ply:GetNWInt( "FStamina" )-( ( ( ply:GetRunSpeed()/12000 )*1.6 ) ) )
end
elseif ply:KeyPressed( IN_JUMP ) and ply:GetNWInt( "FStamina" ) > 0 then
ply:SetNWInt( "FStamina", ply:GetNWInt( "FStamina" )-10 )
ply.LastFStamina = CurTime() + 3
if ply:WaterLevel() == 3 then
ply:SetNWInt( "FStamina", ply:GetNWInt( "FStamina" )-( ( ( ply:GetRunSpeed()/12000 )*1.6 ) ) )
end
elseif ( ply:KeyDown( IN_FORWARD ) or ply:KeyDown( IN_BACK ) or ply:KeyDown( IN_MOVELEFT ) or ply:KeyDown( IN_MOVERIGHT ) ) and ply:GetNWInt( "MStamina" ) > 0 then
if ply:GetMoveType() == MOVETYPE_LADDER or ply:WaterLevel() == 1 then
ply:SetNWInt( "FStamina", ply:GetNWInt( "FStamina" )-( ( ( ply:GetRunSpeed()/12000 )*1.2 ) ) )
elseif ply:WaterLevel() == 3 then
ply:SetNWInt( "FStamina", ply:GetNWInt( "FStamina" )-( ( ( ply:GetRunSpeed()/12000 )*1.6 ) ) )
end
elseif ply.LastMStamina and ply.LastMStamina < CurTime() then
if ply:IsOnGround() and ply:WaterLevel() == 0 then
ply:SetNWInt( "FStamina", ply:GetNWInt( "MStamina" )+2 )
elseif ply:WaterLevel() == 1 then
ply:SetNWInt( "FStamina", ply:GetNWInt( "MStamina" )+3 )
end
ply:SetRunSpeed( ply.FRunSPeed )
ply:SetJumpPower( ply.FJumpPower )
ply.FRunSPeed = nil
ply.FJumpPower = nil
elseif ply:GetNWInt( "FStamina" ) <= 0 and ( ply:GetRunSpeed() > 0 or ply:GetJumpPower() > 0 ) then
ply.FRunSpeed = ply:GetRunSpeed()
ply.FJumpPower = ply:GetJumpPower()
ply:SetWalkSpeed( 250 )
ply:SetRunSpeed( ply:GetWalkSpeed() )
ply:SetJumpPower( 0 )
end
if ply:KeyDown( IN_SPEED ) and ply:GetNWInt( "FStamina" ) <= 0 then
ply:SetRunSpeed( ply:GetWalkSpeed() )
end
end
end
end
hook.Add( "Think", "FStamina_MainThink", FStamina_MainThink )
end
end
function FStamina_Toggle()
if FStaminaToggled then
FStaminaToggled = false
else
FStaminaToggled = true
end
end
concommand.Add( "FanStamina_toggle", FStamina_Toggle )
[/lua]
I've added "if SERVER then" and "if CLIENT then"
Maybe they are in the wrong place ?
Sorry for my bad english, i'm french and study english by my own.
Someone can fix it please ?
A lot of thanks for any help !
what are you asking for someone to fix it whats the problem?
The stamina isn't regenerating.
[lua]
if ply:IsOnGround() and ply:WaterLevel() == 0 then
ply:SetNWInt( "FStamina", ply:GetNWInt( "MStamina" )+2 )
elseif ply:WaterLevel() == 1 then
ply:SetNWInt( "FStamina", ply:GetNWInt( "MStamina" )+3 )
end
ply:SetRunSpeed( ply.FRunSPeed )
ply:SetJumpPower( ply.FJumpPower )
ply.FRunSPeed = nil
ply.FJumpPower = nil
[/lua]
Something wrong happening in that chunk I suppose.
You want a timer to regenerate at a constant rate. I don't feel like implementing it but that's what you need.
I don't know how to use a timer ! the garrysmod exemple is a Text that appear X secondes so I don't know how to make it for the stamina bar !
And maybe, i can center it on the down of the screen
you want a sprint meter like in half life 2?
that i can get
[code]function FStamina_Regen()
for k, v in pairs(player.GetAll()) do
if (v:GetMoveType() ~= MOVETYPE_NOCLIP) and (!v:KeyDown(IN_SPEED)) and (!v:KeyDown(IN_JUMP)) and (!v:KeyDown(IN_FORWARD)) and (!v:KeyDown(IN_BACK)) and (!v:KeyDown(IN_MOVELEFT)) and (!v:KeyDown(IN_MOVERIGHT)) then
local Stam = v:GetNWInt("FStamina")
if v:IsOnGround() and v:WaterLevel() == 0 then
v:SetNWInt( "FStamina", math.Clamp(Stam+2, 0, 100))
elseif v:WaterLevel() == 1 then
v:SetNWInt( "FStamina", math.Clamp(Stam+3, 0, 100))
end
end
end
end
timer.Create("FStamina_Regen", 0.5, 0, FStamina_Regen)[/code]
Put this on the bottom of your script. You can either change the 0.5 on the last line or the +2 and +3 on lines 6 and 8 to change the rate/amount of regeneration.
So first you find a random script off of Pastebin? Then you expect us to help you?
[QUOTE=M4RK;32299508]So first you find a random script off of Pastebin? Then you expect us to help you?[/QUOTE]
That's actually exactly what happened. You sure nailed that one on the head.
Thank you so much KingofBeast !
Sorry, you need to Log In to post a reply to this thread.