Hey, trying to create a quest script which gives multiple items from one chest but at the same time a character can get rewards from only one of eg. four chests.
The player gets the first item from the list and that's it.
tried to put it in one table, eg:
or
Then the player gets only the last item from the table. Any solutions?
The player gets the first item from the list and that's it.
Lua:
--[[
inquistion-style chests.
This script goes into data/scripts as a .lua file
1) Place 2+ chests into map editor
2) Place Same ActionId onto all chests. (example: 45000)
3) Place UniqueId onto all chests. (example: 45001, 45002, 45003...)
4) Update config table here, to match the chests in map editor (ActionId, UniqueId's)
5) Update table with itemId's, count's and an unused storage number
6) Restart Server, and test
]]--
local rewardChests = {
----[actionId] = {
---- [uniqueId] = {itemId = ####, count = #},
---- [uniqueId] = {itemId = ####, count = #},
---- [uniqueId] = {itemId = ####, count = #},
---- [uniqueId] = {itemId = ####, count = #},
---- storage = #####
----},
[17440] = {
[27440] = {itemId = 2323, count = 1}, {itemId = 8870, count = 1}, {itemId = 8900, count = 1}, {itemId = 2187, count = 1},
[27441] = {itemId = 2323, count = 1}, {itemId = 8870, count = 1}, {itemId = 8900, count = 1}, {itemId = 2183, count = 1},
[27442] = {itemId = 2491, count = 1}, {itemId = 2515, count = 1}, {itemId = 2664, count = 1}, {itemId = 7438, count = 1},
[27443] = {itemId = 2491, count = 1}, {itemId = 2515, count = 1}, {itemId = 2486, count = 1}, {itemId = 2438, count = 1}, {itemId = 3962, count = 1}, {itemId = 7437, count = 1},
storage = 17440
},
}
local yala_style_chest = Action()
function yala_style_chest.onUse(player, item, fromPosition, target, toPosition, isHotkey)
local index = rewardChests[item:getActionId()][item:getUniqueId()]
if not index then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Inform gamemaster of error with quest.")
print("Error: UniqueId does not exist in table.")
return true
end
print("Checking storage..")
print(index.storage)
print(player:getStorageValue(index.storage))
if player:getStorageValue(index.storage) == 1 then
print("Player storage == 1. Quest has been completed before.")
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "It is empty.")
return true
end
print("Player storage ~= 1. Continuing..")
local reward = ItemType(index.itemId)
local rewardWeight = reward:getWeight() * index.count
if rewardWeight > player:getFreeCapacity() then
print("Player does not have enough free capacity. No reward or storage given.")
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a " .. reward:getName() .. " weighing " .. rewardWeight .. " oz. It's too heavy.")
return true
end
print("Player storage updated to 1. Reward given.")
player:addItem(index.itemId, index.count, true)
player:setStorageValue(index.storage, 1)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a " .. reward:getName() .. ".")
return true
end
for v, k in pairs(rewardChests) do
yala_style_chest:aid(v)
end
yala_style_chest:register()
tried to put it in one table, eg:
Code:
{itemId = 2491, count = 1, itemId = 2515, count = 1, itemId = 2486, count = 1, itemId = 2438, count = 1, itemId = 3962, count = 1, itemId = 7437, count = 1},
Code:
{itemId = 2491, count = 1; itemId = 2515, count = 1; itemId = 2486, count = 1; itemId = 2438, count = 1; itemId = 3962, count = 1; itemId = 7437, count = 1},
Then the player gets only the last item from the table. Any solutions?