Skip to content

Commit

Permalink
Fix Iter loops (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
Winkarst-cpu authored Jan 7, 2025
1 parent ae11869 commit e6c621c
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 79 deletions.
6 changes: 3 additions & 3 deletions gamemode/core/derma/cl_inventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -774,12 +774,12 @@ hook.Add("CreateMenuButtons", "ixInventory", function(tabs)
ix.gui.inv1 = panel

if (ix.option.Get("openBags", true)) then
for _, v in inventory:Iter() do
if (!v.isBag) then
for k, _ in inventory:Iter() do
if (!k.isBag) then
continue
end

v.functions.View.OnClick(v)
k.functions.View.OnClick(k)
end
end

Expand Down
4 changes: 2 additions & 2 deletions gamemode/core/hooks/sh_hooks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,8 @@ function GM:CanTransferItem(itemObject, curInv, inventory)

-- don't allow transferring items that are in use
if (inventory) then
for _, v in inventory:Iter() do
if (v:GetData("equip") == true) then
for k, _ in inventory:Iter() do
if (k:GetData("equip") == true) then
local owner = itemObject:GetOwner()

if (owner and IsValid(owner)) then
Expand Down
16 changes: 8 additions & 8 deletions gamemode/core/hooks/sv_hooks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -564,12 +564,12 @@ function GM:PostPlayerLoadout(client)
local character = client:GetCharacter()

if (character:GetInventory()) then
for _, v in character:GetInventory():Iter() do
v:Call("OnLoadout", client)
for k, _ in character:GetInventory():Iter() do
k:Call("OnLoadout", client)

if (v:GetData("equip") and v.attribBoosts) then
for attribKey, attribValue in pairs(v.attribBoosts) do
character:AddBoost(v.uniqueID, attribKey, attribValue)
if (k:GetData("equip") and k.attribBoosts) then
for attribKey, attribValue in pairs(k.attribBoosts) do
character:AddBoost(k.uniqueID, attribKey, attribValue)
end
end
end
Expand Down Expand Up @@ -870,9 +870,9 @@ end
function GM:CharacterPreSave(character)
local client = character:GetPlayer()

for _, v in character:GetInventory():Iter() do
if (v.OnSave) then
v:Call("OnSave", client)
for k, _ in character:GetInventory():Iter() do
if (k.OnSave) then
k:Call("OnSave", client)
end
end

Expand Down
24 changes: 12 additions & 12 deletions gamemode/core/libs/sh_storage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ if (SERVER) then
inventory.storageInfo = info

-- remove context from any bags this inventory might have
for _, v in inventory:Iter() do
if (v.isBag and v:GetInventory()) then
ix.storage.CreateContext(v:GetInventory(), table.Copy(info))
for k, _ in inventory:Iter() do
if (k.isBag and k:GetInventory()) then
ix.storage.CreateContext(k:GetInventory(), table.Copy(info))
end
end
end
Expand All @@ -110,9 +110,9 @@ if (SERVER) then
inventory.storageInfo = nil

-- remove context from any bags this inventory might have
for _, v in inventory:Iter() do
if (v.isBag and v:GetInventory()) then
ix.storage.RemoveContext(v:GetInventory())
for k, _ in inventory:Iter() do
if (k.isBag and k:GetInventory()) then
ix.storage.RemoveContext(k:GetInventory())
end
end
end
Expand Down Expand Up @@ -159,9 +159,9 @@ if (SERVER) then
client.ixOpenStorage = inventory

-- update receivers for any bags this inventory might have
for _, v in inventory:Iter() do
if (v.isBag and v:GetInventory()) then
v:GetInventory():AddReceiver(client)
for k, _ in inventory:Iter() do
if (k.isBag and k:GetInventory()) then
k:GetInventory():AddReceiver(client)
end
end

Expand Down Expand Up @@ -192,9 +192,9 @@ if (SERVER) then
inventory:RemoveReceiver(client)

-- update receivers for any bags this inventory might have
for _, v in inventory:Iter() do
if (v.isBag and v:GetInventory()) then
v:GetInventory():RemoveReceiver(client)
for k, _ in inventory:Iter() do
if (k.isBag and k:GetInventory()) then
k:GetInventory():RemoveReceiver(client)
end
end

Expand Down
40 changes: 20 additions & 20 deletions gamemode/core/meta/sh_inventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ end

-- this is pretty good to debug/develop function to use.
function META:Print(printPos)
for k, v in self:Iter() do
for k, v in pairs(self:GetItems()) do
local str = k .. ": " .. v.name

if (printPos) then
Expand All @@ -102,19 +102,19 @@ end
-- This function can be helpful for getting rid of those pesky errors.
-- @realm shared
function META:FindError()
for _, v in self:Iter() do
if (v.width == 1 and v.height == 1) then
for k, _ in self:Iter() do
if (k.width == 1 and k.height == 1) then
continue
end

print("Finding error: " .. v.name)
print("Item Position: " .. v.gridX, v.gridY)
print("Finding error: " .. k.name)
print("Item Position: " .. k.gridX, k.gridY)

for x = v.gridX, v.gridX + v.width - 1 do
for y = v.gridY, v.gridY + v.height - 1 do
for x = k.gridX, k.gridX + k.width - 1 do
for y = k.gridY, k.gridY + k.height - 1 do
local item = self.slots[x][y]

if (item and item.id != v.id) then
if (item and item.id != k.id) then
print("Error Found: ".. item.name)
end
end
Expand Down Expand Up @@ -619,10 +619,10 @@ end
-- -- do something with the item table
-- end
function META:HasItem(targetID, data)
for _, v in self:Iter() do
if (v.uniqueID == targetID) then
for k, _ in self:Iter() do
if (k.uniqueID == targetID) then
if (data) then
local itemData = v.data
local itemData = k.data
local bFound = true

for dataKey, dataVal in pairs(data) do
Expand All @@ -637,7 +637,7 @@ function META:HasItem(targetID, data)
end
end

return v
return k
end
end

Expand All @@ -661,9 +661,9 @@ function META:HasItems(targetIDs)
local count = #targetIDs -- assuming array
targetIDs = table.Copy(targetIDs)

for _, v in self:Iter() do
for item, _ in self:Iter() do
for k, targetID in ipairs(targetIDs) do
if (v.uniqueID == targetID) then
if (item.uniqueID == targetID) then
table.remove(targetIDs, k)
count = count - 1

Expand Down Expand Up @@ -692,10 +692,10 @@ end
-- end
-- -- Notifies the player that they should get some more guns.
function META:HasItemOfBase(baseID, data)
for _, v in self:Iter() do
if (v.base == baseID) then
for k, _ in self:Iter() do
if (k.base == baseID) then
if (data) then
local itemData = v.data
local itemData = k.data
local bFound = true

for dataKey, dataVal in pairs(data) do
Expand All @@ -710,7 +710,7 @@ function META:HasItemOfBase(baseID, data)
end
end

return v
return k
end
end

Expand Down Expand Up @@ -955,8 +955,8 @@ if (SERVER) then
net.WriteTable(self.vars or {})
net.Send(receiver)

for _, v in self:Iter() do
v:Call("OnSendData", receiver)
for k, _ in self:Iter() do
k:Call("OnSendData", receiver)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions gamemode/core/meta/sh_item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,11 @@ function ITEM:Remove(bNoReplication, bNoDelete)

if (failed) then
inv.slots = {}
for _, v in inv:Iter() do
if (v.invID == inv:GetID()) then
for k, _ in inv:Iter() do
if (k.invID == inv:GetID()) then
for x = self.gridX, self.gridX + (self.width - 1) do
for y = self.gridY, self.gridY + (self.height - 1) do
inv.slots[x][y] = v.id
inv.slots[x][y] = k.id
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions gamemode/items/base/sh_bags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ function ITEM:CanTransfer(oldInventory, newInventory)
return false
end

for _, v in self:GetInventory():Iter() do
if (v:GetData("id") == index2) then
for k, _ in self:GetInventory():Iter() do
if (k:GetData("id") == index2) then
return false
end
end
Expand Down
8 changes: 4 additions & 4 deletions gamemode/items/base/sh_outfit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ ITEM.functions.Equip = {
local client = item.player
local char = client:GetCharacter()

for _, v in char:GetInventory():Iter() do
if (v.id != item.id) then
local itemTable = ix.item.instances[v.id]
for k, _ in char:GetInventory():Iter() do
if (k.id != item.id) then
local itemTable = ix.item.instances[k.id]

if (itemTable.pacData and v.outfitCategory == item.outfitCategory and itemTable:GetData("equip")) then
if (itemTable.pacData and k.outfitCategory == item.outfitCategory and itemTable:GetData("equip")) then
client:NotifyLocalized(item.equippedNotify or "outfitAlreadyEquipped")
return false
end
Expand Down
8 changes: 4 additions & 4 deletions gamemode/items/base/sh_pacoutfit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ ITEM.functions.Equip = {
OnRun = function(item)
local char = item.player:GetCharacter()

for _, v in char:GetInventory():Iter() do
if (v.id != item.id) then
local itemTable = ix.item.instances[v.id]
for k, _ in char:GetInventory():Iter() do
if (k.id != item.id) then
local itemTable = ix.item.instances[k.id]

if (itemTable.pacData and v.outfitCategory == item.outfitCategory and itemTable:GetData("equip")) then
if (itemTable.pacData and k.outfitCategory == item.outfitCategory and itemTable:GetData("equip")) then
item.player:NotifyLocalized(item.equippedNotify or "outfitAlreadyEquipped")

return false
Expand Down
18 changes: 9 additions & 9 deletions gamemode/items/base/sh_weapons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ end
function ITEM:Equip(client, bNoSelect, bNoSound)
client.carryWeapons = client.carryWeapons or {}

for _, v in client:GetCharacter():GetInventory():Iter() do
if (v.id != self.id) then
local itemTable = ix.item.instances[v.id]
for k, _ in client:GetCharacter():GetInventory():Iter() do
if (k.id != self.id) then
local itemTable = ix.item.instances[k.id]

if (!itemTable) then
client:NotifyLocalized("tellAdmin", "wid!xt")
Expand Down Expand Up @@ -287,13 +287,13 @@ end
hook.Add("PlayerDeath", "ixStripClip", function(client)
client.carryWeapons = {}

for _, v in client:GetCharacter():GetInventory():Iter() do
if (v.isWeapon and v:GetData("equip")) then
v:SetData("ammo", nil)
v:SetData("equip", nil)
for k, _ in client:GetCharacter():GetInventory():Iter() do
if (k.isWeapon and k:GetData("equip")) then
k:SetData("ammo", nil)
k:SetData("equip", nil)

if (v.pacData) then
v:RemovePAC(client)
if (k.pacData) then
k:RemovePAC(client)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions plugins/logging.lua
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ if (SERVER) then
return
end

for _, v in bagInventory:Iter() do
ix.log.Add(character:GetPlayer(), "inventoryAdd", character:GetName(), v:GetName(), v:GetID())
for k, _ in bagInventory:Iter() do
ix.log.Add(character:GetPlayer(), "inventoryAdd", character:GetName(), k:GetName(), k:GetID())
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions plugins/pac.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ if (SERVER) then
if (curChar) then
local inv = curChar:GetInventory()

for _, v in inv:Iter() do
if (v:GetData("equip") == true and v.pacData) then
client:AddPart(v.uniqueID, v)
for k, _ in inv:Iter() do
if (k:GetData("equip") == true and k.pacData) then
client:AddPart(k.uniqueID, k)
end
end
end
Expand Down Expand Up @@ -156,9 +156,9 @@ if (SERVER) then
local character = client:GetCharacter()
local inventory = character:GetInventory()

for _, v in inventory:Iter() do
if (v:GetData("equip") == true and v.pacData) then
client:AddPart(v.uniqueID, v)
for k, _ in inventory:Iter() do
if (k:GetData("equip") == true and k.pacData) then
client:AddPart(k.uniqueID, k)
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions plugins/vendor/sh_plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,11 @@ if (SERVER) then

local invOkay = true

for _, v in client:GetCharacter():GetInventory():Iter() do
if (v.uniqueID == uniqueID and v:GetID() != 0 and ix.item.instances[v:GetID()] and v:GetData("equip", false) == false) then
invOkay = v:Remove()
for k, _ in client:GetCharacter():GetInventory():Iter() do
if (k.uniqueID == uniqueID and k:GetID() != 0 and ix.item.instances[k:GetID()] and k:GetData("equip", false) == false) then
invOkay = k:Remove()
found = true
name = L(v.name, client)
name = L(k.name, client)

break
end
Expand Down

0 comments on commit e6c621c

Please sign in to comment.