aboutsummaryrefslogtreecommitdiff
path: root/gamemode/shared/itemsystem/weapons_common.lua
blob: 5da9b9a3d575065d65d518bce5d4d63ff3054457 (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
52
53
54
55
56
57
58
59
ART = ART or {}


function ART.playermovedir(player)
    local vel = player:GetVelocity():GetNormalized()
    vel.z = 0
    local swings = {
        {player:GetForward(),"forward"},
        {-player:GetForward(),"backward"},
        {player:GetRight(),"right"},
        {-player:GetRight(),"left"}
    }
    table.sort(swings,function(a,b)
        return vel:Dot(a[1]) > vel:Dot(b[1])
    end)
    return swings[1][2]
end

local positionset = {}

function ART.swingarc(player,times,positions,onhit)
    local positionpoints = {}
    table.insert(positionset,positionpoints)
    local hitents = {}
    for k,v in ipairs(times) do
        timer.Simple(v,function()
            local weaponpos = positions[k] + player:GetPos()
            table.insert(positionpoints,weaponpos)
            if #positionpoints > 1 then
                local tr = util.TraceLine({
                    start = positionpoints[#positionpoints-1],
                    endpos = positionpoints[#positionpoints],
                })
                if tr.Hit then
                    onhit(tr)
                end
            end
        end)
    end
    timer.Simple(times[#times],function()
        print("Inserted swing, drawn positions are now:")
        PrintTable(positionset)
    end)
end

hook.Add( "HUDPaint", "weaponswings", function()
	cam.Start3D() -- Start the 3D function so we can draw onto the screen.
        for k,v in pairs(positionset) do
            for i = 1,#v-1 do
                render.DrawLine( v[i], v[i+1], Color(255,0,0,255), false )
            end
        end
		--render.SetMaterial( material ) -- Tell render what material we want, in this case the flash from the gravgun
		--render.DrawSprite( pos, 16, 16, white ) -- Draw the sprite in the middle of the map, at 16x16 in it's original colour with full alpha.
	cam.End3D()
end )

return wcommon