diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2017-04-02 20:05:56 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2017-04-02 20:05:56 -0400 |
| commit | 191ba416c8b611ea4901cead138789a357c56134 (patch) | |
| tree | b30ae3473c16028a14d3ed0c80633f360cc1c914 /gamemode/core/inventory/common | |
| parent | a22cbeddc5f8fb61e87a30aa14ba354de5cf4431 (diff) | |
| download | artery-191ba416c8b611ea4901cead138789a357c56134.tar.gz artery-191ba416c8b611ea4901cead138789a357c56134.tar.bz2 artery-191ba416c8b611ea4901cead138789a357c56134.zip | |
I finally had some time to work on this... dependency added on bobbleheadbob's zone addon
Diffstat (limited to 'gamemode/core/inventory/common')
| -rw-r--r-- | gamemode/core/inventory/common/items.lua | 31 | ||||
| -rw-r--r-- | gamemode/core/inventory/common/weapons.lua | 126 |
2 files changed, 157 insertions, 0 deletions
diff --git a/gamemode/core/inventory/common/items.lua b/gamemode/core/inventory/common/items.lua new file mode 100644 index 0000000..03113f5 --- /dev/null +++ b/gamemode/core/inventory/common/items.lua @@ -0,0 +1,31 @@ + +local items = {} + +local function drop_provided(ent,invid,frompos) + assert(CLIENT,"requested to drop an item when we are not the client!") + net.Start("art_RequestInvDrop") + net.WriteEntity(ent) + net.WriteUInt(invid,32) + net.WriteTable(frompos) + net.SendToServer() +end + +local function drop_self(tbl) + +end + +function items.DropItem(ent_or_tbl,invid,frompos) + if type(ent_or_tbl) == "table" then + drop_self(ent_or_tbl) + else + drop_provided(ent_or_tbl,invid,frompos) + end + assert(CLIENT,"requested to drop an item when we are not the client!") + net.Start("art_RequestInvDrop") + net.WriteEntity(ent) + net.WriteUInt(invid,32) + net.WriteTable(frompos) + net.SendToServer() +end + +return items diff --git a/gamemode/core/inventory/common/weapons.lua b/gamemode/core/inventory/common/weapons.lua new file mode 100644 index 0000000..9e6eead --- /dev/null +++ b/gamemode/core/inventory/common/weapons.lua @@ -0,0 +1,126 @@ +--[[ + Some common functionality that many weapons need +]] + +local com = {} + +--- Finds the direction a player is moveing. +-- @param player The player to find the move direction of +-- @return The string "forward", "backward", "right", or "left" +function com.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 + +--- The arc swing of a weapon. +-- Finds anything that a weapon should hit in it's swing, and calls a function on it. +-- @param player The player that's swinging the weapon +-- @param tiems A table of times that the trace calculations should be done at, this table needs to be the same length as the positions table +-- @param positions The position offsets from the player that swung that should be the start/end points of the arc +-- @param onhit A function to call on any entities that were hit in the swing of the weapon. +function com.swingarc(player,times,positions,onhit) + local positionpoints = {} + --table.insert(positionset,positionpoints) + for k,v in ipairs(times) do + timer.Simple(v,function() + ART.TraceWeapon = true + ART.TraceStart = CurTime() + local add = Vector(0,0,64) + if player:Crouching() then + add = Vector(0,0,32) + end + print("positions[k]",positions[k],"playerpos",player:GetPos(),"add",add) + local weaponpos = positions[k] + player:GetPos() + add + table.insert(positionpoints,weaponpos) + if #positionpoints > 1 then + --print("Trace from ", positionpoints[#positionpoints-1], " to ", positionpoints[#positionpoints]) + local tr = util.TraceLine({ + start = positionpoints[#positionpoints-1], + endpos = positionpoints[#positionpoints], + }) + onhit(tr) + end + end) + end + timer.Simple(times[#times],function() + net.Start("setwepswing") + net.WriteTable(positionpoints) + net.Broadcast() + --print("Inserted swing, drawn positions are now:") + --PrintTable(positionset) + ART.TraceWeapon = false + end) +end + +--Creates a table of ["forward|backward|left|right"] = function() +--When called, the function does an attack. +function com.createattackstable(tbl_attackdata,attacker) + local movementtbl = {} + for k,v in pairs(tbl_attackdata) do + movementtbl[k] = function() + attacker:SetLuaAnimation(v.anim) + timer.Simple(v.animtime,function() + attacker:StopLuaAnimation(v.anim) + end) + local times, pos = {},{} + for i,j in pairs(v.data) do + times[i] = 1 + j[1] + pos[i] = Vector(j[2]) + pos[i]:Rotate(attacker:GetAimVector():Angle()) + end + if pos[1] == nil then return end + com.swingarc(attacker,times,pos,function(tr) + if not tr.Hit then return end + if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == k then + eff() + elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= attacker then + tr.Entity:TakeDamage(v.dammage,attacker,attacker:GetActiveWeapon()) + end + end) + end + end + + --Empty functions for attacks not defined + for k,v in pairs({"left","right","forward","backward"}) do + if movementtbl[k] == nil then + movementtbl[k] = function() end + end + end + + return movementtbl +end + +if SERVER then + util.AddNetworkString("setwepswing") +end +local positionset = {} + +net.Receive("setwepswing",function() + positionset = net.ReadTable() + print("Got message to read positionset, is now") + PrintTable(positionset) +end) + +hook.Add( "HUDPaint", "weaponswings", function() + cam.Start3D() -- Start the 3D function so we can draw onto the screen. + local v = positionset + for i = 1,#v-1 do + render.DrawLine( v[i], v[i + 1], Color(255,0,0,255), false ) + render.DrawLine( v[i], v[i] + Vector(0,0,20),Color(0,255,0,255),false) + 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 com |
