local ITEM_ID = 5890
local MAX_COUNT = 100
local config = {
pricePos = { x = 734, y = 595, z = 6 },
addonName = { "first", "second" }
}
local PLAYERSEX_FEMALE = 0
local PLAYERSEX_MALE = 1
local outfits = {
[80001] = {
items = {
{ id = ITEM_ID, count = MAX_COUNT }
},
outfit = {
[PLAYERSEX_FEMALE] = 136,
[PLAYERSEX_MALE] = 128,
},
addon = 1
}
}
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
if count <= MAX_COUNT then
local tileItem = tile:getItemById(item.id, count)
if tileItem then
tileItem:remove()
itemFound = true
end
else
local remainingCount = count
repeat
local tileItem = tile:getItemById(item.id)
if tileItem then
local removeCount = math.min(remainingCount, tileItem:getCount())
tileItem:remove(removeCount)
remainingCount = remainingCount - removeCount
else
break
end
until remainingCount <= 0
if remainingCount > 0 then
print("Item not found:", item.id)
return false
end
itemFound = true
end
if not itemFound then
print("Item not found:", item.id)
return false
end
end
return true
end
local checkPrice = function(tile, items)
if not tile then
return false
end
for _, item in ipairs(items) do
local count = item.count or 1
if not tile:getItemById(item.id, count) then
return false
end
end
return true
end
local action = Action()
function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if not player or not item then
return false
end
if not player:isPremium() then
player:sendTextMessage(MESSAGE_INFO_DESCR, "Sorry, only premium players may use addon lever.")
return true
end
local sex = player:getSex()
local pricePos = config.pricePos
local priceTile = Tile(pricePos)
for sId, o in pairs(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[sex]
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 %s %s addon!"):format(addonName, outfit.name))
return true
end
else
player:say("You don't have the required items!", TALKTYPE_ORANGE_1, false, player, priceTile:getPosition())
return true
end
end
end
player:say("You have already unlocked this addon!", TALKTYPE_ORANGE_1, false, player, priceTile:getPosition())
return true
end
action:aid(18563)
action:register()