--DESCRIPTION: stamina script by smallg --DESCRIPTION: player starts with [StartingStamina=50] current stamina --DESCRIPTION: and a limit of [MaxStamina=100] --DESCRIPTION: stamina drains at a rate of [DrainRate#=0.1] while running --DESCRIPTION: [JumpStaminaDrain#=3] - (if you don't want jump to be disabled set jump stamina drain to 0) --DESCRIPTION: while player is walking stamina will recover at a rate of [RecoverRateWalking#=0.01] --DESCRIPTION: if player stops completely stamina recovers at rate of [RecoverRateStopped#=0.1] --DESCRIPTION: after running out of stamina you can't sprint again until you recover at least [MinRecovery=5] stamina --DESCRIPTION: Position of the stamina display text on screen --DESCRIPTION: [TextPosX=92(0,100)] --DESCRIPTION: [TextPosY=93(0,100)] --DESCRIPTION: [TextSize=4(1,5)] --DESCRIPTION: plays when out of stamina and when stamina is back above g_stamina = {} function stamina_properties(e, startingstamina, maxstamina, drainrate, jumpstaminadrain, recoverratewalking, recoverratestopped, minrecovery, textposx, textposy, textsize) local s = g_stamina[e] s.starting = startingstamina s.current = startingstamina s.max = maxstamina s.drainrate = drainrate s.jumpstaminadrain = jumpstaminadrain s.recoverratewalking = recoverratewalking s.recoverratestopped = recoverratestopped s.minrecovery = minrecovery s.textposx = textposx s.textposy = textposy s.textsize = textsize s.recovery = 0 s.jumped = false s.hasrecovered = true SetGamePlayerControlJumpMode(0) end function stamina_init(e) g_stamina[e] = {} end function stamina_main(e) local function round(x, n) n = math.pow(10, n or 0) x = x * n if x >= 0 then x = math.floor(x + 0.5) else x = math.ceil(x - 0.5) end return x / n end local s = g_stamina[e] if GetGamePlayerControlIsRunning() == 1 then s.current = s.current - s.drainrate if s.current < 0 then s.current = 0 end else if GetGamePlayerControlJumpMode() < 1 then if GetGamePlayerControlMovement() == 0 then s.current = s.current + s.recoverratestopped else s.current = s.current + s.recoverratewalking end if s.current > s.max then s.current = s.max end end end if GetGamePlayerControlJumpMode() > 0 then if s.jumped == false then s.jumped = true if s.current < s.jumpstaminadrain then SetGamePlayerControlJumpMode(-1) else s.current = s.current - s.jumpstaminadrain end end else s.jumped = false if s.current >= s.jumpstaminadrain then SetGamePlayerControlJumpMode(0) end end if s.current > 0 then if s.current > s.recovery then if s.hasrecovered == false then PlaySound(e,1) SetGamePlayerControlCanRun(1) s.hasrecovered = true end end else if s.hasrecovered == true then SetGamePlayerControlCanRun(0) PlaySoundIfSilent(e,0) s.recovery = s.minrecovery s.hasrecovered = false end end Text(s.textposx, s.textposy, s.textsize, round(s.current).." | "..s.max) end