I have been searching around the web for a way to check if for exaple the fish has the amount 0 then it should not be showed in DPanelList.
And also how to add a specific amount of let's say bananas without increassing the amount of all the items.
[CODE]InFridge = {}
InFridge[1] = {FridgeName = "Fish", FridgeModel = "models/props/CS_militia/fishriver01.mdl", Amount = 1}
InFridge[2] = {FridgeName = "Blue Soda", FridgeModel = "models/props_junk/PopCan01a.mdl", Amount = 1}
InFridge[3] = {FridgeName = "Milk", FridgeModel = "models/props_junk/garbage_milkcarton002a.mdl", Amount = 1}
InFridge[4] = {FridgeName = "Water Melon", FridgeModel = "models/props_junk/watermelon01.mdl", Amount = 1}
InFridge[5] = {FridgeName = "Water Bottle", FridgeModel = "models/props/cs_office/Water_bottle.mdl", Amount = 1}
InFridge[6] = {FridgeName = "Beer", FridgeModel = "models/props_junk/garbage_glassbottle003a.mdl", Amount = 1}
InFridge[7] = {FridgeName = "Chinese Takeaway", FridgeModel = "models/props_junk/garbage_takeoutcarton001a.mdl", Amount = 1}
InFridge[8] = {FridgeName = "Banana", FridgeModel = "models/weapons/w_banana.mdl", Amount = 1}[/CODE]
[QUOTE=Gastav3;45211649]I have been searching around the web for a way to check if for exaple the fish has the amount 0 then it should not be showed in DPanelList.
And also how to add a specific amount of let's say bananas without increassing the amount of all the items.
[CODE]InFridge = {}
InFridge[1] = {FridgeName = "Fish", FridgeModel = "models/props/CS_militia/fishriver01.mdl", Amount = 1}
InFridge[2] = {FridgeName = "Blue Soda", FridgeModel = "models/props_junk/PopCan01a.mdl", Amount = 1}
InFridge[3] = {FridgeName = "Milk", FridgeModel = "models/props_junk/garbage_milkcarton002a.mdl", Amount = 1}
InFridge[4] = {FridgeName = "Water Melon", FridgeModel = "models/props_junk/watermelon01.mdl", Amount = 1}
InFridge[5] = {FridgeName = "Water Bottle", FridgeModel = "models/props/cs_office/Water_bottle.mdl", Amount = 1}
InFridge[6] = {FridgeName = "Beer", FridgeModel = "models/props_junk/garbage_glassbottle003a.mdl", Amount = 1}
InFridge[7] = {FridgeName = "Chinese Takeaway", FridgeModel = "models/props_junk/garbage_takeoutcarton001a.mdl", Amount = 1}
InFridge[8] = {FridgeName = "Banana", FridgeModel = "models/weapons/w_banana.mdl", Amount = 1}[/CODE][/QUOTE]
[lua]
for i = 1, #InFridge do
if InFridge[i].Amount == 0 then
return
end
end[/lua]
I'm half asleep so bare with me, but I'm fairly sure you can check if it's 0 this way
Thanks alot.
but just one more question.
what does the "#" do?
Is it count how many tabels?
table.Count counts any table ( if keys are string, numbers, etc ), while #table only gives the number of elements which have a numerical key ( I don't recall if they needed to be sequential or not ).
[QUOTE=Acecool;45211840]table.Count counts any table ( if keys are string, numbers, etc ), while #table only gives the number of elements which have a numerical key ( I don't recall if they needed to be sequential or not ).[/QUOTE]
they do not need to be sequential
using # is better because your stuff doesnt doesnt have strings as indexes
[editline]25th June 2014[/editline]
[QUOTE=Gastav3;45211649]
And also how to add a specific amount of let's say bananas without increassing the amount of all the items.
[/QUOTE]
[lua]for i = 1, #InFridge do
if InFridge[i].FridgeName == "Banana" then
InFridge[i].Amount = Amount + 1
end
end[/lua]
This is an entity so do the entire table reset when i press E on it?
becuse it seems like it.
[QUOTE=zerothefallen;45211910]they do not need to be sequential[/QUOTE]
You'll get weird results if they aren't sequential
[QUOTE=Gastav3;45211649]I have been searching around the web for a way to check if for exaple the fish has the amount 0 then it should not be showed in DPanelList.
And also how to add a specific amount of let's say bananas without increassing the amount of all the items.
[CODE]InFridge = {}
InFridge[1] = {FridgeName = "Fish", FridgeModel = "models/props/CS_militia/fishriver01.mdl", Amount = 1}
InFridge[2] = {FridgeName = "Blue Soda", FridgeModel = "models/props_junk/PopCan01a.mdl", Amount = 1}
InFridge[3] = {FridgeName = "Milk", FridgeModel = "models/props_junk/garbage_milkcarton002a.mdl", Amount = 1}
InFridge[4] = {FridgeName = "Water Melon", FridgeModel = "models/props_junk/watermelon01.mdl", Amount = 1}
InFridge[5] = {FridgeName = "Water Bottle", FridgeModel = "models/props/cs_office/Water_bottle.mdl", Amount = 1}
InFridge[6] = {FridgeName = "Beer", FridgeModel = "models/props_junk/garbage_glassbottle003a.mdl", Amount = 1}
InFridge[7] = {FridgeName = "Chinese Takeaway", FridgeModel = "models/props_junk/garbage_takeoutcarton001a.mdl", Amount = 1}
InFridge[8] = {FridgeName = "Banana", FridgeModel = "models/weapons/w_banana.mdl", Amount = 1}[/CODE][/QUOTE]
Not sure what the goal is, but I usually prefer in pairs for use with my tables
[CODE]
for _,v in pairs(InFridge) do
if (v.FridgeName == "Banana") then
v.Amount = v.Amount + 100000
end
end
[/CODE]
Or if you need to programmatically access the Sub Table keys
[CODE]
for _,v in pairs(InFridge) do
if (v["FridgeName"] == "Banana") then
v["Amount"] = v["Amount"] + 100000
end
end
[/CODE]
Okey, I have created an fridge entity that when pressed on opens a menu with items (icons) and when clicking on them it spwns that selected item and sets the table (shown on the top) amount of that item to one less, which makes it to 0.
But when I press E on the fridge the very item that i just spawned is showed again but still has the amount 0.
Any tip how to fix this would be appreciated.
[I]Here is the full code[/I]
[url]http://pastebin.com/fY7XQias[/url]
Thank you.
Sorry, you need to Log In to post a reply to this thread.