The script it doesnt work
Players receive rewards based on their vocation.
Players of vocation 4 and 8 must choose between sword, axe, or club before opening the chest.
Rewards are given inside a backpack.
The script prevents duplicate rewards and ensures inventory space.
The !choose command allows players to select a weapon before claiming the
Players receive rewards based on their vocation.
Players of vocation 4 and 8 must choose between sword, axe, or club before opening the chest.
Rewards are given inside a backpack.
The script prevents duplicate rewards and ensures inventory space.
The !choose command allows players to select a weapon before claiming the
LUA:
local actionId = 2945
local storageKey = 14021 + actionId
local weaponStorageKey = storageKey + 1
local backpackId = 1990
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if item:getActionId() ~= actionId then
return false
end
if player:getStorageValue(storageKey) == 1 then
player:sendTextMessage(MESSAGE_INFO_DESCR, "The chest is empty.")
return true
end
local vocationId = player:getVocation():getId()
local rewardItems = {}
if vocationId == 1 or vocationId == 2 or vocationId == 5 or vocationId == 6 then
table.insert(rewardItems, 12774)
elseif vocationId == 3 or vocationId == 7 then
table.insert(rewardItems, 12806)
table.insert(rewardItems, 12807)
elseif vocationId == 4 or vocationId == 8 then
local chosenWeapon = player:getStorageValue(weaponStorageKey)
if chosenWeapon == -1 then
player:sendTextMessage(MESSAGE_INFO_DESCR, "Use !choose sword, axe, or club before opening the chest.")
return true
else
table.insert(rewardItems, chosenWeapon)
end
end
local backpack = player:addItem(backpackId, 1, true)
if not backpack then
player:sendTextMessage(MESSAGE_INFO_DESCR, "Your inventory is full. Make space and try again.")
return true
end
for _, itemId in ipairs(rewardItems) do
backpack:addItem(itemId, 1)
end
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have received your reward!")
player:setStorageValue(storageKey, 1)
return true
end
function onSay(player, words, param)
local weaponRewards = {
sword = 12794,
axe = 12808,
club = 12805
}
local chosenWeapon = weaponRewards[param:lower()]
if chosenWeapon then
player:setStorageValue(weaponStorageKey, chosenWeapon)
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have chosen " .. param .. " as your weapon.")
return true
else
player:sendTextMessage(MESSAGE_INFO_DESCR, "Invalid choice. Use !choose sword, axe, or club.")
return false
end
end
local chooseCommand = TalkAction("!choose")
chooseCommand.onSay = onSay
chooseCommand:register()