mirror of
https://github.com/sr229/metastruct-experiments.git
synced 2024-09-20 06:30:36 +00:00
Add a check against duplicates
This commit is contained in:
parent
3edcb7ecb1
commit
3da9b8f7b2
1 changed files with 22 additions and 8 deletions
|
@ -16,15 +16,29 @@ function getRunningChips()
|
||||||
--exclude self
|
--exclude self
|
||||||
if v == chip() then continue end
|
if v == chip() then continue end
|
||||||
|
|
||||||
table.insert(serverMetadata.runningChips, {
|
-- check if entry already exists
|
||||||
["this"] = v,
|
if itExists(serverMetadata.runningChips, v) then
|
||||||
["chip_name"] = #v:getChipName() ~= 0 and v:getChipName() or "<none>",
|
continue
|
||||||
["chip_owner"] = v:getOwner():getName() or "<none>",
|
else
|
||||||
["chip_quota"] = math.floor(v:getQuotaAverage() * 100000)
|
table.insert(serverMetadata.runningChips, {
|
||||||
})
|
this = v,
|
||||||
|
chip_name = #v:getChipName() ~= 0 and v:getChipName() or "<none>",
|
||||||
|
chip_owner = #v:getOwner():getName() ~= 0 and v:getOwner():getName() or "<none>",
|
||||||
|
chip_quota = math.floor(v:getQuotaAverage() * 100000)
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function itExists(t, v)
|
||||||
|
for _, sv in ipairs(t) do
|
||||||
|
if sv.this == v then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
if SERVER then
|
if SERVER then
|
||||||
local prevName = ""
|
local prevName = ""
|
||||||
local prevSTime = ""
|
local prevSTime = ""
|
||||||
|
@ -67,7 +81,7 @@ if CLIENT then
|
||||||
-- update the table
|
-- update the table
|
||||||
timer.create("update", 1, 0, function()
|
timer.create("update", 1, 0, function()
|
||||||
for i, v in ipairs(serverMetadata.runningChips) do
|
for i, v in ipairs(serverMetadata.runningChips) do
|
||||||
local ent = v["this"]
|
local ent = v.this
|
||||||
v.chip_quota = math.floor(ent:getQuotaAverage() * 100000)
|
v.chip_quota = math.floor(ent:getQuotaAverage() * 100000)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
@ -92,7 +106,7 @@ if CLIENT then
|
||||||
end
|
end
|
||||||
|
|
||||||
for i, v in ipairs(serverMetadata.runningChips) do
|
for i, v in ipairs(serverMetadata.runningChips) do
|
||||||
render.drawText(10, 130 + (i * 20), "" .. v["chip_name"] .. " by " .. v["chip_owner"] .. " (" .. v["chip_quota"] .. "us)")
|
render.drawText(10, 130 + (i * 20), "" .. v.chip_name .. " by " .. v.chip_owner .. " (" .. v.chip_quota .. "us)")
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
Loading…
Reference in a new issue