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
|
AddCSLuaFile()
if SERVER then return end
local stamina = nrequire("sh_stamina.lua")
local width, height = ScrW(), ScrH()
local padding = height / 32
local barheight = height / 16
local xs, ys = padding, height - (padding * 2) - (barheight * 2)
local obarlength = width / 4
local strikechance = 0.2
local barlength = obarlength
local strikerate = 0.4
local strikes = {}
local strike_segments = 10
local erat_mult = 1.5
--Holds the player's stamina
local mystamina = stamina.default_stamina
net.Receive("art_sync_stamina",function()
mystamina = net.ReadTable()
end)
timer.Create("Energybar_lightening_timer", strikerate, 0, function()
if math.random() < strikechance then
local strike = {
fade = 0,
points = {}
}
local segment_height = barheight / strike_segments
local last = math.random(barheight * erat_mult,barlength - (barheight * erat_mult))
for i = 1,strike_segments + 1 do
local emtsh = erat_mult * segment_height
strike.points[#strike.points + 1] = {
x = last,
y = (i - 1) * segment_height
}
last = last + math.random(-emtsh,emtsh)
end
table.insert(strikes,strike)
end
end)
hook.Add("HUDPaint", "HUD_DrawEnergy", function()
--Background
surface.SetDrawColor(100, 100, 100, 100)
surface.DrawRect(xs, ys, obarlength, barheight)
--Foreground
barlength = (obarlength / 100) * stamina.getStamina(LocalPlayer())
surface.SetDrawColor(0, 0, 150, 255)
surface.DrawRect(xs, ys, barlength, barheight)
--Heighlighting/shadows
surface.SetTexture( surface.GetTextureID("gui/gradient.vtf") )
surface.SetDrawColor( 0, 0, 0, 255 )
surface.DrawTexturedRectRotated( xs + (barlength / 2), ys + (barheight / 4) * 3, barheight / 2, barlength,90)
surface.SetDrawColor( 255, 255, 255, 50 )
surface.DrawTexturedRectRotated( xs + (barlength / 2), ys + (barheight / 8), barheight / 4, barlength,270)
--Draw lightening strikes
for k,strike in pairs(strikes) do
--Strikes all use the same alpha
surface.SetDrawColor(255,255,255,255 - strike.fade)
strike.fade = strike.fade + 20
for i = 2,#strike.points do
local sp = strike.points
surface.DrawLine(sp[i-1].x + xs,sp[i-1].y + ys,sp[i].x + xs,sp[i].y + ys)
end
if strike.fade == 0 then
table.remove(strikes,k)
end
end
end)
function stamina.getStamina(who)
assert(who == LocalPlayer(),"Tried to get stamina of something other than localplayer!")
local ret = stamina.calc_stamina(mystamina)
return ret
end
return stamina
|