summaryrefslogtreecommitdiff
path: root/data/artery/global/sh_player_dodge.txt
blob: 2ee6841b9ca0ca7199f3f040cc9b4012cde8b0e7 (plain)
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
local stam = nil
if SERVER then
	stam = nrequire("sv_stamina.lua") -- Depends on artery_stamina
else
	stam = nrequire("cl_stamina.lua")
end
local dodgeing = {}
local last_dodge = {}
local tostop = {}

hook.Add( "KeyPress", "keypress_dodge_toggle", function( ply, key )
	if ( key == IN_WALK ) then
		dodgeing[ply] = true
	end
end )

hook.Add( "KeyRelease", "keypress_dodge_toggle", function( ply, key )
	if ( key == IN_WALK ) then
		dodgeing[ply] = false
	end
end )

hook.Add( "PlayerInitialSpawn", "dodge_cooldown_init",function(ply)
	last_dodge[ply] = CurTime()
end )
hook.Add( "PlayerDisconnected", "dodge_cooldown_desc",function(ply)
	last_dodge[ply] = nil
end )



hook.Add( "Move", "move_dodge_dodge", function(ply,cmv)
	--print("Player's stamina was",stam.getStamina(ply))
	if dodgeing[ply] and CurTime() > ((last_dodge[ply] or 0) + 1) and stam.getStamina(ply) >= 10 then
		if SERVER then
			stam.takeStamina(ply,10)
		end
		local vel = cmv:GetVelocity()
		vel.z = 0
		vel = (vel * 20) + Vector(0,0,-64)
		for k,v in pairs({"x","y","z"}) do
			vel[v] = math.Clamp(vel[v],-1000,1000)
		end
		cmv:SetVelocity(vel)
		last_dodge[ply] = CurTime()
		tostop[ply] = CurTime() + 0.1
	elseif tostop[ply] and CurTime() > tostop[ply] then
		cmv:SetVelocity(Vector(0,0,0))
		tostop[ply] = nil
	end
end)