diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2016-08-09 17:53:52 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2016-08-09 17:53:52 -0400 |
| commit | d4f197a35c207c9891d3f4dc5e9708af48c935de (patch) | |
| tree | ee8fd3960c3a3fb4ecaf0f62b50d251f007ebaf3 /gamemode/shared/itemsystem | |
| parent | 2fe3c4551344870e3784733fce2d95027b5c8382 (diff) | |
| download | artery-d4f197a35c207c9891d3f4dc5e9708af48c935de.tar.gz artery-d4f197a35c207c9891d3f4dc5e9708af48c935de.tar.bz2 artery-d4f197a35c207c9891d3f4dc5e9708af48c935de.zip | |
Added some weapons
Diffstat (limited to 'gamemode/shared/itemsystem')
| -rw-r--r-- | gamemode/shared/itemsystem/exampleitem.lua | 55 | ||||
| -rw-r--r-- | gamemode/shared/itemsystem/prayers/ninelives.lua | 77 | ||||
| -rw-r--r-- | gamemode/shared/itemsystem/prayers/preditorinstinct.lua | 98 | ||||
| -rw-r--r-- | gamemode/shared/itemsystem/prayers/thickskin.lua | 78 | ||||
| -rw-r--r-- | gamemode/shared/itemsystem/quest/togglechip.lua | 24 | ||||
| -rw-r--r-- | gamemode/shared/itemsystem/weapons/knuckledclaw.lua | 202 | ||||
| -rw-r--r-- | gamemode/shared/itemsystem/weapons/rustyaxe.lua | 197 | ||||
| -rw-r--r-- | gamemode/shared/itemsystem/weapons/scraphammer.lua | 204 | ||||
| -rw-r--r-- | gamemode/shared/itemsystem/weapons/seratedknife.lua | 217 | ||||
| -rw-r--r-- | gamemode/shared/itemsystem/weapons_common.lua | 59 |
10 files changed, 1211 insertions, 0 deletions
diff --git a/gamemode/shared/itemsystem/exampleitem.lua b/gamemode/shared/itemsystem/exampleitem.lua index f39a979..d2d6ed8 100644 --- a/gamemode/shared/itemsystem/exampleitem.lua +++ b/gamemode/shared/itemsystem/exampleitem.lua @@ -3,23 +3,78 @@ ]] local item = {} +--Required, a name, all item names must be unique item.Name = "Test item" +--Optional, a tooltip to display when hovered over +item.Tooltip = "An old axe, probably good for fighting." + +--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 server side, you'll need to use the net library. Remember that items are in the shared domain, so you can define what it does in the same file! +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 + +--Optional. Something run once when this item is drawn in a backpack +function item.DoOnPanel(dimagebutton) + dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png") +end + +--Optional. Something run once when this item is drawn in an equiped slot +function item.DoOnEqupPanel(dimagebutton) + print("called with panel:",panel) + dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png") +end + +--Optional. Called continuously, use if you need the item to display different stuff at different tiems in the backpack. +function item.Paint(self,width,height) + draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) +end + +--Optional. Called continuously, use if you need the item to display different stuff at different tiems when equiped. +function item.PaintEquiped(self,width,height) + draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) +end + +--Required, the shape of this item in a backpack. item.Shape = { {true}, {true}, {true}, } +--Optional, If this item can be equiped in any player slots, put them here. +item.Equipable = "Right" + +--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.onClick = function(self,owner) + print("pew pew!") +end + +--Optional, if we should do something special on equip(like draw the PAC for this weapon). See ART.ApplyPAC in /gamemode/shared/sh_pac.lua +item.onEquip = function(self,who) + print("Oh boy! I'm getting used!") +end + +--Optional, if we should do something speical on unequip(like setting PAC back to normal). Sett ART.RemovePAC in /gamemode/shared/sh_pac.lua +item.onUnEquip = function(self,who) + print("Aw, I'm being stored :(") +end + print("Hello from exampleitem.lua") +--Don't forget to register the item! ART.RegisterItem(item) diff --git a/gamemode/shared/itemsystem/prayers/ninelives.lua b/gamemode/shared/itemsystem/prayers/ninelives.lua new file mode 100644 index 0000000..e03e54c --- /dev/null +++ b/gamemode/shared/itemsystem/prayers/ninelives.lua @@ -0,0 +1,77 @@ +--[[ + An example item +]] +local item = {} + +--Required, a name, all item names must be unique +item.Name = "Nine Lives" + +--Optional, a tooltip to display when hovered over +item.Tooltip = "A prayer to the rouge god to prevent fall dammage for the next 9 falls that you would have taken dammage, or for 5 minutes, whichever comes first." + +--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 server side, you'll need to use the net library. Remember that items are in the shared domain, so you can define what it does in the same file! +local prayedplayers = {} +if SERVER then + util.AddNetworkString("art_prayer_ninelives") + net.Receive("art_prayer_ninelives",function(ln,ply) + if ply:HasItem("Nine Lives") then + prayedplayers[ply] = 9 + timer.Simple(60 * 5,function() + prayedplayers[ply] = nil + end) + end + end) +end +function item.GetOptions(self) + local options = {} + options["Pray"] = function() + net.Start("art_prayer_ninelives") + net.SendToServer() + end + return options +end +hook.Add( "EntityTakeDamage" , "artery_ninelives" , function(ent,info) + if info:GetDamageType() == DMG_FALL and prayedplayers[ent] ~= nil and prayedplayers[ent] > 0 then + info:SetDamage(0) + end +end) + +--Optional. Something run once when this item is drawn in a backpack +function item.DoOnPanel(dimagebutton) + dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png") +end + +--Optional. Something run once when this item is drawn in an equiped slot +function item.DoOnEqupPanel(dimagebutton) + print("called with panel:",panel) + dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png") +end + +--Optional. Called continuously, use if you need the item to display different stuff at different tiems in the backpack. +function item.Paint(self,width,height) + draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) +end + +--Optional. Called continuously, use if you need the item to display different stuff at different tiems when equiped. +function item.PaintEquiped(self,width,height) + draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) +end + +--Required, the shape of this item in a backpack. +item.Shape = { + {true}, +} + +ART.RegisterItem(item) diff --git a/gamemode/shared/itemsystem/prayers/preditorinstinct.lua b/gamemode/shared/itemsystem/prayers/preditorinstinct.lua new file mode 100644 index 0000000..8776c26 --- /dev/null +++ b/gamemode/shared/itemsystem/prayers/preditorinstinct.lua @@ -0,0 +1,98 @@ +--[[ + An example item +]] +local item = {} + +--Required, a name, all item names must be unique +item.Name = "Preditor Instinct" + +--Optional, a tooltip to display when hovered over +item.Tooltip = "A prayer to the rouge god to grant you 30% movement when chaseing a wounded target" + +--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 server side, you'll need to use the net library. Remember that items are in the shared domain, so you can define what it does in the same file! +local prayedplayers = {} +if SERVER then + util.AddNetworkString("art_prayer_preditorinstinct") + net.Receive("art_prayer_preditorinstinct",function(ln,ply) + if ply:HasItem(item.Name) then + prayedplayers[ply] = true + timer.Simple(60,function() + prayedplayers[ply] = nil + end) + end + end) +end +function item.GetOptions(self) + local options = {} + options["Pray"] = function() + net.Start("art_prayer_preditorinstinct") + net.SendToServer() + end + return options +end +--called continuously to buff players +local buffedplayers = {} +local function buffplayers() + for k,v in pairs(prayedplayers) do + if buffedplayers[k] ~= nil then continue end + --Find nearby wounded players or npcs + print("Checking if ", k, "should be buffed") + local wents = ents.FindInSphere(k:GetPos()+Vector(0,0,64),500) + for i,j in pairs(wents) do + print("Checking if ",j, "has taken dammage") + if k ~= j and j:Health() < j:GetMaxHealth() then + print("I buffed a player",k, "because ", j ,"has taken dammage") + k:SetWalkSpeed(k:GetWalkSpeed()*1.3) + buffedplayers[k] = true + timer.Simple(60,function() + k:SetWalkSpeed(k:GetWalkSpeed()*(1/1.3)) + buffedplayers[k] = nil + end) + goto nextply + end + end + ::nextply:: + end + timer.Simple(2,buffplayers) +end +buffplayers() + +--Optional. Something run once when this item is drawn in a backpack +function item.DoOnPanel(dimagebutton) + dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png") +end + +--Optional. Something run once when this item is drawn in an equiped slot +function item.DoOnEqupPanel(dimagebutton) + print("called with panel:",panel) + dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png") +end + +--Optional. Called continuously, use if you need the item to display different stuff at different tiems in the backpack. +function item.Paint(self,width,height) + draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) +end + +--Optional. Called continuously, use if you need the item to display different stuff at different tiems when equiped. +function item.PaintEquiped(self,width,height) + draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) +end + +--Required, the shape of this item in a backpack. +item.Shape = { + {true}, +} + +ART.RegisterItem(item) diff --git a/gamemode/shared/itemsystem/prayers/thickskin.lua b/gamemode/shared/itemsystem/prayers/thickskin.lua new file mode 100644 index 0000000..9dc77bd --- /dev/null +++ b/gamemode/shared/itemsystem/prayers/thickskin.lua @@ -0,0 +1,78 @@ +--[[ + An example item +]] +local item = {} + +--Required, a name, all item names must be unique +item.Name = "Thick Skin" + +--Optional, a tooltip to display when hovered over +item.Tooltip = "A prayer to the warrior god to grant you 20% resistance to all dammage" + +--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 server side, you'll need to use the net library. Remember that items are in the shared domain, so you can define what it does in the same file! +local prayedplayers = {} +if SERVER then + util.AddNetworkString("art_prayer_thickskin") + net.Receive("art_prayer_thickskin",function(ln,ply) + if ply:HasItem("Thick Skin") then + prayedplayers[ply] = true + timer.Simple(120,function() + prayedplayers[ply] = nil + end) + end + end) +end +function item.GetOptions(self) + local options = {} + options["Pray"] = function() + print("I want to pray for thick skin!") + net.Start("art_prayer_thickskin") + net.SendToServer() + end + return options +end +hook.Add( "EntityTakeDamage" , "artery_thickskin" , function(ent,info) + if prayedplayers[ent] then + info:SetDamage(info:GetDamage()*0.8) + end +end) + +--Optional. Something run once when this item is drawn in a backpack +function item.DoOnPanel(dimagebutton) + dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png") +end + +--Optional. Something run once when this item is drawn in an equiped slot +function item.DoOnEqupPanel(dimagebutton) + print("called with panel:",panel) + dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png") +end + +--Optional. Called continuously, use if you need the item to display different stuff at different tiems in the backpack. +function item.Paint(self,width,height) + draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) +end + +--Optional. Called continuously, use if you need the item to display different stuff at different tiems when equiped. +function item.PaintEquiped(self,width,height) + draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) +end + +--Required, the shape of this item in a backpack. +item.Shape = { + {true}, +} + +ART.RegisterItem(item) diff --git a/gamemode/shared/itemsystem/quest/togglechip.lua b/gamemode/shared/itemsystem/quest/togglechip.lua new file mode 100644 index 0000000..7b8ee04 --- /dev/null +++ b/gamemode/shared/itemsystem/quest/togglechip.lua @@ -0,0 +1,24 @@ +--[[ + A toggle chip (quest item) for subterr_generator quest +]] +local item = {} + +item.Name = "Toggle Chip" + +item.Serialize = function(self) + print("Trying to serailize!") + return "" +end + +item.DeSerialize = function(self,string) + print("Trying to deserialize!") + return self +end + +item.Shape = { + {true,true}, + {true,true}, +} + +print("Hello from togglechip.lua") +ART.RegisterItem(item) diff --git a/gamemode/shared/itemsystem/weapons/knuckledclaw.lua b/gamemode/shared/itemsystem/weapons/knuckledclaw.lua new file mode 100644 index 0000000..7f610fa --- /dev/null +++ b/gamemode/shared/itemsystem/weapons/knuckledclaw.lua @@ -0,0 +1,202 @@ +--[[ + 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}, +} + +--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.25 + local fow,rig,up = owner:GetForward(),owner:GetRight(),owner:GetUp() + local movementtbl = { + ["forward"] = function() + owner:SetLuaAnimation("fist_swing_up") + timer.Simple(2.33,function() + owner:StopLuaAnimation("fist_swing_up") + end) + local hits = ART.swingarc(owner,{ + 0.5,0.57,0.65,0.73 + },{ + 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(4, owner, owner:GetActiveWeapon()) + end + print("Hit",tr.Entity) + end) + end, + ["backward"] = function() + owner:SetLuaAnimation("fist_swing_down") + timer.Simple(2.33,function() + owner:StopLuaAnimation("fist_swing_down") + end) + local hits = ART.swingarc(owner,{ + 0.5,0.57,0.65,0.73 + },{ + fow*15 + up*30, + fow*35 + up*45, + fow*25 + up*70, + fow*15 + up*90, + },function(tr) + if tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then + tr.Entity:TakeDamage(4, owner, owner:GetActiveWeapon()) + end + print("Hit",tr.Entity) + end) + end, + ["left"] = function() + + end, + ["right"] = function() + owner:SetLuaAnimation("fist_swing_right") + timer.Simple(2.33,function() + owner:StopLuaAnimation("fist_swing_right") + end) + local hits = ART.swingarc(owner,{ + 0.5,0.57,0.65,0.73 + },{ + 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(4, 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("fist") + ART.ApplyPAC(who,"knuckledclaws") + --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,"knuckledclaws") +end + +print("Hello from scrapgun.lua") +--Don't forget to register the item! +ART.RegisterItem(item) diff --git a/gamemode/shared/itemsystem/weapons/rustyaxe.lua b/gamemode/shared/itemsystem/weapons/rustyaxe.lua new file mode 100644 index 0000000..71d8603 --- /dev/null +++ b/gamemode/shared/itemsystem/weapons/rustyaxe.lua @@ -0,0 +1,197 @@ +--[[ + An example item +]] +local item = {} + +--Required, a name, all item names must be unique +item.Name = "Rusty Axe" + +--Optional, a tooltip to display +item.Tooltip = "An old axe, probably good for fighting." + +--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 + +--Required, the shape of this item. +item.Shape = { + {true,true}, + {true}, + {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 + +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 ) + +--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 dir = playermovedir(owner) + local fow,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 = 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("axe_swing_left") + timer.Simple(2.33,function() owner:StopLuaAnimation("axe_swing_left") end) + local hits = 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, + ["right"] = function() + owner:SetLuaAnimation("axe_swing_right") + timer.Simple(2.33,function() owner:StopLuaAnimation("axe_swing_right") end) + local hits = 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[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("melee") + ART.ApplyPAC(who,"rustyaxe") + --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,"rustyaxe") +end + +print("Hello from scrapgun.lua") +--Don't forget to register the item! +ART.RegisterItem(item) 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) diff --git a/gamemode/shared/itemsystem/weapons/seratedknife.lua b/gamemode/shared/itemsystem/weapons/seratedknife.lua new file mode 100644 index 0000000..8571074 --- /dev/null +++ b/gamemode/shared/itemsystem/weapons/seratedknife.lua @@ -0,0 +1,217 @@ +--[[ + 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}, +} + +--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.25 + local fow,rig,up = owner:GetForward(),owner:GetRight(),owner:GetUp() + local movementtbl = { + ["forward"] = function() + owner:SetLuaAnimation("knife_swing_up") + timer.Simple(2.33,function() + owner:StopLuaAnimation("knife_swing_up") + end) + local hits = ART.swingarc(owner,{ + 0.5,0.611,0.722,0.833 + },{ + 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(4, owner, owner:GetActiveWeapon()) + end + print("Hit",tr.Entity) + end) + end, + ["backward"] = function() + owner:SetLuaAnimation("knife_swing_down") + timer.Simple(2.33,function() + owner:StopLuaAnimation("knife_swing_down") + end) + local hits = ART.swingarc(owner,{ + 0.5,0.611,0.722,0.833 + },{ + fow*15 + up*30, + fow*35 + up*45, + fow*25 + up*70, + fow*15 + up*90, + },function(tr) + if tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then + tr.Entity:TakeDamage(4, owner, owner:GetActiveWeapon()) + end + print("Hit",tr.Entity) + end) + end, + ["left"] = function() + owner:SetLuaAnimation("knife_swing_left") + timer.Simple(2.33,function() + owner:StopLuaAnimation("knife_swing_left") + end) + local hits = ART.swingarc(owner,{ + 0.5,0.611,0.722,0.833 + },{ + 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(4, owner, owner:GetActiveWeapon()) + end + print("Hit",tr.Entity) + end) + end, + ["right"] = function() + owner:SetLuaAnimation("knife_swing_right") + timer.Simple(2.33,function() + owner:StopLuaAnimation("knife_swing_right") + end) + local hits = ART.swingarc(owner,{ + 0.5,0.611,0.722,0.833 + },{ + 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(4, 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("knife") + ART.ApplyPAC(who,"seratedknife") + --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,"seratedknife") +end + +--Don't forget to register the item! +ART.RegisterItem(item) diff --git a/gamemode/shared/itemsystem/weapons_common.lua b/gamemode/shared/itemsystem/weapons_common.lua new file mode 100644 index 0000000..5da9b9a --- /dev/null +++ b/gamemode/shared/itemsystem/weapons_common.lua @@ -0,0 +1,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 |
