• 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 Click item get promoted problem

Heroid

Active Member
Joined
Mar 7, 2011
Messages
330
Solutions
11
Reaction score
34
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local outfits = {
    [1] = {male = 145, female = 149}, --
    [2] = {male = 725, female = 724}, --
    [3] = {male = 129, female = 137}, --
    [4] = {male = 131, female = 139}, --
    }
local voc = player:getVocation():getId()
local pVoc = getPlayerVocation(player)
local outfit = player:getOutfit()

   for k in pairs(outfits) do
        if k == pVoc then
            if voc <= 8 and voc >= 5 and player:getSex() == PLAYERSEX_FEMALE then
                player:addOutfitAddon(outfits[k].female, 2)
                player:setOutfit({lookType = outfits[k].female, lookHead = outfit.lookHead, lookBody= outfit.lookBody, lookLegs = outfit.lookLegs, lookFeet= outfit.lookFeet, lookAddons = 2})
                item:remove(1)
                player:setVocation(voc+4)
                player:sendTextMessage(MESSAGE_INFO_DESCR, "You have been promoted to a " .. player:getVocation():getName() .. "!")
                player:getPosition():sendMagicEffect(27)
            elseif voc >= 5 and voc <= 8 and player:getSex() == PLAYERSEX_MALE then
                player:addOutfitAddon(outfits[k].male, 2)
                player:setOutfit({lookType = outfits[k].male, lookHead = outfit.lookHead, lookBody= outfit.lookBody, lookLegs = outfit.lookLegs, lookFeet= outfit.lookFeet, lookAddons = 2})
                item:remove(1)
                player:setVocation(voc+4)
                player:sendTextMessage(MESSAGE_INFO_DESCR, "You have been promoted to a " .. player:getVocation():getName() .. "!")
                player:getPosition():sendMagicEffect(27)
            end
        return true
    end
end

Nothing happens when I click the item, although if I change
Lua:
elseif voc >= 5 and voc <= 8 and player:getSex() == PLAYERSEX_MALE then
to for example
Lua:
elseif voc <= 4 and voc ~= 0 and player:getSex() == PLAYERSEX_MALE then
and try it while my vocation id is 4 or less, then it works.

But if I do it on a Master Sorcerer for example and confirm in database the vocation id is 5, nothing happens.
And I did add new promotions after the normal ones.
TFS 1.2
 
Last edited:
Solution
lol forgot i was typing a response and thought i posted it

your vocation isn't found in the outfits table, you need to add them
lookType is being assigned nil beacuse vocOutfit = nil since it's indexed by vocation id
Lua:
local outfits = {
    [1] = {male = 145, female = 149}, --
    [2] = {male = 725, female = 724}, --
    [3] = {male = 129, female = 137}, --
    [4] = {male = 131, female = 139}, --
    -- add more vocations here
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local voc = player:getVocation():getId()
    local vocOutfit = outfits[voc]
    local outfit = player:getOutfit()
    if vocOutfit then
        local outfitID = player:getSex() == PLAYERSEX_FEMALE and...
try this, shortened it too
Lua:
local outfits = {
    [1] = {male = 145, female = 149}, --
    [2] = {male = 725, female = 724}, --
    [3] = {male = 129, female = 137}, --
    [4] = {male = 131, female = 139}, --
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local voc = player:getVocation():getId()
    local vocOutfit = outfits[voc]
    local outfit = player:getOutfit()
    vocOutfit = player:getSex() == PLAYERSEX_FEMALE and vocOutfit.female or vocOutfit.male
    if voc ~= 0 and voc <= 8 then
        player:addOutfitAddon(outfits[k].female, 2)
        outfit.lookType = vocOutfit
        outfit.lookAddons = 2
        player:setOutfit(outfit)
        item:remove(1)
        player:setVocation(voc + 4)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have been promoted to a " .. player:getVocation():getName() .. "!")
        player:getPosition():sendMagicEffect(27)
    end
    return true
end
if it doesn't work, post your vocations.xml
 
try this, shortened it too
Lua:
local outfits = {
    [1] = {male = 145, female = 149}, --
    [2] = {male = 725, female = 724}, --
    [3] = {male = 129, female = 137}, --
    [4] = {male = 131, female = 139}, --
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local voc = player:getVocation():getId()
    local vocOutfit = outfits[voc]
    local outfit = player:getOutfit()
    vocOutfit = player:getSex() == PLAYERSEX_FEMALE and vocOutfit.female or vocOutfit.male
    if voc ~= 0 and voc <= 8 then
        player:addOutfitAddon(outfits[k].female, 2)
        outfit.lookType = vocOutfit
        outfit.lookAddons = 2
        player:setOutfit(outfit)
        item:remove(1)
        player:setVocation(voc + 4)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have been promoted to a " .. player:getVocation():getName() .. "!")
        player:getPosition():sendMagicEffect(27)
    end
    return true
end
if it doesn't work, post your vocations.xml

12: attempt to index local 'vocOutfit'

edit: and btw I don't know what 'clientid' means in vocations.xml if that can have something to do with it.
 
don't believe clientid has anything to do with this
Lua:
local outfits = {
    [1] = {male = 145, female = 149}, --
    [2] = {male = 725, female = 724}, --
    [3] = {male = 129, female = 137}, --
    [4] = {male = 131, female = 139}, --
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local voc = player:getVocation():getId()
    local vocOutfit = outfits[voc]
    local outfit = player:getOutfit()
    if vocOutfit then
        vocOutfit = player:getSex() == PLAYERSEX_FEMALE and vocOutfit.female or vocOutfit.male
    end
    if voc ~= 0 and voc <= 8 then
        player:addOutfitAddon(vocOutfit, 2)
        outfit.lookType = vocOutfit
        outfit.lookAddons = 2
        player:setOutfit(outfit)
        item:remove(1)
        player:setVocation(voc + 4)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have been promoted to a " .. player:getVocation():getName() .. "!")
        player:getPosition():sendMagicEffect(27)
    end
    return true
end
 
don't believe clientid has anything to do with this
Lua:
local outfits = {
    [1] = {male = 145, female = 149}, --
    [2] = {male = 725, female = 724}, --
    [3] = {male = 129, female = 137}, --
    [4] = {male = 131, female = 139}, --
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local voc = player:getVocation():getId()
    local vocOutfit = outfits[voc]
    local outfit = player:getOutfit()
    if vocOutfit then
        vocOutfit = player:getSex() == PLAYERSEX_FEMALE and vocOutfit.female or vocOutfit.male
    end
    if voc ~= 0 and voc <= 8 then
        player:addOutfitAddon(vocOutfit, 2)
        outfit.lookType = vocOutfit
        outfit.lookAddons = 2
        player:setOutfit(outfit)
        item:remove(1)
        player:setVocation(voc + 4)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have been promoted to a " .. player:getVocation():getName() .. "!")
        player:getPosition():sendMagicEffect(27)
    end
    return true
end
Shouldn't it be
voc < 5
or
voc <= 4

We don't want them to be able to promote more then once.
 
don't believe clientid has anything to do with this
Lua:
local outfits = {
    [1] = {male = 145, female = 149}, --
    [2] = {male = 725, female = 724}, --
    [3] = {male = 129, female = 137}, --
    [4] = {male = 131, female = 139}, --
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local voc = player:getVocation():getId()
    local vocOutfit = outfits[voc]
    local outfit = player:getOutfit()
    if vocOutfit then
        vocOutfit = player:getSex() == PLAYERSEX_FEMALE and vocOutfit.female or vocOutfit.male
    end
    if voc ~= 0 and voc <= 8 then
        player:addOutfitAddon(vocOutfit, 2)
        outfit.lookType = vocOutfit
        outfit.lookAddons = 2
        player:setOutfit(outfit)
        item:remove(1)
        player:setVocation(voc + 4)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have been promoted to a " .. player:getVocation():getName() .. "!")
        player:getPosition():sendMagicEffect(27)
    end
    return true
end
Everything works good except that I turn invisible when I use the item. :d
 
Last edited:
lol forgot i was typing a response and thought i posted it

your vocation isn't found in the outfits table, you need to add them
lookType is being assigned nil beacuse vocOutfit = nil since it's indexed by vocation id
Lua:
local outfits = {
    [1] = {male = 145, female = 149}, --
    [2] = {male = 725, female = 724}, --
    [3] = {male = 129, female = 137}, --
    [4] = {male = 131, female = 139}, --
    -- add more vocations here
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local voc = player:getVocation():getId()
    local vocOutfit = outfits[voc]
    local outfit = player:getOutfit()
    if vocOutfit then
        local outfitID = player:getSex() == PLAYERSEX_FEMALE and vocOutfit.female or vocOutfit.male
        player:addOutfitAddon(outfitID, 2)
        outfit.lookType = outfitID
        outfit.lookAddons = 2
        player:setOutfit(outfit)
        item:remove(1)
        player:setVocation(voc + 4)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have been promoted to a " .. player:getVocation():getName() .. "!")
        player:getPosition():sendMagicEffect(27)
    end
    return true
end
 
Solution
lol forgot i was typing a response and thought i posted it

your vocation isn't found in the outfits table, you need to add them
lookType is being assigned nil beacuse vocOutfit = nil since it's indexed by vocation id
Lua:
local outfits = {
    [1] = {male = 145, female = 149}, --
    [2] = {male = 725, female = 724}, --
    [3] = {male = 129, female = 137}, --
    [4] = {male = 131, female = 139}, --
    -- add more vocations here
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local voc = player:getVocation():getId()
    local vocOutfit = outfits[voc]
    local outfit = player:getOutfit()
    if vocOutfit then
        local outfitID = player:getSex() == PLAYERSEX_FEMALE and vocOutfit.female or vocOutfit.male
        player:addOutfitAddon(outfitID, 2)
        outfit.lookType = outfitID
        outfit.lookAddons = 2
        player:setOutfit(outfit)
        item:remove(1)
        player:setVocation(voc + 4)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have been promoted to a " .. player:getVocation():getName() .. "!")
        player:getPosition():sendMagicEffect(27)
    end
    return true
end
Thanks alot, working just as I want now! :]
 
Back
Top