• Need Help with TTT Spriting / Stamina Bar
    4 replies, posted
Found a script for sprinting/stamina bar here: [url]http://facepunch.com/showthread.php?t=1124545[/url] Have added together the top part and the bottom part, but removed anything relating to jumping. The bar is there and is works fine depleting/regenerating. However when the bar is empty nothing changes, you can still sprint. Anyone have any idea how to fix this? I dont know any lua myself unfortunately. Also any help with making the sprint bar deplete faster would be great as well. It seems to take a very long time to go all the way down. Code for lua/autorun/stamina.lua: [CODE]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:WaterLevel() == 3 then ply:SetNWInt( "FStamina", ply:GetNWInt( "FStamina" )-( ( ( ply:GetRunSpeed()/12000 )*1.6 ) ) ) end 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.FRunSPeed = nil elseif ply:GetNWInt( "FStamina" ) <= 0 and ( ply:GetRunSpeed() > 0 ) then ply.FRunSpeed = ply:GetRunSpeed() ply:SetWalkSpeed( 250 ) ply:SetRunSpeed( ply:GetWalkSpeed() ) 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 ) 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_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] Thanks for you help in advance.
first, excuse me for my english due it is not my native language. second, I know nothing of this development language, but I do about others. elseif ply:GetNWInt( "FStamina" ) <= 0 and ( ply:GetRunSpeed() > 0 ) then ply.FRunSpeed = ply:GetRunSpeed() ply:SetWalkSpeed( 250 ) ply:SetRunSpeed( ply:GetWalkSpeed() ) end if ply:KeyDown( IN_SPEED ) and ply:GetNWInt( "FStamina" ) <= 0 then ply:SetRunSpeed( ply:GetWalkSpeed() ) end IN_SPEED meaning what? if it's about sprinting, then you have a loop. This should be a separated event, in my opinion, where you restore the player to an original movement This type of coding... well, should go well in state events. where you pass from one event (nothing) to another (walking) to another (sprinting) and backwards with a corresponding key/action for each event. best of lucks!
Unfortunately, I have no programming knowledge at all so I dont know how to edit any of the code. But thanks for your reply, it may very well help if a lua coder comes along and gives it a read.
Bump. I'm sure theres a few people out there that would love a solution as much as myself.
[QUOTE=Inheartswake;45305942]Bump. I'm sure theres a few people out there that would love a solution as much as myself.[/QUOTE] It's not difficult, you should know how to do some basic coding if you're hosting a server. Enable sprint, use messages to relay use of sprint and calculate accordingly at the servers end, reset speeds when sprinting/not sprinting. It will take a few changes to the setting of speed as TTT will reset it all the time. [IMG]http://i.imgur.com/SAGdIgJ.jpg[/IMG] Top bar, tada.
Sorry, you need to Log In to post a reply to this thread.