diff options
Diffstat (limited to 'gamemode/shared')
| -rw-r--r-- | gamemode/shared/inventory.lua | 28 | ||||
| -rw-r--r-- | gamemode/shared/itemsystem/weapons/rustyaxe.lua | 209 | ||||
| -rw-r--r-- | gamemode/shared/itemsystem/weapons/scraphammer.lua | 134 | ||||
| -rw-r--r-- | gamemode/shared/itemsystem/weapons/seratedknife.lua | 46 | ||||
| -rw-r--r-- | gamemode/shared/itemsystem/weapons_common.lua | 19 | ||||
| -rw-r--r-- | gamemode/shared/loadnpcs.lua | 5 | ||||
| -rw-r--r-- | gamemode/shared/npcsystem/blockingdummy.lua | 105 | ||||
| -rw-r--r-- | gamemode/shared/npcsystem/dummy.lua | 95 | ||||
| -rw-r--r-- | gamemode/shared/sh_npcmap.lua | 27 | ||||
| -rw-r--r-- | gamemode/shared/sh_pac.lua | 29 | ||||
| -rw-r--r-- | gamemode/shared/shop.lua | 52 |
11 files changed, 561 insertions, 188 deletions
diff --git a/gamemode/shared/inventory.lua b/gamemode/shared/inventory.lua index 7b6c9cd..006a566 100644 --- a/gamemode/shared/inventory.lua +++ b/gamemode/shared/inventory.lua @@ -2,6 +2,10 @@ Various functions to work with inventories player:GetCredits() player:SetCredits(number credits) + + concommands: + artery_showinventory + artery_setcredits [playername=admin] numcredits ]] --- Various functions to deal with inventories. -- @module Player @@ -45,6 +49,7 @@ if SERVER then -- Sets the number of credits this player has. Credits are synchronized after every set -- @param num The number of credits to set on the player function pmeta:SetCredits(num) + assert(type(num) == "number","Attempted to set credits to something other than a number:" .. type(num)) self.Inventory.Credits = num SynchCredits(self) end @@ -259,11 +264,12 @@ net.Receive("buyitem",function(len,ply) ply:ChatPrint("Could not find a shop selling that!") return false end - print("Found item, cost was ", cost) + print("Found item, cost was ", cost,"type",type(cost)) local playercreds = ply:GetCredits() + print("player credits:",playercreds,"type:",type(playercreds)) local tbp = ply.Inventory.Backpacks[backpack] local canfit = invfuncs.CanFitInBackpack(tbp,j,i,item) - print("Can it?",canfit) + print("Can fit?",canfit) if playercreds < cost then ply:ChatPrint("You don't have enough credits to buy that!") return false @@ -272,8 +278,9 @@ net.Receive("buyitem",function(len,ply) ply:ChatPrint("You can't put that into your packpack there!") return false end - playercreds:SetCredits(playercreds - cost) + ply:SetCredits(playercreds - cost) invfuncs.PutItemInBackpack(tbp,j,i,item) + ply:SynchronizeInventory() return true end) @@ -370,6 +377,21 @@ concommand.Add("artery_showinventory",function(ply,cmd,args) PrintTable(ply.ClientInventory) end) +concommand.Add("artery_setcredits",function(ply,cmd,args) + if not (ply:IsValid() and ply:IsAdmin()) then return end + local e + local i = false + for k,v in pairs(player.GetAll()) do + if v:Nick() == args[1] then + e = v + i = true + break + end + end + e = e or ply + e:SetCredits(tonumber(args[i and 2 or 1])) +end) + hook.Add( "PlayerSpawn", "artery_disable_sprint", function(ply) ply:SetRunSpeed(ply:GetWalkSpeed()) end ) 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) diff --git a/gamemode/shared/itemsystem/weapons/scraphammer.lua b/gamemode/shared/itemsystem/weapons/scraphammer.lua index 9ec7ac9..299d4e2 100644 --- a/gamemode/shared/itemsystem/weapons/scraphammer.lua +++ b/gamemode/shared/itemsystem/weapons/scraphammer.lua @@ -26,6 +26,7 @@ function item.GetOptions(self) local options = {} options["test"] = function() print("You pressed test!") end options["toste"] = function() print("You pressed toste!") end + options["Drop"] = ART.DropItem(self) return options end @@ -60,7 +61,64 @@ item.Shape = { --Optional, If this item can be equiped in any player slots, put them here. item.Equipable = "Right" - +local swingdata = { + ["fwd"] = { + {0.007,Vector(-27,1,9)}, + {0.014,Vector(-20,3,16)}, + {0.020,Vector(-11,6,22)}, + {0.027,Vector(0,7,26)}, + {0.032,Vector(15,7,25)}, + {0.039,Vector(28,6,21)}, + {0.045,Vector(38,4,14)}, + {0.052,Vector(46,0,3)}, + {0.059,Vector(50,-3,-6)}, + {0.065,Vector(52,-6,-15)}, + {0.072,Vector(52,-8,-22)}, + {0.078,Vector(51,-10,-28)}, + {0.084,Vector(50,-11,-31)}, + {0.091,Vector(50,-11,-32)}, + {0.097,Vector(50,-11,-32)} + }, + ["lft"] = { + {0.007,Vector(-6,24,2)}, + {0.014,Vector(-1,26,2)}, + {0.020,Vector(5,28,1)}, + {0.027,Vector(12,28,-1)}, + {0.035,Vector(19,27,-4)}, + {0.042,Vector(27,24,-7)}, + {0.048,Vector(37,17,-13)}, + {0.055,Vector(42,12,-17)}, + {0.061,Vector(45,5,-20)}, + {0.068,Vector(48,-2,-23)}, + {0.075,Vector(49,-8,-25)}, + {0.084,Vector(49,-14,-26)}, + {0.091,Vector(49,-19,-27)}, + {0.097,Vector(48,-22,-27)}, + {0.104,Vector(48,-25,-27)}, + {0.110,Vector(48,-26,-27)}, + {0.117,Vector(48,-27,-27)}, + {0.123,Vector(48,-26,-27)}, + {0.131,Vector(48,-26,-27)} + }, + ["rig"] = { + {0.009,Vector(-3,25,2)}, + {0.017,Vector(3,27,1)}, + {0.025,Vector(11,28,-1)}, + {0.032,Vector(20,27,-4)}, + {0.040,Vector(28,24,-7)}, + {0.051,Vector(36,19,-12)}, + {0.059,Vector(42,11,-17)}, + {0.067,Vector(47,2,-22)}, + {0.075,Vector(49,-5,-25)}, + {0.083,Vector(49,-13,-27)}, + {0.090,Vector(49,-19,-28)}, + {0.098,Vector(48,-24,-28)}, + {0.106,Vector(48,-27,-28)}, + {0.114,Vector(48,-28,-28)}, + {0.121,Vector(48,-27,-28)}, + {0.129,Vector(48,-27,-27)} + }, +} --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 = {} @@ -70,26 +128,30 @@ 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 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("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*40 + up*26, - fow*60 + up*6, - fow*55 + up*-13, - fow*40 + up*-34, - },function(tr) - if tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then + + 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() @@ -99,18 +161,21 @@ item.onClick = function(self,owner) 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*-5, - rig*20 + fow*40 + up*-9, - rig*-20 + fow*40 + up*-10, - rig*-30 + up*-15, - },function(tr) - if tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then - tr.Entity:TakeDamage(10, owner, owner:GetActiveWeapon()) + + 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() @@ -118,18 +183,21 @@ item.onClick = function(self,owner) 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*-5, - rig*-10 + fow*40 + up*-9, - rig*10 + fow*40 + up*-10, - rig*30 + up*-15, - },function(tr) - if tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then + + 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, } diff --git a/gamemode/shared/itemsystem/weapons/seratedknife.lua b/gamemode/shared/itemsystem/weapons/seratedknife.lua index e57351d..2daec36 100644 --- a/gamemode/shared/itemsystem/weapons/seratedknife.lua +++ b/gamemode/shared/itemsystem/weapons/seratedknife.lua @@ -26,6 +26,7 @@ function item.GetOptions(self) local options = {} options["test"] = function() print("You pressed test!") end options["toste"] = function() print("You pressed toste!") end + options["Drop"] = ART.DropItem(self) return options end @@ -58,6 +59,14 @@ item.Shape = { --Optional, If this item can be equiped in any player slots, put them here. item.Equipable = "Right" +local function attacktrace(tr,owner) + if not tr.Hit then return end + if tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then + tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) + 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 = {} local animationtime = 1.833333 @@ -82,10 +91,14 @@ item.onClick = function(self,owner) 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()) + if not tr.Hit then return end + if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "forward" then + print("Entity blocked!") + ART.ApplyEffect(owner,"weapon_blocked") + elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then + print("Got past blocking, it was",tr.Entity.Blocking) + tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) end - print("Hit",tr.Entity) end) end, ["backward"] = function() @@ -101,10 +114,13 @@ item.onClick = function(self,owner) 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()) + if not tr.Hit then return end + if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "backward" then + print("Entity blocked!") + elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then + print("Got past blocking, it was",tr.Entity.Blocking) + tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) end - print("Hit",tr.Entity) end) end, ["left"] = function() @@ -120,10 +136,13 @@ item.onClick = function(self,owner) 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()) + if not tr.Hit then return end + if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "left" then + print("Entity blocked!") + elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then + print("Got past blocking, it was",tr.Entity.Blocking) + tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) end - print("Hit",tr.Entity) end) end, ["right"] = function() @@ -139,10 +158,13 @@ item.onClick = function(self,owner) 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()) + if not tr.Hit then return end + if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "right" then + print("Entity blocked!") + elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then + print("Got past blocking, it was",tr.Entity.Blocking) + tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon()) end - print("Hit",tr.Entity) end) end, } diff --git a/gamemode/shared/itemsystem/weapons_common.lua b/gamemode/shared/itemsystem/weapons_common.lua index a7679a9..6f553fa 100644 --- a/gamemode/shared/itemsystem/weapons_common.lua +++ b/gamemode/shared/itemsystem/weapons_common.lua @@ -29,34 +29,28 @@ local positionset = {} -- @param onhit A function to call on any entities that were hit in the swing of the weapon. function ART.swingarc(player,times,positions,onhit) local positionpoints = {} - --[[ - local ea = player:EyeAngles() - for k,v in pairs(positions) do - print("Position that was at ", positions[k]) - positions[k].z = positions[k].z * math.sin(ea.pitch+90) - print("Is now at",positions[k]) - end - ]] table.insert(positionset,positionpoints) - local hitents = {} for k,v in ipairs(times) do timer.Simple(v,function() + ART.TraceWeapon = true + ART.TraceStart = CurTime() + print("positions[k]",positions[k],"playerpos",player:GetPos(),"add",Vector(0,0,64)) local weaponpos = positions[k] + player:GetPos() + Vector(0,0,64) 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], }) - if tr.Hit then - onhit(tr) - end + onhit(tr) end end) end timer.Simple(times[#times],function() print("Inserted swing, drawn positions are now:") PrintTable(positionset) + ART.TraceWeapon = false end) end @@ -65,6 +59,7 @@ hook.Add( "HUDPaint", "weaponswings", function() 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 ) + render.DrawLine( v[i], v[i]+Vector(0,0,20),Color(0,255,0,255),false) end end --render.SetMaterial( material ) -- Tell render what material we want, in this case the flash from the gravgun diff --git a/gamemode/shared/loadnpcs.lua b/gamemode/shared/loadnpcs.lua index bff5135..3e1861f 100644 --- a/gamemode/shared/loadnpcs.lua +++ b/gamemode/shared/loadnpcs.lua @@ -4,11 +4,13 @@ local f = include("concommands.lua") ART = ART or {} local npcs = {} +local autocompletef function ART.RegisterNPC(npc) assert(npc ~= nil, "Attempted to register a nil npc") assert(npc.Name ~= nil, "Attempted to register an npc without a name") npcs[npc.Name] = npc + autocompletef = f.AutocompleteFunction(npcs) end function ART.CreateNPCByName(npcname, pos) @@ -20,9 +22,10 @@ function ART.CreateNPCByName(npcname, pos) npc[k] = v end npc:Spawn() + return npc end -local autocompletef + if SERVER then autocompletef = nil else diff --git a/gamemode/shared/npcsystem/blockingdummy.lua b/gamemode/shared/npcsystem/blockingdummy.lua new file mode 100644 index 0000000..5c6008c --- /dev/null +++ b/gamemode/shared/npcsystem/blockingdummy.lua @@ -0,0 +1,105 @@ +local NPC = {} +NPC.Name = "Blocking Training Dummy" +NPC.Desc = "A man made of straw. His dream is to have a brain." +NPC.Class = "Ambient" --Ambient, Agressive, Boss +NPC.Model = "models/headcrab.mdl" + +NPC.Stats = { + ["Vitality"] = 100000, + ["Speed"] = 400, + ["AwareDist"] = 1000, + ["Accel"] = 100, + ["Decel"] = 200, + ["Step"] = 20, --Step height + ["Hull"] = HULL_TINY +} + +--Some npc's like birds have diffent names for their idle sequences +NPC.IdleSequences = { + [0] = "lookaround", + [1] = "Idle01", +} + +--Drops should be formated as [index]={["item name"], percent_drop} where percent_drop is a number from 0 to 100 + +NPC.Drops = { +} + +--Attacks should be formated as [i]={function attackpriority() = function doattack()} +local checknothing = function(self,ply) + return 1 +end + +local donothing = function(self,ply) +end +NPC.Attacks = { + [1] = {--run away from the player + [checknothing] = donothing + }, +} + +--A function that takes a position and returns true if this is an acceptable place to spawn +function NPC:SpawnLocations(pos) + return true +end + +--The entity that is this npc's current target, if it has one. Nil otherwise +NPC.Target = nil + +--All enemies that this NPC is aware of +NPC.AwareEnemies = {} +--Attack priority is a fucntion that takes a player, and returns an int describing it's prority to attack (higher = more important) NPC will always attack the player with the highest priority +function NPC:AttackPriority(ply) + if not ply then return 0 end + return 1 +end + +--What to replace the ENT:RunBehaviour with +function NPC:Act(deltat) +end + +--What to replace ENT:OnStuck with +function NPC:Stuck() + +end + +local blockorder = { + "forward", + "right", + "backward", + "left" +} +local cursor = 0 +function NPC:OnDammage(ammount) + self.Blocking = blockorder[cursor + 1] + cursor = (cursor + 1) % 4 + print("A dummy was hit for",ammount:GetDamage(),"!") + print("Blocking is now",self.Blocking) +end + +--These are just here to tell the editors/develoeprs what functions are available.. dont un-comment them out, as this could affect all the items. +/* +function NPC:OnSpawn() +end + +--If we need to do more than just reduce health on dammage +function NPC:OnDammage(ammount) +end + +--If we need to do more than just drop items on death +function NPC:OnDeath() +end + +--A particular spell was cast on this npc by player +function NPC:OnSpell(spell, player) +end + +function NPC:OnFindEnemy(enemy) +end + +--Called when the npc is attacking anything with any attack +function NPC:OnAttack(target) +end +*/ + +ART.RegisterNPC(NPC) diff --git a/gamemode/shared/npcsystem/dummy.lua b/gamemode/shared/npcsystem/dummy.lua new file mode 100644 index 0000000..869dd0e --- /dev/null +++ b/gamemode/shared/npcsystem/dummy.lua @@ -0,0 +1,95 @@ +local NPC = {} +NPC.Name = "Training Dummy" +NPC.Desc = "A man made of straw. His dream is to have a brain." +NPC.Class = "Ambient" --Ambient, Agressive, Boss +NPC.Model = "models/headcrab.mdl" + +NPC.Stats = { + ["Vitality"] = 100000, + ["Speed"] = 400, + ["AwareDist"] = 1000, + ["Accel"] = 100, + ["Decel"] = 200, + ["Step"] = 20, --Step height + ["Hull"] = HULL_TINY +} + +--Some npc's like birds have diffent names for their idle sequences +NPC.IdleSequences = { + [0] = "lookaround", + [1] = "Idle01", +} + +--Drops should be formated as [index]={["item name"], percent_drop} where percent_drop is a number from 0 to 100 + +NPC.Drops = { +} + +--Attacks should be formated as [i]={function attackpriority() = function doattack()} +local checknothing = function(self,ply) + return 1 +end + +local donothing = function(self,ply) +end +NPC.Attacks = { + [1] = {--run away from the player + [checknothing] = donothing + }, +} + +--A function that takes a position and returns true if this is an acceptable place to spawn +function NPC:SpawnLocations(pos) + return true +end + +--The entity that is this npc's current target, if it has one. Nil otherwise +NPC.Target = nil + +--All enemies that this NPC is aware of +NPC.AwareEnemies = {} +--Attack priority is a fucntion that takes a player, and returns an int describing it's prority to attack (higher = more important) NPC will always attack the player with the highest priority +function NPC:AttackPriority(ply) + if not ply then return 0 end + return 1 +end + +--What to replace the ENT:RunBehaviour with +function NPC:Act(deltat) +end + +--What to replace ENT:OnStuck with +function NPC:Stuck() + +end + +function NPC:OnDammage(ammount) + print("A dummy was hit for",ammount:GetDamage(),"!") +end + +--These are just here to tell the editors/develoeprs what functions are available.. dont un-comment them out, as this could affect all the items. +/* +function NPC:OnSpawn() +end + +--If we need to do more than just reduce health on dammage +function NPC:OnDammage(ammount) +end + +--If we need to do more than just drop items on death +function NPC:OnDeath() +end + +--A particular spell was cast on this npc by player +function NPC:OnSpell(spell, player) +end + +function NPC:OnFindEnemy(enemy) +end + +--Called when the npc is attacking anything with any attack +function NPC:OnAttack(target) +end +*/ + +ART.RegisterNPC(NPC) diff --git a/gamemode/shared/sh_npcmap.lua b/gamemode/shared/sh_npcmap.lua deleted file mode 100644 index 5c6d93c..0000000 --- a/gamemode/shared/sh_npcmap.lua +++ /dev/null @@ -1,27 +0,0 @@ - -local pmeta = FindMetaTable("Player") - -if SERVER then - util.AddNetworkString("addmapicon") -end - -function pmeta:AddMapIcon(icon,position) - print("adding map icon") - net.Start("addmapicon") - net.WriteString(icon) - net.WriteVector(position) - net.Send(self) -end - -if CLIENT then - net.Receive("addmapicon",function() - print("got recieve for map icon") - LocalPlayer().MapIcons = LocalPlayer().MapIcons or {} - local matstr = net.ReadString() - local matpos = net.ReadVector() - table.insert(LocalPlayer().MapIcons,{ - ["material"] = Material(matstr), - ["pos"] = matpos, - }) - end) -end diff --git a/gamemode/shared/sh_pac.lua b/gamemode/shared/sh_pac.lua index 1ab9f88..1d4da41 100644 --- a/gamemode/shared/sh_pac.lua +++ b/gamemode/shared/sh_pac.lua @@ -2,6 +2,7 @@ All the functions related to networking pac's ]] if CLIENT then + local what local function applypac(who,pacname) local pactxt = file.Read("artery/pacs/"..pacname..".txt","DATA") print("got pac txt",pactxt) @@ -26,9 +27,37 @@ if CLIENT then print("who is",who) who:AttachPACPart(pactbl) print("Pac Equiped!") + + what = who:FindPACPart(pactbl, "ball") + print("what was", what) + if what ~= nil then + print("What's position:") + for k,v in pairs(what) do + print(k,":",v) + end + print(what:GetDrawPosition(),type(what:GetDrawPosition())) + end end end + local RecordTrace = false + local swingtime + hook.Add("Tick","weapon_trace",function() + if what ~= nil and ART.TraceWeapon and RecordTrace then + local pos = what:GetDrawPosition() + local ppos = LocalPlayer():GetPos() + for k = 1,3 do pos[k] = pos[k] - ppos[k] end -- Now is a local vector, player is the origin + print(string.format("{%1.3f,Vector(%d,%d,%d)},",swingtime/1000,pos[1],pos[2],pos[3]-64)) + swingtime = swingtime + util.TimerCycle() + else + swingtime = util.TimerCycle() + end + end) + + concommand.Add("artery_dev_traceweapons",function(ply,cmd,args) + RecordTrace = args[1] == "1" + end) + local function removepac(who,pacname) local pactxt = file.Read("artery/pacs/"..pacname..".txt","DATA") assert(pactxt ~= nil, "Attempted to remove a pac that dosn't exist") diff --git a/gamemode/shared/shop.lua b/gamemode/shared/shop.lua index b188e7c..c330fb3 100644 --- a/gamemode/shared/shop.lua +++ b/gamemode/shared/shop.lua @@ -1,3 +1,13 @@ +--[[ + Displays shop npc's interfaces + + public functions: + (sv)ART.OpenShop(shoptbl, ply) :: nil + (sv)ART.CreateShop(npctbl) :: nil + net messages: + art_openshop +]] + local ivf = include("inventory_common.lua") ART = ART or {} @@ -34,10 +44,8 @@ end if SERVER then return end local w,h = ScrW(),ScrH() -function DrawShopItemOnDPanel(dp,item) +local function DrawShopItemOnDPanel(dp,itemtbl,cost) --An item is a string, and int cost - local itemtbl = ART.GetItemByName(item[1]) - local cost = item[2] local shape = itemtbl.Shape local twidth,theight = 0,#shape @@ -50,7 +58,7 @@ function DrawShopItemOnDPanel(dp,item) backgrid:SetPos( 10, 30 ) backgrid:SetCols( twidth ) backgrid:SetColWide( theight ) - backgrid:Dock(FILL) + backgrid:Dock(LEFT) local shopicon = vgui.Create( "DImageButton", dp ) shopicon:SetSize(slotsize * twidth, slotsize * theight) @@ -65,7 +73,10 @@ function DrawShopItemOnDPanel(dp,item) if itemtbl.DoOnPanel then itemtbl.DoOnPanel(shopicon) end - --invicon.Paint = function(self, w, h) draw.RoundedBox(4, 0,0,w,h,Color(0,100,0)) end + shopicon.Paint = function(self, w, h) + surface.SetDrawColor( 0, 0, 0, 255 ) + surface.DrawOutlinedRect( 0, 0, w, h) + end shopicon.DoClick = function() print("You cliked me!") end @@ -92,16 +103,41 @@ function DrawShopItemOnDPanel(dp,item) print("Found false spot:",k,i) local emptyslot = vgui.Create("DPanel", dp) emptyslot:SetSize(slotsize,slotsize) - emptyslot:SetPos(slotsize * (i - 1), slotsize * (k - 1)) + emptyslot:SetPos(slotsize * (i - 1) + 2, slotsize * (k - 1) + 2) end end end end -function DrawShopOnDPanel(dp,items) +local slotsize = math.Round(w / 32) + +local function DrawShopOnDPanel(dp,items) --This gets pretty involved, lets try to not make it a clusterfuck. - DrawShopItemOnDPanel(dp,items[1]) + dp.Paint = function(self, w, h) draw.RoundedBox(4, 0,0,w,h,Color(100,0,0)) end + print("dp",dp) + local scrollpanel = vgui.Create( "DScrollPanel",dp ) + print("scollpanel",scrollpanel) + scrollpanel.Paint = function(self, w, h) draw.RoundedBox(4, 0,0,w,h,Color(0,0,100)) end + scrollpanel:Dock(FILL) + for k,v in pairs(items) do + local itemtbl = ART.GetItemByName(v[1]) + local invpanel = vgui.Create( "DPanel", scollpanel) + invpanel.Paint = function(self, w, h) + draw.RoundedBox(4, 1,1,w-4,h-4,Color(50,50,50)) + draw.RoundedBox(4, 2,2,w-5,h-5,Color(100,100,100)) + end + print("invpanel",invpanel) + DrawShopItemOnDPanel(invpanel,itemtbl,v[2]) + scrollpanel:AddItem(invpanel) + invpanel:Dock(TOP) + local x,_ = invpanel:GetSize() + print("item is",v) + PrintTable(v) + invpanel:SetSize(x,slotsize*(#itemtbl.Shape) + 4) + invpanel:Dock(TOP) + + end end |
