aboutsummaryrefslogtreecommitdiff
path: root/gamemode/shared/itemsystem/weapons/rustyaxe.lua
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2016-11-27 22:02:47 -0500
committerAlexander Pickering <alexandermpickering@gmail.com>2016-11-27 22:02:47 -0500
commit2c4329e2b6e19182a441f79a5c3010011f8ae767 (patch)
treee4d8cd88690bed4cfacf2d4df39bdeed97b376f8 /gamemode/shared/itemsystem/weapons/rustyaxe.lua
parent5f2a8015bd5d2a42e79038bb52f20260d8d97ba0 (diff)
downloadartery-2c4329e2b6e19182a441f79a5c3010011f8ae767.tar.gz
artery-2c4329e2b6e19182a441f79a5c3010011f8ae767.tar.bz2
artery-2c4329e2b6e19182a441f79a5c3010011f8ae767.zip
Vairous updates
Diffstat (limited to 'gamemode/shared/itemsystem/weapons/rustyaxe.lua')
-rw-r--r--gamemode/shared/itemsystem/weapons/rustyaxe.lua209
1 files changed, 117 insertions, 92 deletions
diff --git a/gamemode/shared/itemsystem/weapons/rustyaxe.lua b/gamemode/shared/itemsystem/weapons/rustyaxe.lua
index 735c3da..b26597c 100644
--- a/gamemode/shared/itemsystem/weapons/rustyaxe.lua
+++ b/gamemode/shared/itemsystem/weapons/rustyaxe.lua
@@ -49,62 +49,54 @@ item.Shape = {
--Optional, If this item can be equiped in any player slots, put them here.
item.Equipable = "Right"
---[[ returns the direction the player swung]]
-local function 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 = {}
-
---[[
-local function 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 )
-]]
+local swingdata = {
+ ["fwd"] = {
+ {0.011,Vector(-25,-3,-11)},
+ {0.020,Vector(-25,-1,-3)},
+ {0.031,Vector(-21,0,7)},
+ {0.040,Vector(-13,-1,16)},
+ {0.051,Vector(0,-5,22)},
+ {0.060,Vector(17,-12,19)},
+ {0.069,Vector(27,-18,11)},
+ {0.077,Vector(31,-22,2)},
+ {0.087,Vector(32,-26,-6)},
+ {0.098,Vector(32,-28,-12)},
+ {0.107,Vector(31,-29,-16)},
+ {0.117,Vector(31,-29,-17)},
+ {0.128,Vector(31,-29,-16)},
+ {0.141,Vector(31,-29,-16)},
+ },
+ ["lft"] = {
+ {0.009,Vector(-34,-25,3)},
+ {0.021,Vector(-29,-33,3)},
+ {0.031,Vector(-21,-41,2)},
+ {0.042,Vector(-9,-47,0)},
+ {0.053,Vector(5,-48,-2)},
+ {0.064,Vector(20,-44,-6)},
+ {0.075,Vector(31,-34,-10)},
+ {0.086,Vector(37,-24,-15)},
+ {0.095,Vector(39,-16,-17)},
+ {0.106,Vector(39,-10,-19)},
+ {0.116,Vector(39,-8,-20)},
+ {0.126,Vector(39,-8,-19)},
+ {0.134,Vector(39,-9,-19)},
+ {0.146,Vector(39,-10,-18)},
+ },
+ ["rig"] = {
+ {0.021,Vector(-2,9,11)},
+ {0.031,Vector(5,10,10)},
+ {0.042,Vector(12,8,9)},
+ {0.053,Vector(19,4,6)},
+ {0.062,Vector(26,-4,2)},
+ {0.072,Vector(29,-12,-4)},
+ {0.083,Vector(29,-21,-12)},
+ {0.093,Vector(25,-27,-18)},
+ {0.102,Vector(22,-30,-22)},
+ {0.113,Vector(20,-31,-25)},
+ {0.123,Vector(19,-32,-25)},
+ {0.133,Vector(19,-32,-25)},
+ },
+}
--Optional, what to do when the player clicks, and this item is in the slot in inventory. only works for items equipable in left and right
item.lastSwing = {}
@@ -114,65 +106,98 @@ item.onClick = function(self,owner)
print("returning because item.lastSwing is " .. item.lastSwing[owner], "but Curtime is",CurTime())
return end
item.lastSwing[owner] = CurTime()+1.33
- local dir = playermovedir(owner)
- local fow,rig,up = owner:GetForward(),owner:GetRight(),owner:GetUp()
+ local fwd,rig,up = owner:GetForward(),owner:GetRight(),owner:GetUp()
local movementtbl = {
["forward"] = function()
owner:SetLuaAnimation("axe_swing_up")
- timer.Simple(2.33,function() owner:StopLuaAnimation("axe_swing_up") end)
- local hits = ART.swingarc(owner,{
- 1,1.1,1.2,1.3
- },{
- fow*20 + up*26,
- fow*45 + up*6,
- fow*35 + up*-13,
- fow*20 + up*-34,
- },function(tr)
- if tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then
+ timer.Simple(2.33,function()
+ owner:StopLuaAnimation("axe_swing_up")
+ end)
+ timer.Simple(1,function()
+ ART.TraceWeapon = true
+ end)
+ timer.Simple(1.33,function()
+ ART.TraceWeapon = false
+ end)
+
+ local times,pos = {},{}
+ for k,v in ipairs(swingdata["fwd"]) do
+ times[k] = 1 + v[1]
+ pos[k] = Vector(v[2])
+ pos[k]:Rotate(owner:GetAimVector():Angle())
+ end
+ if pos[1] == nil then return end
+ local hits = ART.swingarc(owner,times,pos,function(tr)
+ if not tr.Hit then return end
+ if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "forward" then
+ ART.ApplyEffect(owner,"weapon_blocked")
+ elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then
tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon())
end
- print("Hit",tr.Entity)
end)
+
end,
["backward"] = function()
end,
["left"] = function()
owner:SetLuaAnimation("axe_swing_left")
- timer.Simple(2.33,function() owner:StopLuaAnimation("axe_swing_left") end)
- local hits = ART.swingarc(owner,{
- 1,1.1,1.2,1.3
- },{
- rig*30 + up*-5,
- rig*10 + fow*30 + up*-9,
- rig*-10 + fow*30 + up*-10,
- rig*-30 + up*-15,
- },function(tr)
- if tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then
+ timer.Simple(2.33,function()
+ owner:StopLuaAnimation("axe_swing_left")
+ end)
+ timer.Simple(1,function()
+ ART.TraceWeapon = true
+ end)
+ timer.Simple(1.33,function()
+ ART.TraceWeapon = false
+ end)
+
+ local times,pos = {},{}
+ for k,v in ipairs(swingdata["lft"]) do
+ times[k] = 1 + v[1]
+ pos[k] = Vector(v[2])
+ pos[k]:Rotate(owner:GetAimVector():Angle())
+ end
+ if pos[1] == nil then return end
+ local hits = ART.swingarc(owner,times,pos,function(tr)
+ if not tr.Hit then return end
+ if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "left" then
+ ART.ApplyEffect(owner,"weapon_blocked")
+ elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then
tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon())
end
- print("Hit",tr.Entity)
end)
end,
["right"] = function()
owner:SetLuaAnimation("axe_swing_right")
- timer.Simple(2.33,function() owner:StopLuaAnimation("axe_swing_right") end)
- local hits = ART.swingarc(owner,{
- 1,1.1,1.2,1.3
- },{
- rig*-30 + up*-5,
- rig*-10 + fow*30 + up*-9,
- rig*10 + fow*30 + up*-10,
- rig*30 + up*-15,
- },function(tr)
- if tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then
+ timer.Simple(2.33,function()
+ owner:StopLuaAnimation("axe_swing_right")
+ end)
+ timer.Simple(1,function()
+ ART.TraceWeapon = true
+ end)
+ timer.Simple(1.33,function()
+ ART.TraceWeapon = false
+ end)
+
+ local times,pos = {},{}
+ for k,v in ipairs(swingdata["rig"]) do
+ times[k] = 1 + v[1]
+ pos[k] = Vector(v[2])
+ pos[k]:Rotate(owner:GetAimVector():Angle())
+ end
+ if pos[1] == nil then return end
+ local hits = ART.swingarc(owner,times,pos,function(tr)
+ if not tr.Hit then return end
+ if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "right" then
+ ART.ApplyEffect(owner,"weapon_blocked")
+ elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then
tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon())
end
- print("Hit",tr.Entity)
end)
end,
}
- movementtbl[playermovedir(owner)]()
+ movementtbl[ART.playermovedir(owner)]()
end
--Optional, if we should do something special on equip(like draw the PAC for this weapon)