aboutsummaryrefslogtreecommitdiff
path: root/gamemode/shared/itemsystem/weapons/scraphammer.lua
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2016-08-09 17:53:52 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2016-08-09 17:53:52 -0400
commitd4f197a35c207c9891d3f4dc5e9708af48c935de (patch)
treeee8fd3960c3a3fb4ecaf0f62b50d251f007ebaf3 /gamemode/shared/itemsystem/weapons/scraphammer.lua
parent2fe3c4551344870e3784733fce2d95027b5c8382 (diff)
downloadartery-d4f197a35c207c9891d3f4dc5e9708af48c935de.tar.gz
artery-d4f197a35c207c9891d3f4dc5e9708af48c935de.tar.bz2
artery-d4f197a35c207c9891d3f4dc5e9708af48c935de.zip
Added some weapons
Diffstat (limited to 'gamemode/shared/itemsystem/weapons/scraphammer.lua')
-rw-r--r--gamemode/shared/itemsystem/weapons/scraphammer.lua204
1 files changed, 204 insertions, 0 deletions
diff --git a/gamemode/shared/itemsystem/weapons/scraphammer.lua b/gamemode/shared/itemsystem/weapons/scraphammer.lua
new file mode 100644
index 0000000..978fde8
--- /dev/null
+++ b/gamemode/shared/itemsystem/weapons/scraphammer.lua
@@ -0,0 +1,204 @@
+--[[
+ An example item
+]]
+local item = {}
+
+--Required, a name, all item names must be unique
+item.Name = "Scrap Hammer"
+
+--Optional, a tooltip to display
+item.Tooltip = "Bits of scrap put togeather to resembel a hammer"
+
+--Required Returns the data needed to rebuild this item, should only contain the minimum data nessessary since this gets sent over the network
+item.Serialize = function(self)
+ print("Trying to serailize!")
+ return ""
+end
+
+--Required, Rebuilds the item from data created in Serialize, if the item is different from the "main" copy of the item, it should retun a tabl.Copy(self), with the appropriate fields set.
+item.DeSerialize = function(self,string)
+ print("Trying to deserialize!")
+ return self
+end
+
+--Optional, when the player clicks this item, a menu will show up, if the menu item is clicked, the function is ran. This is all run client side, so if you want it to do something, you'll need to use the net library.
+function item.GetOptions(self)
+ local options = {}
+ options["test"] = function() print("You pressed test!") end
+ options["toste"] = function() print("You pressed toste!") end
+ return options
+end
+
+function item.DoOnPanel(dimagebutton)
+ dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png")
+end
+
+function item.DoOnEqupPanel(dimagebutton)
+ print("called with panel:",panel)
+ dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png")
+end
+
+--[[
+function item.Paint(self,width,height)
+ --print("painting with values",self,width,height)
+ draw.RoundedBox(4, 0,0,width,height,Color(0,100,0))
+end
+
+function item.PaintEquiped(self,width,height)
+ --print("painting with values",self,width,height)
+ draw.RoundedBox(4, 0,0,width,height,Color(0,100,0))
+end
+]]
+
+--Required, the shape of this item.
+item.Shape = {
+ {true,true,true},
+ {false,true},
+ {false,true},
+}
+
+--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
+
+
+
+--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 = {}
+item.onClick = function(self,owner)
+ item.lastSwing[owner] = item.lastSwing[owner] or 0
+ if item.lastSwing[owner] > CurTime() then
+ print("returning because item.lastSwing is " .. item.lastSwing[owner], "but Curtime is",CurTime())
+ return end
+ item.lastSwing[owner] = CurTime()+1.33
+ local fow,rig,up = owner:GetForward(),owner:GetRight(),owner:GetUp()
+ local movementtbl = {
+ ["forward"] = function()
+ owner:SetLuaAnimation("hammer_swing_up")
+ timer.Simple(2.33,function()
+ owner:StopLuaAnimation("hammer_swing_up")
+ end)
+ local hits = ART.swingarc(owner,{
+ 1,1.1,1.2,1.3
+ },{
+ fow*20 + up*90,
+ fow*45 + up*70,
+ fow*35 + up*45,
+ fow*20 + up*30,
+ },function(tr)
+ if 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("hammer_swing_left")
+ timer.Simple(2.33,function()
+ owner:StopLuaAnimation("hammer_swing_left")
+ end)
+ local hits = ART.swingarc(owner,{
+ 1,1.1,1.2,1.3
+ },{
+ rig*30 + up*59,
+ rig*10 + fow*30 + up*55,
+ rig*-10 + fow*30 + up*54,
+ rig*-30 + up*50,
+ },function(tr)
+ if tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then
+ tr.Entity:TakeDamage(10, owner, owner:GetActiveWeapon())
+ end
+ print("Hit",tr.Entity)
+ end)
+ end,
+ ["right"] = function()
+ owner:SetLuaAnimation("hammer_swing_right")
+ timer.Simple(2.33,function()
+ owner:StopLuaAnimation("hammer_swing_right")
+ end)
+ local hits = ART.swingarc(owner,{
+ 1,1.1,1.2,1.3
+ },{
+ rig*-30 + up*59,
+ rig*-10 + fow*30 + up*55,
+ rig*10 + fow*30 + up*54,
+ rig*30 + up*50,
+ },function(tr)
+ if tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then
+ tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon())
+ end
+ print("Hit",tr.Entity)
+ end)
+ end,
+ }
+ movementtbl[ART.playermovedir(owner)]()
+end
+
+--Optional, if we should do something special on equip(like draw the PAC for this weapon)
+item.onEquip = function(self,who)
+ print("onEquip",who)
+ if CLIENT then print("onEquip client!") end
+ if SERVER then
+ PrintTable(pac)
+ who:GetActiveWeapon():SetHoldType("melee2")
+ ART.ApplyPAC(who,"scraphammer")
+ --local outfit = pac.luadata.ReadFile("pac3/mech.txt")
+ --who:AttachPACPart(outfit)
+ --print("onEquip server!")
+ end
+end
+
+--Optional, if we should do something speical on unequip(like setting animations back to normal)
+item.onUnEquip = function(self,who)
+ who:GetActiveWeapon():SetHoldType("normal")
+ ART.RemovePAC(who,"scraphammer")
+end
+
+print("Hello from scrapgun.lua")
+--Don't forget to register the item!
+ART.RegisterItem(item)