diff options
| author | Alexander Pickering <Alexander.Pickering@anondomain.site90.net> | 2016-03-07 16:27:49 -0500 |
|---|---|---|
| committer | Alexander Pickering <Alexander.Pickering@anondomain.site90.net> | 2016-03-07 16:27:49 -0500 |
| commit | 154aa39e820b32878a514c3cf1410043d26fcc08 (patch) | |
| tree | d814bea2a2d0d7eac4f5f0016554df73540913a7 /gamemode | |
| parent | 008b317887e13fa27bf1317fab64dee3eb3b5de2 (diff) | |
| download | wintersurvival2-154aa39e820b32878a514c3cf1410043d26fcc08.tar.gz wintersurvival2-154aa39e820b32878a514c3cf1410043d26fcc08.tar.bz2 wintersurvival2-154aa39e820b32878a514c3cf1410043d26fcc08.zip | |
Fixing bug with AccountInv not synchronizeing correctly, blame garry
Diffstat (limited to 'gamemode')
| -rw-r--r-- | gamemode/shared/player_accountinventory.lua | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/gamemode/shared/player_accountinventory.lua b/gamemode/shared/player_accountinventory.lua index 2a1b684..4bb7fad 100644 --- a/gamemode/shared/player_accountinventory.lua +++ b/gamemode/shared/player_accountinventory.lua @@ -3,34 +3,34 @@ local meta = FindMetaTable("Player") if (SERVER) then
util.AddNetworkString("UpdateAccountInventory")
-
+
function meta:UpdateAccountSlot(id)
if (!self.AccountInv[id]) then return end
-
+
net.Start("UpdateAccountInventory")
net.WriteUInt(id,5)
net.WriteString(self.AccountInv[id].Name)
net.WriteUInt(self.AccountInv[id].Quantity,32)
net.Send(self)
end
-
+
function meta:AddAccountItem(item,quantity)
local Item = GetItemByName(item)
-
+
if (!Item) then return end
if (!self.AccountInv) then self.AccountInv = {} end
-
+
--First search for existing items
- for i = 1,MAIN_MAX_SLOTS do
+ for i = 1,MAIN_MAX_SLOTS do
if (self.AccountInv[i] and self.AccountInv[i].Name == item) then
self.AccountInv[i].Quantity = self.AccountInv[i].Quantity+quantity
self:UpdateAccountSlot(i)
return
end
end
-
+
--If it hasnt found any existing item, find an empty spot
- for i = 1,MAIN_MAX_SLOTS do
+ for i = 1,MAIN_MAX_SLOTS do
if (!self.AccountInv[i]) then
self.AccountInv[i] = {Name = item,Quantity = quantity}
self:UpdateAccountSlot(i)
@@ -38,9 +38,9 @@ if (SERVER) then end
end
end
-
+
function meta:RemoveAccountItem(item,quantity)
- for i = 1,MAIN_MAX_SLOTS do
+ for i = 1,MAIN_MAX_SLOTS do
if (self.AccountInv[i] and self.AccountInv[i].Name == item) then
if (self.AccountInv[i].Quantity > quantity) then
self.AccountInv[i].Quantity = self.AccountInv[i].Quantity-quantity
@@ -48,13 +48,13 @@ if (SERVER) then return
else
quantity = quantity - self.AccountInv[i].Quantity
-
+
self.AccountInv[i].Quantity = 0
-
+
self:UpdateAccountSlot(i)
-
+
self.AccountInv[i] = nil
-
+
if (quantity > 0) then self:RemoveAccountItem(item,quantity) return end
end
end
@@ -63,14 +63,15 @@ if (SERVER) then else
net.Receive("UpdateAccountInventory",function()
local pl = LocalPlayer()
-
+
if (!pl.AccountInv) then pl.AccountInv = {} end
-
+
local ID = net.ReadUInt(5)
+ if(not pl.AccountInv) then return end
pl.AccountInv[ID] = {Name = net.ReadString(),Quantity = net.ReadUInt(32)}
-
+
if (pl.AccountInv[ID].Quantity <= 0) then pl.AccountInv[ID] = nil end
-
+
ReloadAccountMenu()
end)
end
@@ -81,18 +82,18 @@ end function meta:HasAccountItem(name,quantity)
if (!self.AccountInv) then return end
-
+
quantity = quantity or 1
-
+
for k,v in pairs(self.AccountInv) do
if (v.Name == name and v.Quantity >= quantity) then
return k
end
end
-
+
return false
end
function meta:GetAccountSlot(id)
return (self.AccountInv and self.AccountInv[id]) or nil
-end
\ No newline at end of file +end
|
