• 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!

[LUA] [8.6] Addon Doll

Demnish

Tibian Hero
Joined
Sep 28, 2011
Messages
402
Solutions
2
Reaction score
65
Location
Sweden
SOLVED & FINISHED
Please move this to Resources/Talkactions.

Distro:
OTServ 0.6.4 STABLE
Client: 8.6

What?:
Improved Addon Doll (Talkaction)
Made by Xeraphus.
MYJspEE.png


How To Use?:
!addon <name of the outfit>

Scripts:
addon.lua (..\<your distro>\data\talkactions\scripts\custom)
Code:
local ADDON_DOLL = 9693 --ID of Addon Doll

local outfits = {
    [0] = {
        ["citizen"] = 136,
        ["hunter"] = 137,
        ["mage"] = 138,
        ["knight"] = 139,
        ["nobleman"] = 140,
        ["summoner"] = 141,
        ["warrior"] = 142,
        ["barbarian"] = 147,
        ["druid"] = 148,
        ["wizard"] = 149,
        ["oriental"] = 150,
        ["pirate"] = 155,
        ["assassin"] = 156,
        ["beggar"] = 157,
        ["shaman"] = 158,
        ["norsewoman"] = 252,
        ["nightmare"] = 269,
        ["jester"] = 270,
        ["brotherhood"] = 279,
        ["demonhunter"] = 288,
        ["yalaharian"] = 324
    },
    [1] = {
        ["citizen"] = 128,
        ["hunter"] = 129,
        ["mage"] = 130,
        ["knight"] = 131,
        ["nobleman"] = 132,
        ["summoner"] = 133,
        ["warrior"] = 134,
        ["barbarian"] = 143,
        ["druid"] = 144,
        ["wizard"] = 145,
        ["oriental"] = 146,
        ["pirate"] = 151,
        ["assassin"] = 152,
        ["beggar"] = 153,
        ["shaman"] = 154,
        ["norsewoman"] = 251,
        ["nightmare"] = 268,
        ["jester"] = 273,
        ["brotherhood"] = 278,
        ["demonhunter"] = 289,
        ["yalaharian"] = 325
    }
}

local msg = {
    success = "Full addon set successfully added!",
    invalidParam = "Command requires a valid parameter.",
    hasAddons = "You already have the addons for this outfit.",
    needDoll = "You do not have an addon doll.",
    invalidOutfit = "You must put a valid outfit name."
}

function onSay(cid, words, param)
    local param = string.lower(param)

    if (param == "") then
        return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg.invalidParam)
    end

    if (getPlayerItemCount(cid, ADDON_DOLL) == 0) then
        return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg.needDoll)
    end

    local outfit = outfits[getPlayerSex(cid)][param]
    if not outfit then
        return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg.invalidOutfit)
    end

    if (canPlayerWearOutfit(cid, outfit, 3)) then
        return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg.hasAddons)
    end

    doPlayerRemoveItem(cid, ADDON_DOLL, 1)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg.success)
    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_GIFT_WRAPS)
    doPlayerAddOutfit(cid, outfit, 3)
    return true
end

talkactions.xml (..\<your distro>\data\talkactions)
Code:
<talkaction words="!addon" filter="first word" script="custom/addon.lua"/>
 
Last edited:
Solution
try this:
Lua:
local outfits = {
    [0] = {
        ["citizen"] = 136,
        ["hunter"] = 137,
        ["mage"] = 138,
        ["knight"] = 139,
        ["nobleman"] = 140,
        ["summoner"] = 141,
        ["warrior"] = 142,
        ["barbarian"] = 147,
        ["druid"] = 148,
        ["wizard"] = 149,
        ["oriental"] = 150,
        ["pirate"] = 155,
        ["assassin"] = 156,
        ["beggar"] = 157,
        ["shaman"] = 158,
        ["norsewoman"] = 252,
        ["nightmare"] = 269,
        ["jester"] = 270,
        ["brotherhood"] = 279,
        ["demonhunter"] = 288,
        ["yalaharian"] = 324
    },
    [1] = {
        ["citizen"] = 128,
        ["hunter"] = 129,
        ["mage"] = 130,
        ["knight"] = 131...
Changed the code but couldn't get it to work.

The added code is in line 8 and 17-19:
Code:
function onSay(cid, words, param)
    local femaleOutfits = { ["citizen"]={136}, ["hunter"]={137}, ["mage"]={138}, ["knight"]={139}, ["nobleman"]={140}, ["summoner"]={141}, ["warrior"]={142}, ["barbarian"]={147}, ["druid"]={148}, ["wizard"]={149}, ["oriental"]={150}, ["pirate"]={155}, ["assassin"]={156}, ["beggar"]={157}, ["shaman"]={158}, ["norsewoman"]={252}, ["nightmare"]={269}, ["jester"]={270}, ["brotherhood"]={279}, ["demonhunter"]={288}, ["yalaharian"]={324} }
    local maleOutfits = { ["citizen"]={128}, ["hunter"]={129}, ["mage"]={130}, ["knight"]={131}, ["nobleman"]={132},["summoner"]={133}, ["warrior"]={134}, ["barbarian"]={143}, ["druid"]={144}, ["wizard"]={145}, ["oriental"]={146}, ["pirate"]={151}, ["assassin"]={152}, ["beggar"]={153}, ["shaman"]={154}, ["norsewoman"]={251}, ["nightmare"]={268}, ["jester"]={273}, ["brotherhood"]={278}, ["demonhunter"]={289}, ["yalaharian"]={325} }
    local msg = {"Full addon set successfully added!", "You already have the addons for this outfit.", "Command requires a valid parameter.", "You do not have an addon doll."}
    local param = string.lower(param)
    if(getPlayerItemCount(cid, 9693) > 0) then
        if(param ~= "" and maleOutfits[param] and femaleOutfits[param]) then
            if(canPlayerWearOutfit(cid, femaleOutfits[param][1], 3)) or (canPlayerWearOutfit(cid, maleOutfits[param][1], 3)) then
                doPlayerRemoveItem(cid, 9693, 1)
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg[1])
                doSendMagicEffect(getCreaturePosition(cid), CONST_ME_GIFT_WRAPS)
                if(getPlayerSex(cid) == 0)then
                    doPlayerAddOutfit(cid, femaleOutfits[param][1], 3)
                else
                    doPlayerAddOutfit(cid, maleOutfits[param][1], 3)
                end
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg[2])
            end
        else
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg[3])
        end
    else
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg[4])
    end
end

This is what is said ingame:
15:04 You do not have an addon doll. //Didn't have an addon doll, so the first part worked.
15:04 Tester [8]: !addon

15:04 Command requires a valid parameter. //Tried to call the function, so the second part worked.
15:04 Tester [8]: !addon test

15:04 You already have the addons for this outfit. //Tried to add the addons normally, this part did not work. (It should've given me the addons and send me msg[1])
15:04 Tester [8]: !addon citizen

No errors in the console either.
 
Last edited:
try this:
Lua:
local outfits = {
    [0] = {
        ["citizen"] = 136,
        ["hunter"] = 137,
        ["mage"] = 138,
        ["knight"] = 139,
        ["nobleman"] = 140,
        ["summoner"] = 141,
        ["warrior"] = 142,
        ["barbarian"] = 147,
        ["druid"] = 148,
        ["wizard"] = 149,
        ["oriental"] = 150,
        ["pirate"] = 155,
        ["assassin"] = 156,
        ["beggar"] = 157,
        ["shaman"] = 158,
        ["norsewoman"] = 252,
        ["nightmare"] = 269,
        ["jester"] = 270,
        ["brotherhood"] = 279,
        ["demonhunter"] = 288,
        ["yalaharian"] = 324
    },
    [1] = {
        ["citizen"] = 128,
        ["hunter"] = 129,
        ["mage"] = 130,
        ["knight"] = 131,
        ["nobleman"] = 132,
        ["summoner"] = 133,
        ["warrior"] = 134,
        ["barbarian"] = 143,
        ["druid"] = 144,
        ["wizard"] = 145,
        ["oriental"] = 146,
        ["pirate"] = 151,
        ["assassin"] = 152,
        ["beggar"] = 153,
        ["shaman"] = 154,
        ["norsewoman"] = 251,
        ["nightmare"] = 268,
        ["jester"] = 273,
        ["brotherhood"] = 278,
        ["demonhunter"] = 289,
        ["yalaharian"] = 325
    }
}

local msg = {
    success = "Full addon set successfully added!",
    invalidParam = "Command requires a valid parameter.",
    hasAddons = "You already have the addons for this outfit.",
    needDoll = "You do not have an addon doll.",
    invalidOutfit = "You must put a valid outfit name."
}

function onSay(cid, words, param)
    local param = string.lower(param)

    if (param == "") then
        return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg.invalidParam)
    end

    if (getPlayerItemCount(cid, 9693) == 0) then
        return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg.needDoll)
    end

    local outfit = outfits[getPlayerSex(cid)][param]
    if not outfit then
        return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg.invalidOutfit)
    end

    if (canPlayerWearOutfit(cid, outfit, 3)) then
        return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg.hasAddons)
    end

    doPlayerRemoveItem(cid, 9693, 1)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg.success)
    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_GIFT_WRAPS)
    doPlayerAddOutfit(cid, outfit, 3)
    return true
end
 
Last edited:
Solution
Fixed it.
Updated my main post with the working code.

I'm kinda happy that all I had was "canPlayerWearOutfit(cid, looktype, addons)" from Xikini and I managed to fix it, I guess I took a step away from noob today.

Now I'm going to try to add so that you can't get addons if you don't have the outfit unlocked.
Lets hope I can keep this up!


Thanks for the support guys. :)
 
Last edited:
I fixed it.
This is the final code:
Code:
function onSay(cid, words, param)

    local femaleOutfits = { ["citizen"]={136}, ["hunter"]={137}, ["mage"]={138}, ["knight"]={139}, ["nobleman"]={140}, ["summoner"]={141}, ["warrior"]={142}, ["barbarian"]={147}, ["druid"]={148}, ["wizard"]={149}, ["oriental"]={150}, ["pirate"]={155}, ["assassin"]={156}, ["beggar"]={157}, ["shaman"]={158}, ["norsewoman"]={252}, ["nightmare"]={269}, ["jester"]={270}, ["brotherhood"]={279}, ["demonhunter"]={288}, ["yalaharian"]={324} }
    local maleOutfits = { ["citizen"]={128}, ["hunter"]={129}, ["mage"]={130}, ["knight"]={131}, ["nobleman"]={132},["summoner"]={133}, ["warrior"]={134}, ["barbarian"]={143}, ["druid"]={144}, ["wizard"]={145}, ["oriental"]={146}, ["pirate"]={151}, ["assassin"]={152}, ["beggar"]={153}, ["shaman"]={154}, ["norsewoman"]={251}, ["nightmare"]={268}, ["jester"]={273}, ["brotherhood"]={278}, ["demonhunter"]={289}, ["yalaharian"]={325} }
    local msg = {"You already have the addons for this outfit.", "Full addon set successfully added!", "Command requires a valid parameter.", "You do not have an addon doll."}
    local param = string.lower(param)
 
 
    if(getPlayerItemCount(cid, 9693) > 0) then
        if(param ~= "" and maleOutfits[param] and femaleOutfits[param]) then
            if(canPlayerWearOutfit(cid, femaleOutfits[param][1], 3)) or (canPlayerWearOutfit(cid, maleOutfits[param][1], 3)) then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg[1])
            else
                doPlayerRemoveItem(cid, 9693, 1)
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg[2])
                doSendMagicEffect(getCreaturePosition(cid), CONST_ME_GIFT_WRAPS)
                if(getPlayerSex(cid) == 0)then
                    doPlayerAddOutfit(cid, femaleOutfits[param][1], 3)
                else
                    doPlayerAddOutfit(cid, maleOutfits[param][1], 3)
                end
            end
        else
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg[3])
        end
    else
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg[4])
    end
end

I'm kinda happy that all I had was "canPlayerWearOutfit" from Xikini and I managed to fix it, I guess I took a step away from noob today.

Now I'm going to try to add so that you can't get addons if you don't have the outfit unlocked.
Lets hope I can keep this up! :)
the code i gave (should) be more readable and a better way to define outfit & message tables
you can define the tables once outside of the function, instead of letting the script redefine them every time someone uses the command
splitting the if statements lets you keep track of what's going on rather than having big wall of if/else statements
 
Thanks for the tips, I will try to keep code clean in the future!
Your code is indeed easier to read, change and understand.

Anyway, I get this when using it while not having the addons:
16:08 You already have the addons for this outfit.
16:08 Tester [8]: !addon citizen

Feels like the same problem I had the first time I changed the one I use.
I'll see if I can fix it! :)

EDIT:
I can't seem to be able to fix it, but I have a feeling it gets stuck somewhere in here:

Code:
    local outfit = outfits[getPlayerSex(cid)][param]
    if not outfit then
        return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg.invalidOutfit)
    end

    if not (canPlayerWearOutfit(cid, outfit, 3)) then
        return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg.hasAddons)
    end

    doPlayerRemoveItem(cid, ADDON_DOLL, 1)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg.success)
    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_GIFT_WRAPS)
    doPlayerAddOutfit(cid, outfit, 3)
    return true

Since the first 2 parts works, I imagine this section must contain an error of some kind.
Though in my eyes, it looks like it should work.
 
Last edited:
Thanks for the tips, I will try to keep code clean in the future!
Your code is indeed easier to read, change and understand.

Anyway, I get this when using it while not having the addons:


Feels like the same problem I had the first time I changed the one I use.
I'll see if I can fix it! :)

EDIT:
I can't seem to be able to fix it, but I have a feeling it gets stuck somewhere in here:

Code:
    local outfit = outfits[getPlayerSex(cid)][param]
    if not outfit then
        return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg.invalidOutfit)
    end

    if not (canPlayerWearOutfit(cid, outfit, 3)) then
        return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg.hasAddons)
    end

    doPlayerRemoveItem(cid, ADDON_DOLL, 1)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg.success)
    DoSend magic effect (getCreaturePosition (cid), CONST_ME_GIFT_WRAPS)
    doPlayerAddOutfit(cid, outfit, 3)
    return true

Since the first 2 parts works, I imagine this section must contain an error of some kind.
Though in my eyes, it looks like it should work.
my bad, change
Lua:
if not (canPlayerWearOutfit(cid, outfit, 3)) then
to
Lua:
if (canPlayerWearOutfit(cid, outfit, 3)) then
 
For me dont work in tfs 1.2
when i write !addon then i see
"Command requires a valid parameter"
when i press a !addon hunter or !addon citizen then nothing....
 
Back
Top