-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathcl_stamina.lua
124 lines (104 loc) · 3.86 KB
/
cl_stamina.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
--Luctus Stamina
--Made by OverlordAkise
--This is a fully working, clientside only stamina system
--jumping and sprinting uses stamina, not sprinting or ducking while standing still restores it quickly
local LUCTUS_STAMINA_ACTIVE = true
local staminaMax = 100
local staminaUse = 0.02
local staminaCur = staminaMax
local staminaNextRegeneration = 0
local green = Color(0,200,0,200)
local yellow = Color(200,200,0,200)
local red = Color(200,0,0,200)
function LuctusStaminaHUD()
local w = ScrW()
local curWidth = (staminaCur*w)/staminaMax
if curWidth == w then return end
local col = green
if curWidth/w < 0.66 then
col = yellow
end
if curWidth/w < 0.33 then
col = red
end
draw.RoundedBox(0, 0, ScrH()-6, curWidth, 12, col)
end
function LuctusStaminaEdgeHUD()
local VARS = table.Copy(EdgeHUD.Vars)
local x = VARS.ScreenMargin
local y = ScrH() - VARS.ScreenMargin - VARS.WidgetHeight * 4 - VARS.ElementsMargin
local wx = x + EdgeHUD.LeftOffset
local wy = y - EdgeHUD.BottomOffset
local ww = VARS.infoWidgetWidth
local wh = VARS.WidgetHeight/2
local curWidth = (staminaCur*ww)/staminaMax
if curWidth == ww then return end
local col = green
if curWidth/ww < 0.66 then
col = yellow
end
if curWidth/ww < 0.33 then
col = red
end
782F
draw.RoundedBox(0,wx,wy,curWidth,wh,col)
surface.SetDrawColor(EdgeHUD.Colors["Black_Transparent"])
surface.DrawRect(wx, wy, ww, wh)
surface.SetDrawColor(EdgeHUD.Colors["White_Outline"])
surface.DrawOutlinedRect(wx, wy, ww, wh)
surface.SetDrawColor(EdgeHUD.Colors["White_Corners"])
EdgeHUD.DrawEdges(wx,wy,ww,wh,10)
draw.SimpleTextOutlined("Stamina","Trebuchet18",wx+10,wy+(wh/2),Color(255,255,255,255),TEXT_ALIGN_LEFT,TEXT_ALIGN_CENTER,1,Color(0,0,0,255))
end
hook.Add("InitPostEntity","luctus_stamina",function()
if EdgeHUD and EdgeHUD.LeftOffset then
print("[luctus_stamina] edgehud found, loading design")
hook.Add("HUDPaint","luctus_stamina",LuctusStaminaEdgeHUD)
else
hook.Add("HUDPaint","luctus_stamina",LuctusStaminaHUD)
end
end)
local OnGroundCache = false
hook.Add("CreateMove","luctus_stamina",function(cmd)
if not LUCTUS_STAMINA_ACTIVE then return end
local ply = LocalPlayer()
local cmdButtons = cmd:GetButtons()
local isMoving = cmd:KeyDown(IN_FORWARD) or cmd:KeyDown(IN_BACK) or cmd:KeyDown(IN_MOVELEFT) or cmd:KeyDown(IN_MOVERIGHT)
local Change = FrameTime() * 5
if staminaNextRegeneration < CurTime() then
local staminaRecover = 1
if isMoving then
staminaRecover = 0.5
elseif cmd:KeyDown(IN_DUCK) then
staminaRecover = 2
end
staminaCur = math.Clamp(staminaCur + ( staminaUse * staminaRecover) ,0,staminaMax)
end
if ply:InVehicle() then return end
if cmd:KeyDown(IN_SPEED) and isMoving and (ply:GetVelocity():Length() > 100) and ply:OnGround() then
staminaCur = math.Clamp(staminaCur - staminaUse,0,staminaMax)
staminaNextRegeneration = CurTime() + 1
if staminaCur < 1 then
cmdButtons = cmdButtons - IN_SPEED
end
end
if cmd:KeyDown(IN_JUMP) and ply:OnGround() then
if staminaCur < 1 then
cmdButtons = cmdButtons - IN_JUMP
else
if not OnGroundCache then
if cmd:KeyDown(IN_SPEED) and isMoving then
staminaCur = math.Clamp(staminaCur - 10,0,staminaMax)
else
staminaCur = math.Clamp(staminaCur - 5,0,staminaMax)
end
staminaNextRegeneration = CurTime() + 1
end
end
OnGroundCache = true
end
if not cmd:KeyDown(IN_JUMP) then
OnGroundCache = false
end
cmd:SetButtons(cmdButtons)
end)
print("[luctus_stamina] cl loaded")