• 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!

Lua Call Multiples storages NPC

alejandro762

Well-Known Member
Joined
Sep 6, 2021
Messages
225
Reaction score
64
Hello,

on a NPC, i want to check each StorageID Value if they are completed or not, if not, player cannot complete the delivery, if all storages are 1, so the delivery it's completed and player get a reward,

I got a table like this:

Lua:
local itemsDelivery = {
['royal helmet'] = {cost = 0, items = {{2498, 1}},  storageID = 29127},
['golden helmet'] = {cost = 0, items = {{2471, 1}},  storageID = 29128},
['legion helmet'] = {cost = 0, items = {{2480, 1}},  storageID = 29129},
}

local reward= 22222

I add on npc a message that can verify if player get this storage Value completed:

Code:
 elseif msgcontains(msg, "complete") then
 if getStorageValue(cid, reward) ~= -1 then
    npcHandler:say('You have done the delivery', cid)
elseif getStorageValue(cid, reward) ~= 0 and getStorageValue(cid, XXXXXX --- itemsDelivery.StorageID ?? ) ~= 1
    npcHandler:say('You completed the delivery', cid)
    doPlayerAddItem(2160, 1)
else
    npcHandler:say('You don\'t completed the delivery', cid)
end

Where XXXXX, how we can call on table items.xxx.storageID ?
as item[msg] it works, but only for One item im stuck on how call each line storageID and check if any storage is done before the reward and if is already done.
 
Or maybe , if player get 10 storages values ( 1000, 2000, 3000 ….) completed then player get a storage value X.
How without adding each time
and
we can call all this storages ?
Bad way:
Lua:
if player:getStorageValue(1000) == 1 and player:getStorageValue(2000) == 1 and player:getStorageValue(3000) == 1 and player:getStorageValue(4000) == 1 and player:getStorageValue(5000) == 1 and ..6000 and ... 7000 .... then
player:setStorageValue(99999)
end

How many and can we add there is a limit or other way to “verify” lots of storages in easy way ?
 
Something like
Lua:
local itemsDelivery = {
  ['royal helmet'] = {cost = 0, items = {{2498, 1}},  storageID = 29127},
  ['golden helmet'] = {cost = 0, items = {{2471, 1}},  storageID = 29128},
  ['legion helmet'] = {cost = 0, items = {{2480, 1}},  storageID = 29129},
}

local hasStorages = true;
for k, v in pairs(itemsDelivery) do
  if player:getStorageValue(v.storageID) ~= 1 then
    hasStorages = false;
    break;
  end
end
if hasStorages then
  player:setStorageValue(99999)
end
 
Something like
Lua:
local itemsDelivery = {
  ['royal helmet'] = {cost = 0, items = {{2498, 1}},  storageID = 29127},
  ['golden helmet'] = {cost = 0, items = {{2471, 1}},  storageID = 29128},
  ['legion helmet'] = {cost = 0, items = {{2480, 1}},  storageID = 29129},
}

local hasStorages = true;
for k, v in pairs(itemsDelivery) do
  if player:getStorageValue(v.storageID) ~= 1 then
    hasStorages = false;
    break;
  end
end
if hasStorages then
  player:setStorageValue(99999)
end
Tried, not giving any error, but is like isn't detecting the hasStorages,

i added:
Lua:
 if hasStorages then
        npcHandler:say('Congratulations, you have completed the collection.', cid)
        setPlayerStorageValue(cid, 99999, 1)
        else
        npcHandler:say('You do not have completed the collection.', cid)
        end

And says you don't have delivered all items each time ( of course i got the 3 storages on player )

i Think it was this,
Code:
if getPlayerStorageValue(cid, v.storageID) ~= 1 then
Forget the cid, before v.storageID.
Smells working, i need to go but i will check later with different storages.

Edit, solved, to make it working we need when say 'completed' to pass check the storage of completed all deliveries before check if hasStorages.
 
Last edited:
Back
Top