• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Script that checks items and it counts.

Swiftxd

Member
Joined
Apr 5, 2014
Messages
85
Reaction score
5
Hey, i have a question, if i uses a item in a item2, how can i made it gives more than 1 item, like, check every item and its counts. Heres an Example:
Code:
config = {
[item] = {loot={{1145, 5},{8181, 1},{1273, 8}}, level=5, xp=5}
}
i need check how much itens have on loot and then uses doPlayerAddItem(cid, loot[1], loot[2]) get it ?
but i dont want to make 100 ifs, or make 3 doPlayerAddItem function, how can i do that ?
 
Solution
Try again, cant understand you.

Maybe this?
Code:
local items = config[item.itemid].loot
for i = 1, #items do
    doPlayerAddItem(cid, items[i][1], items[i][2])
end
Try again, cant understand you.

Maybe this?
Code:
local items = config[item.itemid].loot
for i = 1, #items do
    doPlayerAddItem(cid, items[i][1], items[i][2])
end
 
Solution
In the Opening post example we cant use ipairs() because ipairs starts from 1..2..3..4..5 etc.
if you use itemID as the key then it quite frankly cant start from 1 and more over have a secuence.

for i=1, #table do
also is bad solution, its almost same as ipairs

the only option here is: for k, v in pairs() do If we use the configuration file given by opening post.

And as much as I understood, he wants double loop trough. trough config and loot table.
 
In the Opening post example we cant use ipairs() because ipairs starts from 1..2..3..4..5 etc.
if you use itemID as the key then it quite frankly cant start from 1 and more over have a secuence.

for i=1, #table do
also is bad solution, its almost same as ipairs

the only option here is: for k, v in pairs() do If we use the configuration file given by opening post.

And as much as I understood, he wants double loop trough. trough config and loot table.
You don't have to loop through the config table if he already has the "key" that he is looking for that is an itemid.

You just have to do:
local items = config[item.itemid].loot
Ofc you should check before if config[item.itemid] exists depending on what you are doing.

And this table starts from 1..2..3..4..5 etc.
 
Last edited:
Sorry guys, I have been busy in the last days, and sorry for bad grammar.
here's the code:
Code:
local reward = config[item].loot
        for i, v in ipairs(reward) do
                doPlayerAddItem(cid, reward[i][1], math.random(0,reward[i][2]+(getEnchantingSkill(cid)*0.03)) or 1)
        end
the question was how i can add more than one item in a single function, but i found it by myself, yamaken was right. Thanks.
 
Back
Top