Hello Otlands people!
i have write a code so all my chest on the server that have actionid "2000" and random unique id will be rewarded when they open the chest.
But the problem is i dont get any error in the console and it will only open the chest. I hope anyone could help me with a clean code
i have write a code so all my chest on the server that have actionid "2000" and random unique id will be rewarded when they open the chest.
But the problem is i dont get any error in the console and it will only open the chest. I hope anyone could help me with a clean code
XML:
<action actionid="2000" script="quests.lua" /> <!-- quests -->
Lua:
local quest = {
[2000] = Reward
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if quest == 2000 then
return false
end
if quest[item.actionid] then
if player:getStorageValue(quest) == 1 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'It\'s empty.')
return true
end
local chest = quest[item.actionid]
local itemType = ItemType(chest.itemid)
if itemType then
local itemWeight = itemType:getWeight()
local playerCap = player:getFreeCapacity()
if playerCap >= itemWeight then
local textm = itemType:getArticle()
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found ' .. (#textm > 0 and textm .. ' ' or '') .. itemType:getName() .. '.')
player:addItem(chest.itemid, chest.count)
player:setStorageValue(item.uid, 1)
else
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. itemType:getName() .. ' weighing ' .. itemWeight .. ' oz it\'s too heavy.')
end
end
end
return true
end