• Help bug stamina darkrp
    5 replies, posted
Hello everyone, I have a bug with the script "TCB stamina." The script works fine when we are only 3 or 4 on the server. But when we are more than 15 players, stamina will not regenerate. People could help me please? :) Here is the code of the script: [CODE]/*--------------------------------------------------------------------------- Creator: TheCodingBeast - TheCodingBeast.com This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/ ---------------------------------------------------------------------------*/ local ShouldDrawHUD = false -- true/false local DefaultRunSpeed = 240 -- If you change this value you need to change it in garrysmod\addons\darkrpmodification\lua\darkrp_config\settings.lua too local DefaultWalkSpeed = 160 -- If you change this value you need to change it in garrysmod\addons\darkrpmodification\lua\darkrp_config\settings.lua too local DefaultJumpPower = 200 local DisableLevel = 10 -- (0 - 100) When should Run & Jump get disabled local StaminaDrainSpeed = 0.25 -- Time in seconds local StaminaRestoreSpeed = 0.75 -- Time in seconds -- Server if (SERVER) then -- PlayerSpawn function tcb_StaminaStart( ply ) timer.Destroy( "tcb_StaminaTimer" ) ply:SetRunSpeed( DefaultRunSpeed ) ply:SetNWInt( "tcb_Stamina", 100 ) tcb_StaminaRestore( ply ) end hook.Add( "PlayerSpawn", "tcb_StaminaStart", tcb_StaminaStart ) -- KeyPress function tcb_StaminaPress( ply, key ) if key == IN_SPEED or ply:KeyDown(IN_SPEED) then if ply:InVehicle() then return end if ply:GetMoveType() == MOVETYPE_NOCLIP then return end if ply:GetMoveType() == MOVETYPE_LADDER then return end if ply:GetNWInt( "tcb_Stamina" ) >= DisableLevel then ply:SetRunSpeed( DefaultRunSpeed ) timer.Destroy( "tcb_StaminaGain" ) timer.Create( "tcb_StaminaTimer", StaminaDrainSpeed, 0, function( ) if ply:GetNWInt( "tcb_Stamina" ) <= 0 then ply:SetRunSpeed( DefaultWalkSpeed ) timer.Destroy( "tcb_StaminaTimer" ) return false end local vel = ply:GetVelocity() if vel.x >= DefaultWalkSpeed or vel.x <= -DefaultWalkSpeed or vel.y >= DefaultWalkSpeed or vel.y <= -DefaultWalkSpeed then ply:SetNWInt( "tcb_Stamina", ply:GetNWInt( "tcb_Stamina" ) - 1 ) end end) else ply:SetRunSpeed( DefaultWalkSpeed ) timer.Destroy( "tcb_StaminaTimer" ) end end if key == IN_JUMP or ply:KeyDown(IN_JUMP) then if ply:GetNWInt( "tcb_Stamina" ) >= DisableLevel then ply:SetJumpPower( DefaultJumpPower ) ply:SetNWInt( "tcb_Stamina", ply:GetNWInt( "tcb_Stamina" ) - 1 ) else ply:SetJumpPower( 0 ) end end end hook.Add( "KeyPress", "tcb_StaminaPress", tcb_StaminaPress ) -- KeyRelease function tcb_StaminaRelease( ply, key ) if key == IN_SPEED and !ply:KeyDown(IN_SPEED) then timer.Destroy( "tcb_StaminaTimer" ) tcb_StaminaRestore( ply ) end end hook.Add( "KeyRelease", "tcb_StaminaRelease", tcb_StaminaRelease ) -- StaminaRestore function tcb_StaminaRestore( ply ) timer.Create( "tcb_StaminaGain", StaminaRestoreSpeed, 0, function( ) if ply:GetNWInt( "tcb_Stamina" ) >= 100 then return false else ply:SetNWInt( "tcb_Stamina", ply:GetNWInt( "tcb_Stamina" ) + 1 ) end end) end end -- Client if (CLIENT) then -- HUDPaint function tcb_StaminaDraw( ) if ShouldDrawHUD == true then if LocalPlayer():GetNWInt( "tcb_Stamina" ) <= DisableLevel then StaminaDrawColor = Color( 255, 0, 0, 255) else StaminaDrawColor = Color( 255, 255, 255, 255) end draw.DrawText( "Stamina: "..LocalPlayer():GetNWInt( "tcb_Stamina" ), "TargetID", 11, 11, Color(0, 0, 0, 255) ) draw.DrawText( "Stamina: "..LocalPlayer():GetNWInt( "tcb_Stamina" ), "TargetID", 10, 10, StaminaDrawColor ) end end hook.Add( "HUDPaint", "tcb_StaminaDraw", tcb_StaminaDraw ) end[/CODE]
Do you really expect us to read that awful shitton of code to fix for you a code that you didnt build? No.
You do not understand, looking for the error in this script but I do not find this error, I just request a hand.
I repeat, its a really large code, we just wont debug it since its really big to follow, the best you can do is to create a new one
To agree, sorry I'm French and I translated. So it's not easy to understand
None of the timers have unique names serverside. Add the player's SteamID to it or something
Sorry, you need to Log In to post a reply to this thread.