local config = {
lever = 18563,
pricePos = { x = 653, y = 734, z = 7 },
addonName = { "first", "second" },
outfits = {
[50002] = {
items = {
{ id = 5890, count = 100 }
},
outfit = {
[PLAYERSEX_FEMALE] = 136,
[PLAYERSEX_MALE] = 128,
},
addon = 1
}
-- Add more outfits as needed
}
}
local action = Action()
local removePrice = function(tile, items)
local tileItems = tile:getItems()
local itemFound = false
for _, item in ipairs(items) do
local count = item.count or 1
itemFound = false
for _, tileItem in ipairs(tileItems) do
if tileItem:getId() == item.id and count > 0 then
local removeCount = math.min(count, tileItem:getCount())
count = count - removeCount
tileItem:remove(removeCount)
itemFound = true
end
end
if not itemFound then
print("Item not found:", item.id)
return false
end
end
return true
end
local checkPrice = function(tile, items)
local countMap = {}
for _, item in ipairs(items) do
local tileCount = countMap[item.id] or tile:getItemCountById(item.id)
local count = item.count or 1
if tileCount < count then
return false
end
countMap[item.id] = tileCount - count
end
return true
end
function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if item.actionid then
local priceTile = Tile(config.pricePos)
if not priceTile then
print("Error: Unable to create priceTile")
return false
end
if not player:isPremium() then
player:sendTextMessage(MESSAGE_INFO_DESCR, "Sorry, only premium players may use addon lever.")
return true
end
for sId, o in pairs(config.outfits) do
local hasOutfit = player:getStorageValue(sId) > 0
if not hasOutfit and checkPrice(priceTile, o.items) then
if removePrice(priceTile, o.items) then
local lookType = o.outfit[player:getSex()]
if lookType then
local outfit = Outfit(lookType)
outfit.lookAddons = o.addon or 1
local addonName = config.addonName[outfit.lookAddons] or ""
priceTile:getPosition():sendMagicEffect(CONST_ME_HITBYFIRE)
player:setStorageValue(sId, 1)
player:addOutfitAddon(lookType, outfit.lookAddons)
player:sendTextMessage(MESSAGE_INFO_DESCR, ("You have unlocked the addon %s %s!"):format(addonName, outfit.name))
return true
end
else
player:say("You don't have the necessary items!", TALKTYPE_ORANGE_1, false, player, priceTile:getPosition())
return true
end
end
end
player:say("You do not have the necessary items or you already have this addon!", TALKTYPE_ORANGE_1, false, player, priceTile:getPosition())
return true
end
return false
end
action:aid(config.lever)
action:register()