aboutsummaryrefslogtreecommitdiff
path: root/gamemode
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode')
-rw-r--r--gamemode/client/cl_inventory.lua48
-rw-r--r--gamemode/core/clienteffects/blocked.lua3
-rw-r--r--gamemode/core/database/sv_queries.lua51
-rw-r--r--gamemode/core/database/sv_setup.lua67
-rw-r--r--gamemode/core/inventory/common/items.lua31
-rw-r--r--gamemode/core/inventory/common/weapons.lua126
-rw-r--r--gamemode/core/inventory/inventory.lua33
-rw-r--r--gamemode/core/inventory/item.lua8
-rw-r--r--gamemode/core/inventory/sv_invtracker.lua78
-rw-r--r--gamemode/core/mapstich/cl_mapstich.lua12
-rw-r--r--gamemode/core/mapstich/sv_mapstich.lua70
-rw-r--r--gamemode/core/npc/cl_shop.lua141
-rw-r--r--gamemode/core/npc/sv_shop.lua58
-rw-r--r--gamemode/core/pac/sv_pac.lua2
-rw-r--r--gamemode/inventorysystem/equipment/cl_equipment.lua2
-rw-r--r--gamemode/itemsystem/foodstuffs/watermelon.lua8
-rw-r--r--gamemode/itemsystem/weapons/rustyaxe.lua355
-rw-r--r--gamemode/itemsystem/weapons/scraphammer.lua329
-rw-r--r--gamemode/itemsystem/weapons_common.lua3
-rw-r--r--gamemode/npcsystem/sv_dummy.lua4
-rw-r--r--gamemode/nrequire.lua10
-rw-r--r--gamemode/server/sv_loadplayer.lua3
-rw-r--r--gamemode/server/sv_mapchange.lua64
-rw-r--r--gamemode/shared/shop.lua1
-rw-r--r--gamemode/utility/svg/cl_svg.lua7
25 files changed, 1054 insertions, 460 deletions
diff --git a/gamemode/client/cl_inventory.lua b/gamemode/client/cl_inventory.lua
index b1f5728..0c84e5c 100644
--- a/gamemode/client/cl_inventory.lua
+++ b/gamemode/client/cl_inventory.lua
@@ -10,7 +10,9 @@
]]
local qinv = nrequire("cl_qinventory.lua")
local state = nrequire("cl_state.lua") --Holds weather or not player is in inventory
+local itm = nrequire("core/inventory/item.lua")
--local qpray = nrequire("cl_qprayers.lua")
+local inv = {}
print("Hello from cl_inventory.lua")
--debug.Trace()
@@ -31,6 +33,9 @@ local qtabs = {} --The tabs
local width = ScrW()
local height = ScrH()
+local credits = 0
+local creditslabel
+local droppanel --Dpanel to drop things on when they are dropped, should be the backmost panel, and cover the entire screen.
local player_data --The data the player needs to show the q panel
net.Receive("art_load_player_data",function()
@@ -38,12 +43,15 @@ net.Receive("art_load_player_data",function()
player_data = net.ReadTable()
print("It was")
PrintTable(player_data)
+ credits = player_data.credits
+ if creditslabel then creditslabel:SetText(credits) end
+ print("Credits was", credits)
end)
local function BuildInventory()
print("Building inventory")
- if qframe then return end
- if not player_data then print("no player data!") return end
+ if qframe and IsValid(qframe) then return end
+ if not player_data then print("no player data!") player_data = {credits = 0} end
qframe = vgui.Create("DFrame")
qframe:SetPos(0,0)
qframe:SetSize(width / 4, height)
@@ -51,6 +59,7 @@ local function BuildInventory()
qframe:SetDraggable(true)
qframe:MakePopup()
qframe.OnClose = function(self)
+ droppanel:Hide()
state.invopen = false
self:Hide()
return
@@ -58,8 +67,18 @@ local function BuildInventory()
qframe.Remove = function(self)
state.invopen = false
self:Hide()
+ droppanel:Hide()
return
end
+
+ creditslabel = vgui.Create("DLabel",qframe)
+ creditslabel:SetText(credits)
+ creditslabel:SetPos(150,5)
+
+ local creditstext = vgui.Create("DLabel",qframe)
+ creditstext:SetText("Credits:")
+ creditstext:SetPos(100,5)
+
local tabsheet = vgui.Create("DPropertySheet",qframe)
tabsheet:Dock(FILL)
@@ -74,17 +93,34 @@ local function BuildInventory()
end
-local function ShowInventory()
+function inv.ShowInventory()
print("qframe is ", qframe)
if not qframe then BuildInventory()
else qframe:Show() end
state.invopen = true
+ droppanel = vgui.Create("DPanel")
+ droppanel:SetSize(ScrW(),ScrH())
+ droppanel:SetPos(0,0)
+ droppanel:MoveToBack()
+ droppanel:SetAlpha(10)
+ droppanel:Receiver("item",function(self,panels,dropped,_,_,_)
+ if not dropped then return end
+ print("Dropedpanel had something dropped on it!")
+ --Drop the item
+ print("Pnl:",pnl)
+ local froment = panels[1].info.owner
+ local fromid = panels[1].info.id
+ local frompos = panels[1].info.pos
+ local frominv = panels[1].info.inv
+ itm.DropItem(froment,fromid,frompos)
+ end,{})
end
-hook.Add("OnSpawnMenuOpen","ArteryOpenInventory",ShowInventory)
+hook.Add("OnSpawnMenuOpen","ArteryOpenInventory",inv.ShowInventory)
hook.Add("OnSpawnMenuClose","ArteryCloseInventory",function()
+ droppanel:Remove()
state.invopen = false
qframe:Hide()
if (not sheet) or (not sheet:GetActiveTab()) or (not sheet:GetActiveTab():GetPanel()) then return end
@@ -97,7 +133,7 @@ hook.Add("OnSpawnMenuClose","ArteryCloseInventory",function()
end
end)
-concommand.Add("showinventory",ShowInventory)
+concommand.Add("showinventory",inv.ShowInventory)
local viewdistance = 100
local rotatespeed = 65
local bone = nil
@@ -128,3 +164,5 @@ hook.Add("CalcView","ArteryInventoryView",function(ply,pos,ang,fov,nearz,farz)
return view
end)
+
+return inv
diff --git a/gamemode/core/clienteffects/blocked.lua b/gamemode/core/clienteffects/blocked.lua
new file mode 100644
index 0000000..fa2352c
--- /dev/null
+++ b/gamemode/core/clienteffects/blocked.lua
@@ -0,0 +1,3 @@
+--[[
+ Return a function that will get called when our attack is blocked (client side)
+]]
diff --git a/gamemode/core/database/sv_queries.lua b/gamemode/core/database/sv_queries.lua
new file mode 100644
index 0000000..4e48255
--- /dev/null
+++ b/gamemode/core/database/sv_queries.lua
@@ -0,0 +1,51 @@
+--[[
+ Some helper functions for building sql queries
+]]
+
+local fn = nrequire("utility/fn.lua")
+local track = nrequire("core/inventory/sv_invtracker.lua")
+
+local q = {}
+
+function q.serialize_player(ply)
+ local sdata = {}
+ local invs = {}
+ for k,v in pairs(ply.data.inventories) do
+ invs[k] = {v.Name,v:Serialize()}
+ end
+ sdata.inventories = invs
+ sdata.skills = ply.data.skills
+ sdata.quests = ply.data.quests
+ sdata.prayers = ply.data.prayers
+ sdata.credits = ply.data.credits
+ return util.TableToJSON(sdata)
+end
+
+function q.deserialize_player(ply,str)
+ print("Deseriailizeing player",ply," with ", str)
+ track.ClearInventories(ply)
+ local tbl = util.JSONToTable(str)
+ local invs = tbl.inventories
+ print("Inventories was", invs)
+ PrintTable(invs)
+ for k,v in pairs(invs) do
+ print("Giveing inventory",v[1],v[2])
+ track.GiveInventoryWithData(ply,v[1],v[2])
+ end
+ ply.data = ply.data or {}
+ ply.data.skills = tbl.skills or {}
+ ply.data.quests = tbl.quests or {}
+ ply.data.prayers = tbl.prayers or {}
+ ply.data.credits = tbl.credits or 100
+ print("After deserializeing player, their .data is",ply.data)
+ PrintTable(ply.data)
+ track.SendPlayerData(ply)
+end
+
+function q.s_fmt(fmt,...)
+ local args = {...}
+ fn.map(args,MySQLite.SQLStr)
+ return string.format(fmt,unpack(args))
+end
+
+return q
diff --git a/gamemode/core/database/sv_setup.lua b/gamemode/core/database/sv_setup.lua
index 0d0eb74..2fb7ed7 100644
--- a/gamemode/core/database/sv_setup.lua
+++ b/gamemode/core/database/sv_setup.lua
@@ -2,10 +2,8 @@
nrequire("sv_mysqlite.lua")
local config = nrequire("config/sv_sql.lua")
local data = nrequire("config/sv_newplayer.lua")
-local fn = nrequire("fn.lua")
-local col = nrequire("colortheme.lua")
-local inv = nrequire("inventory/inventory.lua")
-local track = nrequire("sv_invtracker.lua")
+local col = nrequire("config/colortheme.lua")
+local q = nrequire("core/database/sv_queries.lua")
local sql = {}
--Setup the database if it's not already
@@ -14,7 +12,7 @@ CREATE TABLE IF NOT EXISTS playerdata(SteamID bigint primary key, PlayerData jso
--Create a new player
local create_player_query = [[
-INSERT INTO playerdata (`SteamID`,`PlayerData`,`MetaData`) VALUES(%.0f,%q,%q)]]
+INSERT INTO playerdata (`SteamID`,`PlayerData`,`MetaData`) VALUES(%.0f,'%s','%s')]]
--Get a player's data from the database
local fetch_player_query = [[
@@ -22,48 +20,14 @@ SELECT PlayerData, MetaData FROM playerdata WHERE SteamID=%.0f
]]
local save_player_query = [[
-UPDATE playerdata SET MetaData=%q PlayerData=%q WHERE SteamID=%.0f
+UPDATE playerdata SET MetaData="%s" PlayerData="%s" WHERE SteamID=%.0f
]]
-local s_fmt = function(fmt,...)
- local args = {...}
- fn.map(args,MySQLite.SQLStr)
- return string.format(fmt,unpack(args))
-end
-
local function q_fai(err,query)
- MsgC(col.console.red,string.format("Error executing %q, error:%s",query,err))
+ MsgC(col.console.red,string.format("Error executing %s, error:%s",query,err))
end
-local function serialize_player(ply)
- local sdata = {}
- local invs = {}
- for k,v in pairs(ply.data.inventories) do
- invs[k] = {v.Name,v:Serialize()}
- end
- sdata.inventories = invs
- sdata.skills = ply.data.skills
- sdata.quests = ply.data.quests
- sdata.prayers = ply.data.prayers
- return util.TableToJSON(sdata)
-end
-local function deserialize_player(ply,str)
- print("Deseriailizeing player",ply," with ", str)
- track.ClearInventories(ply)
- local tbl = util.JSONToTable(str)
- local invs = tbl.inventories
- print("Inventories was", invs)
- PrintTable(invs)
- for k,v in pairs(invs) do
- print("Giveing inventory",v[1],v[2])
- track.GiveInventoryWithData(ply,v[1],v[2])
- end
- ply.data.skills = tbl.skills or {}
- ply.data.quests = tbl.quests or {}
- ply.data.prayers = tbl.prayers or {}
- track.SendPlayerData(ply)
-end
local function connect()
print("Connecting to the database...")
@@ -81,7 +45,7 @@ connect()
--Retruns (PlayerData, MetaData) or nil
function sql.GetPlayerData(ply)
local s64 = ply:SteamID64()
- local q_str = s_fmt(fetch_player_query,s64)
+ local q_str = q.s_fmt(fetch_player_query,s64)
local q_suc = function(res,li)
print("Got player's data:",res,type(res))
if res == nil then
@@ -101,13 +65,18 @@ function sql.GetPlayerData(ply)
return
end
print("We were on the right server")
- local _,_,x,y,z = mtbl.lastlocation:find("([%d%.]+) ([%d%.]+) ([%d%.]+)")
+ --[[
+ print("Before finding data in the metatable, mtbl was ")
+ PrintTable(mtbl)
+ print(type(mtbl.lastlocation))
+ local _,_,x,y,z = string.find(mtbl.lastlocation,"([-%d%.]+) ([-%d%.]+) ([-%d%.]+)")
local vec = {x,y,z}
for k,v in pairs(vec) do vec[k] = tonumber(v) end
print("setting player pos to")
PrintTable(vec)
- ply:SetPos(Vector(unpack(vec)))
- deserialize_player(ply,plyd)
+ ]]
+ ply:SetPos(mtbl.lastlocation)
+ q.deserialize_player(ply,plyd)
end
end
print("doing query",q_str)
@@ -122,7 +91,7 @@ function sql.CreatePlayerTable(ply)
local plymet = data.newmeta()
local plydata = util.TableToJSON(plytbl)
local metdata = util.TableToJSON(plymet)
- local q_str = s_fmt(create_player_query,s64,plydata,metdata)
+ local q_str = q.s_fmt(create_player_query,s64,plydata,metdata)
local q_suc = function(res,li)
print("Inserted new player",ply)
sql.GetPlayerData(ply)
@@ -133,12 +102,12 @@ end
function sql.SendPlayerToInstance(ply,ls,ll)
local s64 = ply:SteamID64()
- local plydata = serialize_player(ply)
+ local plydata = q.serialize_player(ply)
local plymeta = util.TableToJSON({
lastserver = ls,
lastlocation = ll
})
- local q_str = s_fmt(save_player_query,plymeta,plydata,s64)
+ local q_str = q.s_fmt(save_player_query,plymeta,plydata,s64)
local q_suc = function(res,li)
print("Successfully saved player data")
end
@@ -157,4 +126,6 @@ concommand.Add("DoQuery",function(ply,cmd,args)
end
end)
+print("In sv_setup.lua, sql before returning is", sql)
+
return sql
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
diff --git a/gamemode/core/inventory/inventory.lua b/gamemode/core/inventory/inventory.lua
index b4c025c..6b6f6f4 100644
--- a/gamemode/core/inventory/inventory.lua
+++ b/gamemode/core/inventory/inventory.lua
@@ -1,20 +1,33 @@
--[[
Public functions:
RegisterInventory(tbl_inventory) ::nil
+ Registers a new inventory prototype, see below
CreateInventory(string_name) ::table_inventory
+ Creates a new inventory be sure to set the .owner and .id fields!
CreateInventoryFromData(string_name,string_data)::table_inventory)
+ Just deserializes an inventory. You still need to set .owner and .id!
DeriveInventory(string_name) ::table_inventory
+ Creates a new inventory from an old, allows for heiarchy.
Inventories have the following structure
- field returns description
- inv.Name ::string The name!
- inv:FindPlaceFor(item) ::table_position or nil Finds a place for the item
- inv:CanFitIn(table_position,item) ::boolean Check if the item can fit in the position
- inv:Put(table_position,item) ::nil Put an item in at the position
- inv:Has(string_or_compare_func) ::table_position or nil find an item in the inventory
- inv:Remove(position) ::table_item Remove an item from the position
- inv:Get(position) ::table_item Get the item at a position
- inv:Serialize() ::string Serialize the item to store it in a db
- inv:DeSerialize(str) ::table_inventory recreate the item from data in serialize
+ field returns
+ inv.Name ::string
+ The name!
+ inv:FindPlaceFor(item) ::table_position or nil
+ Finds a place for the item
+ inv:CanFitIn(table_position,item) ::boolean
+ Check if the item can fit in the position
+ inv:Put(table_position,item) ::nil
+ Put an item in at the position
+ inv:Has(string_or_compare_func) ::table_position or nil
+ find an item in the inventory
+ inv:Remove(position) ::table_item
+ Remove an item from the position
+ inv:Get(position) ::table_item
+ Get the item at a position
+ inv:Serialize() ::string
+ Serialize the item to store it in a db
+ inv:DeSerialize(str) ::table_inventory
+ recreate the item from data in serialize
The above fields must be defined for new inventories.
-----------------------------------------------------
The below are automatically made if they do not exist.
diff --git a/gamemode/core/inventory/item.lua b/gamemode/core/inventory/item.lua
index dd788d6..103da7f 100644
--- a/gamemode/core/inventory/item.lua
+++ b/gamemode/core/inventory/item.lua
@@ -35,7 +35,13 @@ end
function itm.GetItemByName(name)
assert(items[name] ~= nil,string.format("Attempted to get item with invalid name %q Valid item names are:\n\t%s",name,table.concat(table.GetKeys(items),"\n\t")))
- return items[name]
+ local item
+ if items[name].init then
+ item = items[name]:init()
+ else
+ item = table.Copy(items[name])
+ end
+ return item
end
function itm.GetItemFromData(name,data)
diff --git a/gamemode/core/inventory/sv_invtracker.lua b/gamemode/core/inventory/sv_invtracker.lua
index 5331261..4c1fc1b 100644
--- a/gamemode/core/inventory/sv_invtracker.lua
+++ b/gamemode/core/inventory/sv_invtracker.lua
@@ -12,6 +12,7 @@ for k,v in pairs({
"art_CloseInventory",
"art_load_player_data",
"art_RequestInvMove",
+ "art_RequestInvDrop",
}) do util.AddNetworkString(v) end
--[[
net.Receive("art_ObserveInventory",function()
@@ -62,6 +63,21 @@ net.Receive("art_RequestInvMove",function(len,ply)
toinv:Put(topos,item)
end)
+net.Receive("art_RequestInvDrop",function(len,ply)
+ local froment = net.ReadEntity()
+ local frominvid = net.ReadUInt(32)
+ local frompos = net.ReadTable()
+ assert(not froment:IsPlayer() or froment == ply, "Player tried to drop an item that was from another players inventory")
+ local frominv = froment.data.inventories[frominvid]
+ local item = frominv:Get(frompos)
+ frominv:Remove(frompos)
+ local e = ents.Create("art_droppeditem")
+ e.Item = {Name = item.Name, Data = item:Serialize()}
+ e:SetPos((ply:GetForward() * 20) + ply:GetPos())
+ e:Spawn()
+
+end)
+
function track.ClearInventories(ply)
ply.data = {}
ply.data.inventories = {}
@@ -150,7 +166,7 @@ end
local plymeta = FindMetaTable("Player")
function plymeta:HasItem(str)
- for k,v in pairs(self.inventories) do
+ for k,v in pairs(self.data.inventories) do
local p = v:Has(str)
if type(p) == "table" then
return {k,p}
@@ -160,23 +176,52 @@ function plymeta:HasItem(str)
end
function plymeta:RemoveItem(tbl)
+ print("Got remove table, it was",tbl)
+ PrintTable(tbl)
local nid = tbl[1]
local pos = tbl[2]
- self.inventories[nid]:Remove(pos)
+ print("Self inventory was")
+ PrintTable(self.data.inventories[nid])
+ self.data.inventories[nid]:Remove(pos)
+end
+
+function plymeta:GiveItem(tbl)
+ for k,v in pairs(self.data.inventories) do
+ local p = v:FindPlaceFor(tbl)
+ if type(p) == "table" then
+ v:Put(p,tbl)
+ return
+ end
+ end
+ error("Unable to find place to put item")
+end
+
+function plymeta:GetCredits()
+ return self.data.credits
+end
+
+function plymeta:SetCredits(num)
+ print("Set credits called")
+ self.data.credits = num
+ net.Start("art_load_player_data")
+ net.WriteTable({
+ credits = num
+ })
+ net.Send(self)
end
function track.SendPlayerData(ply)
net.Start("art_load_player_data")
- net.WriteTable({})
+ net.WriteTable({
+ credits = ply.data.credits
+ })
net.Send(ply)
end
concommand.Add("SendMeData",function(ply,cmd,args)
track.ClearInventories(ply)
track.GiveInventoryTo(ply,"Equipment")
- net.Start("art_load_player_data")
- net.WriteTable({})
- net.Send(ply)
+ track.SendPlayerData(ply)
end)
concommand.Add("ShowMyInventories",function(ply,cmd,args)
@@ -188,22 +233,11 @@ concommand.Add("AddInventory",function(ply,cmd,args)
end)
concommand.Add("GiveItem",function(ply,cmd,args)
- local itmname = args[1]
- local item = itm.GetItemByName(itmname)
- local foundplacefor = false
- for k,v in pairs(ply.data.inventories) do
- print("Trying to find a place in ", v.Name)
- local pf = v:FindPlaceFor(item)
- print("It returned ", pf)
- if pf ~= nil then
- v:Put(pf,item)
- foundplacefor = true
- break
- end
- end
- if not foundplacefor then
- print("I couldn't find a place to put it!")
- end
+ xpcall(function()
+ ply:GiveItem(itm.GetItemByName(args[1]))
+ end,function()
+ print("Could not find a position to put that in!")
+ end)
end)
return track
diff --git a/gamemode/core/mapstich/cl_mapstich.lua b/gamemode/core/mapstich/cl_mapstich.lua
new file mode 100644
index 0000000..65a5208
--- /dev/null
+++ b/gamemode/core/mapstich/cl_mapstich.lua
@@ -0,0 +1,12 @@
+--[[
+ The client constantly cheks to see if we're in a serverchnage zone
+]]
+
+hook.Add("Think","artery_checklevelchange",function()
+ local z = LocalPlayer():GetCurrentZone()
+ --print("looks like i'm in zone",z)
+ if z then
+ net.Start("art_zonechange")
+ net.SendToServer()
+ end
+end)
diff --git a/gamemode/core/mapstich/sv_mapstich.lua b/gamemode/core/mapstich/sv_mapstich.lua
new file mode 100644
index 0000000..93f8667
--- /dev/null
+++ b/gamemode/core/mapstich/sv_mapstich.lua
@@ -0,0 +1,70 @@
+--Make sure zones are loaded already
+nrequire("sv_mysqlite.lua")
+local q = nrequire("core/database/sv_queries.lua")
+--if not zones then error("This thing needs zones to function!") end
+
+print("Hello from sv_mapstich.lua")
+util.AddNetworkString("art_zonechange")
+
+local dontupdatedisconnect = {}
+
+local function SavePlayerData(ply)
+ local query
+ local pdat = q.serialize_player(ply)
+ if dontupdatedisconnect[ply] then
+ dontupdatedisconnect[ply] = nil
+ query = [[
+ UPDATE playerdata SET PlayerData='%s' WHERE SteamID=%.0f
+ ]]
+ query = q.s_fmt(query,pdat,ply:SteamID64())
+ else
+ query = [[
+ UPDATE playerdata SET PlayerData='%s' MetaData='%s' WHERE SteamID=%.0f
+ ]]
+ local pmet = util.TableToJSON({
+ lastserver = game.GetIPAddress(),
+ lastlocation = ply:GetPos()
+ })
+ query = q.s_fmt(query,pdat,pmet,ply:SteamID64())
+ end
+ MySQLite.query(query,function(data)
+
+ end,function(err,sql)
+ print("Query error:")
+ print("Query",sql)
+ print("Error",err)
+ end)
+end
+
+net.Receive("art_zonechange",function(len,ply)
+
+ timer.Simple(0.5,function()
+ local zone = ply:GetCurrentZone("artery_serverchange")
+ if zone then
+ dontupdatedisconnect[ply] = true
+
+ local query = [[
+ UPDATE playerdata SET PlayerData='%s',MetaData='%s' WHERE SteamID=%.0f
+ ]]
+ local pdat = util.TableToJSON(ply.data)
+ local pmet = util.TableToJSON({
+ lastserver = zone.toserver,
+ lastlocation = zone.topos
+ })
+ print("pdat is", pdat)
+ print("pmet is", pmet)
+ local fquery = q.s_fmt(query,pdat,pmet,ply:SteamID64())
+ print("fquery was", fquery)
+ print("Running query:",qc)
+ MySQLite.query(fquery,function(data)
+ ply:ConCommand("connect " .. zone.toserver)
+ end,function(err,sql)
+ print("Query error:")
+ print("Query",sql)
+ print("Error",err)
+ end)
+
+ SavePlayerData(ply)
+ end
+ end)
+end)
diff --git a/gamemode/core/npc/cl_shop.lua b/gamemode/core/npc/cl_shop.lua
new file mode 100644
index 0000000..fa076ce
--- /dev/null
+++ b/gamemode/core/npc/cl_shop.lua
@@ -0,0 +1,141 @@
+local inv = nrequire("client/cl_inventory.lua")
+local itm = nrequire("core/inventory/item.lua")
+print("in cl_shop inv is", inv)
+local w,h = ScrW(),ScrH()
+local function DrawShopItemOnDPanel(dp,itemtbl,cost)
+ --An item is a string, and int cost
+
+ local shape = itemtbl.Shape
+ local twidth,theight = 0,#shape
+ for k = 1,#shape do
+ twidth = math.max(twidth,#shape[k])
+ end
+
+ local slotsize = math.Round(w / 32)
+ local backgrid = vgui.Create( "DGrid", dp )
+ backgrid:SetPos( 10, 30 )
+ backgrid:SetCols( twidth )
+ backgrid:SetColWide( theight )
+ backgrid:Dock(LEFT)
+
+ local shopicon = vgui.Create( "DImageButton", dp )
+ shopicon:SetSize(slotsize * twidth, slotsize * theight)
+ shopicon:SetPos(0,0)
+ shopicon:SetText(itemtbl.Name)
+ if itemtbl.Tooltip then
+ shopicon:SetTooltip(itemtbl.Tooltip)
+ end
+ if itemtbl.Paint then
+ shopicon.Paint = itemtbl.Paint
+ end
+ if itemtbl.DoOnPanel then
+ itemtbl.DoOnPanel(shopicon)
+ end
+ shopicon.Paint = function(self, wi, hi)
+ surface.SetDrawColor( 0, 0, 0, 255 )
+ surface.DrawOutlinedRect( 0, 0, wi, hi)
+ end
+ shopicon.DoClick = function()
+ print("You cliked me!")
+ end
+ shopicon.Item = itemtbl
+ shopicon.Cost = cost
+ shopicon.ondropped = function(back,j,i,item)
+ print("ondropped was called!")
+ print("back",back,"j",j,"i",i,"item",item)
+ PrintTable(item)
+ net.Start("buyitem")
+ net.WriteString(item.Name)
+ net.WriteUInt(back,8)
+ net.WriteUInt(j,8)
+ net.WriteUInt(i,8)
+ net.SendToServer()
+ end
+
+ print("Displaying shape:")
+ PrintTable(shape)
+ for k = 1, twidth do
+ for i = 1, theight do
+ if not shape[k][i] then
+ print("Found false spot:",k,i)
+ local emptyslot = vgui.Create("DPanel", dp)
+ emptyslot:SetSize(slotsize,slotsize)
+ emptyslot:SetPos(slotsize * (i - 1) + 2, slotsize * (k - 1) + 2)
+ end
+ end
+ end
+
+ local buybutton = vgui.Create("DButton",dp)
+ buybutton:Dock(RIGHT)
+ buybutton:SetText("Buy\n(" .. cost .. ")")
+ buybutton.DoClick = function()
+ net.Start("art_buyitem")
+ net.WriteString(itemtbl.Name)
+ net.SendToServer()
+ end
+
+end
+
+local slotsize = math.Round(w / 32)
+
+local function DrawShopOnDPanel(dp,items)
+ --This gets pretty involved, lets try to not make it a clusterfuck.
+ dp.Paint = function(self, wi, hi) draw.RoundedBox(4, 0,0,wi,hi,Color(100,0,0)) end
+ print("dp",dp)
+ local scrollpanel = vgui.Create( "DScrollPanel",dp )
+ print("scollpanel",scrollpanel)
+ scrollpanel.Paint = function(self, wi, hi) draw.RoundedBox(4, 0,0,wi,hi,Color(0,0,100)) end
+ scrollpanel:Dock(FILL)
+ for k,v in pairs(items) do
+ local itemtbl = itm.GetItemByName(v[1])
+ local invpanel = vgui.Create( "DPanel", scollpanel)
+ invpanel.Paint = function(self, wi, hi)
+ draw.RoundedBox(4, 1,1,wi-4,hi-4,Color(50,50,50))
+ draw.RoundedBox(4, 2,2,wi-5,hi-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
+
+local shopwindow,shoppanel
+
+local function createshopwindow()
+ print("Createing shopwindow")
+ shopwindow = vgui.Create( "DFrame" )
+ shopwindow:SetPos( w - (w / 4), 0 )
+ shopwindow:SetSize( w / 4, h )
+ shopwindow:SetTitle( "Unset shop" )
+ shopwindow:SetDraggable( true )
+ shopwindow.OnClose = function(self)
+ self:SetVisible(false)
+ print("After onclose, shopwindow was",shopwindow)
+ end
+ shopwindow:SetVisible(false)
+
+ shoppanel = vgui.Create( "DPanel",shopwindow)
+ shoppanel:SetPos( 10, 30 ) -- Set the position of the panel
+ shoppanel:Dock(FILL)
+end
+createshopwindow()
+
+net.Receive("art_openshop",function()
+ print("shopwindows was ",shopwindow)
+ if not shopwindow:IsValid() then createshopwindow() end
+ assert(shopwindow,"Shopwindow was not created, even after re-createing!")
+ print("inv was", inv)
+ inv.ShowInventory()
+ shopwindow:SetVisible(true)
+ local stock = net.ReadTable()
+ DrawShopOnDPanel(shoppanel,stock)
+ shopwindow:MakePopup()
+end)
diff --git a/gamemode/core/npc/sv_shop.lua b/gamemode/core/npc/sv_shop.lua
index 2e54f7e..2825996 100644
--- a/gamemode/core/npc/sv_shop.lua
+++ b/gamemode/core/npc/sv_shop.lua
@@ -2,8 +2,28 @@
Create a shop npc
]]
+local itm = nrequire("core/inventory/item.lua")
+
local shop = {}
+for k,v in pairs({
+ "art_openshop",
+ "art_buyitem",
+ "art_sellitem",
+}) do
+ util.AddNetworkString(v)
+end
+
+function shop.OpenShop(tbl, ply)
+ print("Called openshop!")
+ print("tbl was")
+ PrintTable(tbl)
+ if CLIENT then return end
+ net.Start("art_openshop")
+ net.WriteTable(tbl)
+ net.Send(ply)
+end
+
function shop.CreateShop(npc)
print("Createing shop npc")
local npcent = ents.Create("npc_shop")
@@ -14,4 +34,42 @@ function shop.CreateShop(npc)
print("Called spawn")
end
+net.Receive("art_buyitem",function(len,ply)
+ local itemname = net.ReadString()
+
+ --Find the shop near the player
+ local es = ents.FindInSphere(ply:GetPos(),500)
+ local shop
+ for k,v in pairs(es) do
+ if IsValid(v) and v:GetClass() == "npc_shop" then
+ shop = v
+ break
+ end
+ end
+ print("Shop was", shop)
+ print("Items:", shop.shopitems)
+ PrintTable(shop.shopitems)
+
+ --Find the price of the item we want to buy
+ local price
+ for k,v in pairs(shop.shopitems) do
+ if v[1] == itemname then
+ price = v[2]
+ break
+ end
+ end
+
+ --Make sure we have enough credits to buy it
+ if ply:GetCredits() < price then
+ print(ply, " didn't have enough credits to buy a ", itemname, "(" .. price .. ")")
+ else
+ xpcall(function()
+ ply:GiveItem(itm.GetItemByName(itemname))
+ ply:SetCredits(ply:GetCredits() - price)
+ end,function(err)
+ print("Coulden't fit a " , itemname, " into ", ply, "'s inventory: ", err)
+ end)
+ end
+end)
+
return shop
diff --git a/gamemode/core/pac/sv_pac.lua b/gamemode/core/pac/sv_pac.lua
index 5a82607..3c5c6be 100644
--- a/gamemode/core/pac/sv_pac.lua
+++ b/gamemode/core/pac/sv_pac.lua
@@ -64,6 +64,7 @@ loadhashes()
local appliedpacs = {}
function p3.ApplyPac(what, name)
+ print("Applying pac", what, "to",name)
appliedpacs[what] = appliedpacs[what] or {}
appliedpacs[what][name] = pachashes[name]
net.Start("artery_applypac")
@@ -74,6 +75,7 @@ function p3.ApplyPac(what, name)
end
function p3.RemovePac(what, name)
+ print("Removeing pac",what,"from",name)
assert(appliedpacs[what][name],"Attempted to remove a pac that an entity is not wearing!")
appliedpacs[what][name] = nil
if #appliedpacs[what] == 0 then
diff --git a/gamemode/inventorysystem/equipment/cl_equipment.lua b/gamemode/inventorysystem/equipment/cl_equipment.lua
index 22458c7..8a14a1a 100644
--- a/gamemode/inventorysystem/equipment/cl_equipment.lua
+++ b/gamemode/inventorysystem/equipment/cl_equipment.lua
@@ -153,7 +153,7 @@ inv.DrawOnDPanel = function(self,panel)
print("Put was called!",position,item)
PrintTable(position)
PrintTable(item)
- assert(self[position[1]] ~= nil, "Tried to put an item into an unknown slot!")
+ assert(self[position[1]] ~= nil, "Tried to put an item into an unknown slot! Slot:" .. position[1])
if item.GetOptions then
self[position[1]].DoClick = function()
local dm = DermaMenu()
diff --git a/gamemode/itemsystem/foodstuffs/watermelon.lua b/gamemode/itemsystem/foodstuffs/watermelon.lua
index 851cf1f..3f858d7 100644
--- a/gamemode/itemsystem/foodstuffs/watermelon.lua
+++ b/gamemode/itemsystem/foodstuffs/watermelon.lua
@@ -2,6 +2,10 @@
An example item
]]
local item = {}
+local pac
+if SERVER then
+ pac = nrequire("core/pac/sv_pac.lua")
+end
--Required, a name, all item names must be unique
item.Name = "Watermelon"
@@ -47,7 +51,9 @@ item.Shape = {
}
item.onDropped = function(self, ent)
- ART.ApplyPAC(ent,"Watermelon")
+ if SERVER then
+ pac.ApplyPac(ent,"Watermelon")
+ end
end
print("Hello from exampleitem.lua")
diff --git a/gamemode/itemsystem/weapons/rustyaxe.lua b/gamemode/itemsystem/weapons/rustyaxe.lua
index c19a24a..00547c8 100644
--- a/gamemode/itemsystem/weapons/rustyaxe.lua
+++ b/gamemode/itemsystem/weapons/rustyaxe.lua
@@ -1,12 +1,15 @@
--[[
- An example item
+ An axe that you can swing around!
]]
local pac
if SERVER then
pac = nrequire("core/pac/sv_pac.lua")
- print("in rustyaxe.lua, pac is", pac)
end
-local reg = nrequire("item.lua")
+local reg = nrequire("core/inventory/item.lua")
+local com = nrequire("core/inventory/common/weapons.lua")
+local itm = nrequire("core/inventory/common/items.lua")
+
+
local item = {}
--Required, a name, all item names must be unique
@@ -17,219 +20,223 @@ 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 ""
+ 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
+ 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
- options["Drop"] = ART.DropItem(self)
- return options
+ 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
function item.DoOnPanel(dimagebutton)
- dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png")
+ dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png")
end
function item.DoOnEqupPanel(dimagebutton)
- print("called with panel:",panel)
- dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png")
+ 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},
+ {true,true},
+ {true},
+ {true},
}
--Optional, If this item can be equiped in any player slots, put them here.
item.Equipable = "Right Hand"
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)},
- },
+ ["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)},
+ },
+}
+
+local attacks = {
+ ["forward"] = {
+ time = 2.33,
+ anim = "axe_swing_up",
+ }
}
--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 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)
- 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
- end)
-
- end,
- ["backward"] = function()
-
- end,
- ["left"] = function()
- owner:SetLuaAnimation("axe_swing_left")
- 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
- end)
- end,
- ["right"] = function()
- owner:SetLuaAnimation("axe_swing_right")
- 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
- end)
- end,
- }
- movementtbl[ART.playermovedir(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 movementtbl = {
+ ["forward"] = function()
+ --Do the animation
+ owner:SetLuaAnimation("axe_swing_up")
+ timer.Simple(2.33,function()
+ owner:StopLuaAnimation("axe_swing_up")
+ end)
+ --Do the traces
+ 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
+ --What to do when our weapon hits
+ com.swingarc(owner,times,pos,function(tr)
+ print("Calling the swingarc function")
+ if not tr.Hit then return end
+ print("We hit something!")
+ print("takedamage is",tr.Entity.TakeDamage)
+ 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
+ print("I hit a ", tr.Entity)
+ tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon())
+ end
+ end)
+
+ end,
+ ["backward"] = function()
+
+ end,
+ ["left"] = function()
+ owner:SetLuaAnimation("axe_swing_left")
+ 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
+ com.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
+ end)
+ end,
+ ["right"] = function()
+ owner:SetLuaAnimation("axe_swing_right")
+ 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
+ com.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
+ end)
+ end,
+ }
+ print("At time of doing playermovedir, com is", com)
+ movementtbl[com.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
+ print("onEquip",who)
+ if CLIENT then print("onEquip client!") end
+ if SERVER then
print("pac is", pac)
- PrintTable(pac)
- who:GetActiveWeapon():SetHoldType("melee")
- pac.ApplyPac(who,"rustyaxe")
- --local outfit = pac.luadata.ReadFile("pac3/mech.txt")
- --who:AttachPACPart(outfit)
- --print("onEquip server!")
- end
+ PrintTable(pac)
+ who:GetActiveWeapon():SetHoldType("melee")
+ pac.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)
print("Unequiping axe")
- who:GetActiveWeapon():SetHoldType("normal")
- if SERVER then pac.RemovePac(who,"rustyaxe") end
+ who:GetActiveWeapon():SetHoldType("normal")
+ if SERVER then pac.RemovePac(who,"rustyaxe") end
end
item.onDropped = function(self, ent)
- if SERVER then pac.ApplyPac(ent,"rustyaxe") end
+ if SERVER then pac.ApplyPac(ent,"rustyaxe") end
end
print("Hello from rustyaxe.lua")
diff --git a/gamemode/itemsystem/weapons/scraphammer.lua b/gamemode/itemsystem/weapons/scraphammer.lua
index 586b331..762dc5f 100644
--- a/gamemode/itemsystem/weapons/scraphammer.lua
+++ b/gamemode/itemsystem/weapons/scraphammer.lua
@@ -1,233 +1,202 @@
--[[
An example item
]]
+local com = nrequire("core/inventory/common/weapons.lua")
+local itm = nrequire("core/inventory/common/items.lua")
+local reg = nrequire("core/inventory/item.lua")
+local pac,eff
+if SERVER then
+ pac = nrequire("core/pac/sv_pac.lua")
+else
+ eff = nrequire("core/clienteffects/blocked.lua")
+end
+
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"
+item.Tooltip = "Bits of scrap put togeather to resemble 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 ""
+ 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
+ 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
- options["Drop"] = ART.DropItem(self)
- return options
+ local options = {}
+ options["test"] = function() print("You pressed test!") end
+ options["toast"] = function() print("You pressed toast!") end
+ options["Drop"] = itm.DropItem(self)
+ 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))
+ dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png")
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))
+function item.DoOnEquipPanel(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},
- {false,true},
- {false,true},
+ {true,true,true},
+ {false,true},
+ {false,true},
}
--Optional, If this item can be equiped in any player slots, put them here.
-item.Equipable = "Right"
+item.Equipable = "Right Hand"
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)}
- },
+ ["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)}
+ },
+}
+
+local attacks = {
+ forward = {
+ anim = "hammer_swing_up",
+ animtime = 2.33,
+ data = swingdata["fwd"],
+ dammage = 5
+ },
+ left = {
+ anim = "hammer_swing_left",
+ animtime = 2.33,
+ data = swingdata["lft"],
+ dammage = 5
+ },
+ right = {
+ anim = "hammer_swing_right",
+ animtime = 2.33,
+ data = swingdata["rig"],
+ dammage = 5
+ }
}
--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 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 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
- end)
-
- end,
- ["backward"] = function()
-
- end,
- ["left"] = function()
- owner:SetLuaAnimation("hammer_swing_left")
- timer.Simple(2.33,function()
- owner:StopLuaAnimation("hammer_swing_left")
- 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
- end)
- end,
- ["right"] = function()
- owner:SetLuaAnimation("hammer_swing_right")
- timer.Simple(2.33,function()
- owner:StopLuaAnimation("hammer_swing_right")
- 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
- end)
- end,
- }
- movementtbl[ART.playermovedir(owner)]()
+ --Make sure we can swing (off cooldown)
+ item.lastSwing[owner] = item.lastSwing[owner] or 0
+ if item.lastSwing[owner] > CurTime() then return end
+ item.lastSwing[owner] = CurTime()+1.33
+
+ --[[
+ local movementtbl = {}
+ for k,v in pairs(attacks) do
+ movementtbl[k] = function()
+ owner:SetLuaAnimation(v.anim)
+ timer.Simple(v.animtime,function()
+ owner: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(owner:GetAimVector():Angle())
+ end
+ if pos[1] == nil then return end
+ com.swingarc(owner,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 ~= owner then
+ tr.Entity:TakeDamage(v.dammage,owner,owner:GetActiveWeapon())
+ end
+ end)
+ end
+ end
+ ]]
+ local movementtbl = com.createattackstable(attacks)
+
+ --Do the attack
+ movementtbl[com.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
+ print("woo! i'm being used!")
+ if SERVER then
+ who:GetActiveWeapon():SetHoldType("melee2")
+ pac.ApplyPac(who,"scraphammer")
+ 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")
+ print("aw, I'm being put away :(")
+ who:GetActiveWeapon():SetHoldType("normal")
+ pac.RemovePac(who,"scraphammer")
end
item.onDropped = function(self, ent)
- ART.ApplyPAC(ent,"scraphammer")
+ pac.ApplyPac(ent,"scraphammer")
end
-print("Hello from scrapgun.lua")
+print("Hello from scraphammer.lua")
--Don't forget to register the item!
-nrequire("item.lua").RegisterItem(item)
+reg.RegisterItem(item)
diff --git a/gamemode/itemsystem/weapons_common.lua b/gamemode/itemsystem/weapons_common.lua
index 6f553fa..f31b18f 100644
--- a/gamemode/itemsystem/weapons_common.lua
+++ b/gamemode/itemsystem/weapons_common.lua
@@ -1,4 +1,5 @@
-
+--This file has been moved to core/inventory/common/weapons.lua
+do return end
ART = ART or {}
--- Finds the direction a player is moveing.
diff --git a/gamemode/npcsystem/sv_dummy.lua b/gamemode/npcsystem/sv_dummy.lua
index 6a7e894..6c5acae 100644
--- a/gamemode/npcsystem/sv_dummy.lua
+++ b/gamemode/npcsystem/sv_dummy.lua
@@ -65,8 +65,8 @@ function NPC:Stuck()
end
-function NPC:OnDammage(ammount)
- print("A dummy was hit for",ammount:GetDamage(),"!")
+function NPC:OnDammage(dmg)
+ print("A dummy was hit for",dmg: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.
diff --git a/gamemode/nrequire.lua b/gamemode/nrequire.lua
index d437a5e..6595fed 100644
--- a/gamemode/nrequire.lua
+++ b/gamemode/nrequire.lua
@@ -106,7 +106,10 @@ local function scan(pretbl, name)
assert(cursor ~= nil,string.format("Scan did not find a file named %q, valid files are:\n\t%s",filename,table.concat(collect_paths(pretbl),"\n\t")))
local rev = {}
for i = 1, #pathparts do rev[#pathparts - i + 1] = pathparts[i] end
- for k,v in ipairs(rev) do cursor = cursor[v] end
+ for k,v in ipairs(rev) do
+ if cursor == nil then error(string.format("Scan could not complete file path translation while translateing %q at %s",table.concat(rev,","),v)) end
+ cursor = cursor[v]
+ end
while type(cursor) ~= "string" do
assert(type(cursor) ~= "nil",string.format("Could not find a valid file for path %q, file paths:\n\t%s",name,table.concat(collect_paths(pretbl),"\n\t")))
assert(tbllen(cursor) == 1,string.format("Ambiguous scan, there are two or more paths that match %q\n\t%s\nSpecify more of the file path.",name,table.concat(collect_paths(cursor),"\n\t")))
@@ -136,7 +139,7 @@ local pathstack = {}
function nrequire(req)
local tpath = scan(ntbl,req)
if reqtbl[tpath] then
- print("Cache hit! returning",reqtbl[tpath])
+ --print("Cache hit! returning",reqtbl[tpath])
--for k,v in pairs(reqtbl[tpath]) do print(k,":",v) end
return reqtbl[tpath]
end
@@ -146,9 +149,12 @@ function nrequire(req)
local tab_rep = {}
for k = 1, #pathstack do tab_rep[k] = "\t" end
print(string.format("%sIncluding %q",table.concat(tab_rep),tpath))
+ local oldprint = print
+ print = function(...) oldprint(" ",unpack({...})) end
pathstack[#pathstack + 1] = tpath
reqtbl[tpath] = include(tpath)
pathstack[#pathstack] = nil
+ print = oldprint
print(string.format("%sIncluded %q",table.concat(tab_rep),tpath))
return reqtbl[tpath]
end
diff --git a/gamemode/server/sv_loadplayer.lua b/gamemode/server/sv_loadplayer.lua
index ee4eee6..f8c2568 100644
--- a/gamemode/server/sv_loadplayer.lua
+++ b/gamemode/server/sv_loadplayer.lua
@@ -1,4 +1,5 @@
local sql = nrequire("core/database/sv_setup.lua")
+print("in sv_loadplayer.lua sql is", sql)
local models = {}
for k = 1,9 do
models[#models + 1] = "models/player/Group01/male_0" .. k .. ".mdl"
@@ -6,7 +7,7 @@ for k = 1,9 do
end
local function delayplayerload(ply)
- if ply:Alive() then
+ if ply:Alive() and IsValid(ply) then
sql.GetPlayerData(ply)
else
timer.Simple(1,function()
diff --git a/gamemode/server/sv_mapchange.lua b/gamemode/server/sv_mapchange.lua
index 032a1bb..d697a67 100644
--- a/gamemode/server/sv_mapchange.lua
+++ b/gamemode/server/sv_mapchange.lua
@@ -1,12 +1,17 @@
--[[
A script to move the player to a different map
]]
+local fn = nrequire("utility/fn.lua")
+local q = nrequire("core/database/queries.lua")
+nrequire("sv_mysqlite.lua")
local mapname = game.GetMap()
local mapareasstr = file.Read("artery/maps/" .. mapname .. "/mapareas.txt")
+--[=[
+local dontupdatedisconnect = {}
+
hook.Add("InitPostEntity", "LoadMapChangePoints", function()
local transfers = string.Explode("\r?\n\r?\n",mapareasstr,true)
- local dontupdatedisconnect = {}
for k,v in pairs(transfers) do
local parts = string.Explode("\r?\n",v,true)
local vectortxt = string.Explode(" ",parts[1],false)
@@ -25,35 +30,71 @@ hook.Add("InitPostEntity", "LoadMapChangePoints", function()
print("collider",collider)
if coldata.HitEntity:IsPlayer() then
dontupdatedisconnect[coldata.HitEntity] = true
- local db = ART.database
local qc = table.concat({[[
- UPDATE artery.playerdata SET WorldPosition="]],
+ UPDATE playerdata SET MetaData="]],
tvt[1]," ",
tvt[2]," ",
tvt[3]," ",
[[" WHERE SteamID="]],
coldata.HitEntity:SteamID64(),
'"'})
+ local query = [[
+ UPDATE playerdata SET PlayerData='%s',MetaData='%s' WHERE SteamID=%.0f
+ ]]
+ local pdat = util.TableToJSON(coldata.HitEntity.data)
+ local pmet = util.TableToJSON({
+ lastserver = server,
+ lastlocation = parts[5]
+ })
+ print("pdat is", pdat)
+ print("pmet is", pmet)
+ local fquery = q.s_fmt(query,pdat,pmet,coldata.HitEntity:SteamID64())
+ print("fquery was", fquery)
print("Running query:",qc)
- local q = db:query(qc)
- function q:onSuccess(data)
- print("Got data from update:")
- PrintTable(data)
+ MySQLite.query(fquery,function(data)
coldata.HitEntity:ConCommand("connect " .. server)
- end
- function q:onError(err,sql)
+ end,function(err,sql)
print("Query error:")
print("Query",sql)
print("Error",err)
- end
- q:start()
+ end)
end
end
sch:Spawn()
print("Loading mapchange area",svec)
end
end)
+]=]
+
+local function SavePlayerData(ply)
+ local query
+ local pdat = q.serialize_player(ply)
+ if dontupdatedisconnect[ply] then
+ dontupdatedisconnect[ply] = nil
+ query = [[
+ UPDATE playerdata SET PlayerData='%s' WHERE SteamID=%.0f
+ ]]
+ query = q.s_fmt(query,pdat,ply:SteamID64())
+ else
+ query = [[
+ UPDATE playerdata SET PlayerData='%s' MetaData='%s' WHERE SteamID=%.0f
+ ]]
+ local pmet = util.TableToJSON({
+ lastserver = game.GetIPAddress(),
+ lastlocation = ply:GetPos()
+ })
+ query = q.s_fmt(query,pdat,pmet,ply:SteamID64())
+ end
+ MySQLite.query(query,function(data)
+
+ end,function(err,sql)
+ print("Query error:")
+ print("Query",sql)
+ print("Error",err)
+ end)
+end
+--[=[
hook.Add("PlayerDisconnected","SavePlayerData",function(ply)
local qc
if dontupdatedisconnect[ply] then
@@ -109,3 +150,4 @@ hook.Add("PlayerDisconnected","SavePlayerData",function(ply)
end
q:start()
end)
+]=]
diff --git a/gamemode/shared/shop.lua b/gamemode/shared/shop.lua
index c330fb3..679035f 100644
--- a/gamemode/shared/shop.lua
+++ b/gamemode/shared/shop.lua
@@ -1,3 +1,4 @@
+do return end
--[[
Displays shop npc's interfaces
diff --git a/gamemode/utility/svg/cl_svg.lua b/gamemode/utility/svg/cl_svg.lua
index 52b8556..1ab37bb 100644
--- a/gamemode/utility/svg/cl_svg.lua
+++ b/gamemode/utility/svg/cl_svg.lua
@@ -1,5 +1,10 @@
+--[[
+ SVGModule v1.0 - Alexander "Apickx" Pickering
+ Entered into the public domain Febuary 4, 2017
+ You are not required to, but consider putting a link to the source in your file's comments!
+]]
+
local svg = {}
---local fn = nrequire("fn.lua")
local file_cache_max_size = 100
local file_cache_size = 0
local file_cache = {}