• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Addon Doll (Random Outfits)

Maziajka

Excellent OT User
Joined
Mar 4, 2009
Messages
1,711
Reaction score
618
Location
Hamburg
Hi everyone,

I've downloaded the Addon Doll script for random outfits/addons from OpenTibiaBR (Actions | OpenTibiaBR (https://docs.opentibiabr.com/opentibiabr/downloads/revscripts/actions)). I've modified the script so that it always grants the full outfit instead of randomly giving just one addon or the second.

However, the issue I'm facing is that the Addon Doll still gets consumed and grants outfits/addons even if the player already owns them. I am using the latest Canary version.. anyone know's how to make it work so it does not gives the same outfit twice and does not consume the doll instead gives a message like "You already own this outfit" or so? (I removed most outfits from the list otherwise it's maybe too long to read)

script:


--local actionId = 8221
local itemDollId = 40964
local outfits = {
{136, 128, "Citizen"},
{137, 129, "Hunter"},
{138, 130, "Mage"},
{1271, 1270, "Poltergeist"},
{1280, 1279, "Herder"},
{1283, 1282, "Falconer"},
{1676, 1675, "Darklight Evoker"},
{1681, 1680, "Flamefury Mage"},
{1714, 1713, "Doom Knight"},
{1723, 1722, "Draccoon Herald"},
{1726, 1725, "Celestial Avenger"},
{1746, 1745, "Blade Dancer"},
{1775, 1774, "Rootwalker"},
{1777, 1776, "Beekeeper"},
{1808, 1809, "Fiend Slayer"},
}

local randOutfit = Action("RandomOutfitForNewPlayers")

-- Strict check for full ownership of both genders and both addons
local function hasFullOutfit(player, male, female)
return player:hasOutfit(male, 1) and player:hasOutfit(male, 2)
and player:hasOutfit(female, 1) and player:hasOutfit(female, 2)
end

local function grantFullOutfit(player, male, female)
for addon = 1, 2 do
player:addOutfitAddon(male, addon)
player:addOutfitAddon(female, addon)
end
end

function randOutfit.onUse(player, item, fromPosition, target, toPosition, isHotkey)
-- Sanity check: prevent multiple actions affecting this item
if item:getId() ~= itemDollId then
player:sendTextMessage(MESSAGE_STATUS_SMALL, "This item is not configured correctly.")
return true
end

-- Filter list of unowned outfits
local unowned = {}
for _, outfit in ipairs(outfits) do
if not hasFullOutfit(player, outfit[1], outfit[2]) then
table.insert(unowned, outfit)
end
end

if #unowned == 0 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You already own all available outfits with both addons.")
return true -- Don't consume item
end

local chosen = unowned[math.random(#unowned)]
local male, female, name = chosen[1], chosen[2], chosen[3]

grantFullOutfit(player, male, female)

player:sendTextMessage(MESSAGE_EVENT_ADVANCE,
string.format("You obtained the full %s outfit with both addons!", name))

item:remove(1)
return true
end

randOutfit:id(itemDollId)
randOutfit:register()
 
try this
LUA:
local actionId = 8221
local itemDollId = 40964

local outfits = {
    {136, 128, "Citizen"},
    {137, 129, "Hunter"},
    {138, 130, "Mage"},
    {1271, 1270, "Poltergeist"},
    {1280, 1279, "Herder"},
    {1283, 1282, "Falconer"},
    {1676, 1675, "Darklight Evoker"},
    {1681, 1680, "Flamefury Mage"},
    {1714, 1713, "Doom Knight"},
    {1723, 1722, "Draccoon Herald"},
    {1726, 1725, "Celestial Avenger"},
    {1746, 1745, "Blade Dancer"},
    {1775, 1774, "Rootwalker"},
    {1777, 1776, "Beekeeper"},
    {1808, 1809, "Fiend Slayer"},
}

local randOutfit = Action("RandomOutfitForNewPlayers")

-- Full ownership: both genders, both addons
local function hasFullOutfit(player, male, female)
    return player:hasOutfit(male, 1) and player:hasOutfit(male, 2)
       and player:hasOutfit(female, 1) and player:hasOutfit(female, 2)
end

-- Has any part of outfit (any addon on either gender)
local function hasAnyOutfitAddon(player, male, female)
    for addon = 1, 2 do
        if player:hasOutfit(male, addon) or player:hasOutfit(female, addon) then
            return true
        end
    end
    return false
end

-- Grant both addons to both genders
local function grantFullOutfit(player, male, female)
    for addon = 1, 2 do
        player:addOutfitAddon(male, addon)
        player:addOutfitAddon(female, addon)
    end
end

function randOutfit.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item:getId() ~= itemDollId then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "This item is not configured correctly.")
        return true
    end

    local unowned = {}
    for _, outfit in ipairs(outfits) do
        if not hasFullOutfit(player, outfit[1], outfit[2]) then
            table.insert(unowned, outfit)
        end
    end

    if #unowned == 0 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You already own all available outfits with both addons.")
        return true
    end

    local chosen = unowned[math.random(#unowned)]
    local male, female, name = chosen[1], chosen[2], chosen[3]

    if hasAnyOutfitAddon(player, male, female) then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You already have this addon.")
        return true -- Don't consume item
    end

    grantFullOutfit(player, male, female)

    player:sendTextMessage(MESSAGE_EVENT_ADVANCE,
        string.format("You obtained the full %s outfit with both addons!", name))

    item:remove(1)
    return true
end

randOutfit:id(itemDollId)
randOutfit:register()
 
try this
LUA:
local actionId = 8221
local itemDollId = 40964

local outfits = {
    {136, 128, "Citizen"},
    {137, 129, "Hunter"},
    {138, 130, "Mage"},
    {1271, 1270, "Poltergeist"},
    {1280, 1279, "Herder"},
    {1283, 1282, "Falconer"},
    {1676, 1675, "Darklight Evoker"},
    {1681, 1680, "Flamefury Mage"},
    {1714, 1713, "Doom Knight"},
    {1723, 1722, "Draccoon Herald"},
    {1726, 1725, "Celestial Avenger"},
    {1746, 1745, "Blade Dancer"},
    {1775, 1774, "Rootwalker"},
    {1777, 1776, "Beekeeper"},
    {1808, 1809, "Fiend Slayer"},
}

local randOutfit = Action("RandomOutfitForNewPlayers")

-- Full ownership: both genders, both addons
local function hasFullOutfit(player, male, female)
    return player:hasOutfit(male, 1) and player:hasOutfit(male, 2)
       and player:hasOutfit(female, 1) and player:hasOutfit(female, 2)
end

-- Has any part of outfit (any addon on either gender)
local function hasAnyOutfitAddon(player, male, female)
    for addon = 1, 2 do
        if player:hasOutfit(male, addon) or player:hasOutfit(female, addon) then
            return true
        end
    end
    return false
end

-- Grant both addons to both genders
local function grantFullOutfit(player, male, female)
    for addon = 1, 2 do
        player:addOutfitAddon(male, addon)
        player:addOutfitAddon(female, addon)
    end
end

function randOutfit.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item:getId() ~= itemDollId then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "This item is not configured correctly.")
        return true
    end

    local unowned = {}
    for _, outfit in ipairs(outfits) do
        if not hasFullOutfit(player, outfit[1], outfit[2]) then
            table.insert(unowned, outfit)
        end
    end

    if #unowned == 0 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You already own all available outfits with both addons.")
        return true
    end

    local chosen = unowned[math.random(#unowned)]
    local male, female, name = chosen[1], chosen[2], chosen[3]

    if hasAnyOutfitAddon(player, male, female) then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You already have this addon.")
        return true -- Don't consume item
    end

    grantFullOutfit(player, male, female)

    player:sendTextMessage(MESSAGE_EVENT_ADVANCE,
        string.format("You obtained the full %s outfit with both addons!", name))

    item:remove(1)
    return true
end

randOutfit:id(itemDollId)
randOutfit:register()

Works perfect! Thank you so much
 

Similar threads

Back
Top