aboutsummaryrefslogtreecommitdiff
path: root/gamemode/shared/inventory.lua
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode/shared/inventory.lua')
-rw-r--r--gamemode/shared/inventory.lua28
1 files changed, 25 insertions, 3 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 )