local oldx = nil local oldz = nil local catch_breath = 0 local sprint_frozen = 0 local out_of_breath = 0 local breath_delay = 1 local jumped = 0 max_sprint = 200 --how much energy/breath the player has at maximum current_sprint = max_sprint --how much energy the player starts the level with recovery_time = 0.2 --how fast the player regains energy when not sprinting (1 per ?s) max_catch_breath = 100 --how fast player recovers from being out of sprint/breath (lower = quicker) jump_penalty = 25 --amount of sprint to remove if jumping (can't jump if below) dist_mod = 10 --adjusts how far you can travel before sprint will deplete (maybe best to just adjust max_sprint) local sprint_perc = (current_sprint / max_sprint) * 100 recovery_time = recovery_time * 1000 function sprint_init(e) Hide(e) CollisionOff(e) end function sprint_main(e) Hide(e) CollisionOff(e) if oldx == nil or oldz == nil then oldx = g_PlayerPosX oldz = g_PlayerPosZ else SetPosition(e,g_PlayerPosX,g_Entity[e]['y'],g_PlayerPosZ) sprint_perc = math.floor((current_sprint / max_sprint) * 100) if out_of_breath == 0 then catch_breath = 0 if g_KeyPressSPACE == 1 then if current_sprint < jump_penalty then TransportToIfUsed(e) out_of_breath = 1 else if jumped == 0 then current_sprint = current_sprint - jump_penalty jumped = 1 end end else jumped = 0 end if g_KeyPressSHIFT == 1 then if current_sprint > 0 then if (oldx < g_PlayerPosX -dist_mod or oldx > g_PlayerPosX + dist_mod or oldz < g_PlayerPosZ -dist_mod or oldz > g_PlayerPosZ + dist_mod) then current_sprint = current_sprint - 1 oldx = g_PlayerPosX oldz = g_PlayerPosZ else if GetTimer(e) > recovery_time then current_sprint = current_sprint + 1 StartTimer(e) end end else out_of_breath = 1 end else if current_sprint < max_sprint then if GetTimer(e) > recovery_time then StartTimer(e) current_sprint = current_sprint + 1 end end end else if catch_breath < max_catch_breath then PlaySoundIfSilent(e,1) TransportToIfUsed(e) if GetTimer(e) > breath_delay then StartTimer(e) catch_breath = catch_breath + 1 if sprint_frozen == 0 then breath_delay = 1 FreezePlayer() sprint_frozen = 1 else if current_sprint < max_sprint then current_sprint = current_sprint + 1 end breath_delay = 100 UnFreezePlayer() sprint_frozen = 0 end end else if sprint_frozen == 1 then UnFreezePlayer() end out_of_breath = 0 end end --out of breath Prompt("sprint % = "..sprint_perc) end --old pos setup end --main function sprint_exit(e) end