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

RevScripts Vocation changing bug

T

Tibia Demon

Guest
I use last forgottenserver.
Script working but when I have promotion already it sends the cancel message and continue promoting me to second promotion.
Lua:
-- Promotion script TFS 1.3 revScriptSys
-- place in data/scripts/talkaction/promotion.lua
local config = {
    ["premium"] = true,
    ["price"] = 20000,
    ["level"] = 100
}
local vocationsforfirstpromo = {
    [1] = 5,
    [2] = 6,
    [3] = 7,
    [4] = 8,
}

local TA_promotion = TalkAction("!buypromotion")

function TA_promotion.onSay(player)
    -- Check if player need premium
    if not player:isPremium() and config.premium then
        player:sendCancelMessage("Sorry, you need to have a premium account.")
        return false
    end

    -- Check if player is already promoted
    local vocation = player:getVocation()
    local vocID = player:getVocation():getId()
    local vocationName = vocation:getName()
    local promotion = vocation:getPromotion()
    if (vocID > 4) or player:getStorageValue(PlayerStorageKeys.promotion) == 1 then
        player:sendCancelMessage("You are already promoted!")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        player:setStorageValue(PlayerStorageKeys.promotion, 1)
        return false
    end
    if (vocID == 0) then
       player:sendCancelMessage("No vocation cannot get a promotion.")
       player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    -- Check if player is high enough level
    if player:getLevel() < config.level then
        player:sendCancelMessage("You can only be promoted once you have reached level " .. config.level .. ".")
        return false
    end

    -- Check if player can afford promotion
    if not player:removeTotalMoney(config.price) then
        player:sendCancelMessage("You do not have enough money!")
        return false
    end
    if vocationsforfirstpromo[vocID] ~= nil then
    if table.contains({4, 3, 2, 1}, vocID) then
    player:setVocation(Vocation(vocationsforfirstpromo[vocID]))
    player:setStorageValue(PlayerStorageKeys.promotion, 1)
    player:save()
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Congratulations! You have succesfully upgraded from "..vocationName.." to "..Vocation(vocationsforfirstpromo[vocID]):getName()..".")
    player:sendTextMessage(MESSAGE_EVENT_ORANGE, "Congratulations! You are now promoted.")
    player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
    else
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your vocation cannot use this promotion.")
    end
    end
    return false
end

TA_promotion:register()
I add many checks and kept trying for long but it only sends
player:sendCancelMessage("You are already promoted!")
but continues and promotes me to second promotion instead of returning false.
Post automatically merged:

Solved.
I changed fromvoc to same as vocation id in vocations.xml but I wonder why it doesn't work when I have the correct fromvoc? like Epic master sorcerer fromvoc mastersorcerer so fromvoc = "5"?
Is it safe to keep it fromvoc same as vocation id?
Post automatically merged:

I want to use the correct fromvoc because this is a promotion not a whole new custom vocation.
Any idea?
Post automatically merged:

I noticed one thing after changing fromvoc when I try to use it I get this client message
You cannot use this object.
It is like it doesn't read the checks [level check, storage check, money check] its trying to make next promotion and then it fails [because it doesn't exist anymore] I changed fromvoc/vocid so instead of sending the [level check, storage check, money check] error message it just send this one
You cannot use this object.
 
Last edited by a moderator:
Solution
when I changed it to player:sendTextMessage(MESSAGE_EVENT_ADVANCE,
it worked and showed both messages
You cannot use this object. and player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "message")
I think something else send this message You cannot use this object. Could be source message.
Oh, I see.
Change your return false's to return true's

If you're using an object in onUse, return false is not a good thing to use.
If you're using a talkaction, then return false is good to use, so that words don't show up in chat channel.
I use last forgottenserver.
Script working but when I have promotion already it sends the cancel message and continue promoting me to second promotion.
Lua:
-- Promotion script TFS 1.3 revScriptSys
-- place in data/scripts/talkaction/promotion.lua
local config = {
    ["premium"] = true,
    ["price"] = 20000,
    ["level"] = 100
}
local vocationsforfirstpromo = {
    [1] = 5,
    [2] = 6,
    [3] = 7,
    [4] = 8,
}

local TA_promotion = TalkAction("!buypromotion")

function TA_promotion.onSay(player)
    -- Check if player need premium
    if not player:isPremium() and config.premium then
        player:sendCancelMessage("Sorry, you need to have a premium account.")
        return false
    end

    -- Check if player is already promoted
    local vocation = player:getVocation()
    local vocID = player:getVocation():getId()
    local vocationName = vocation:getName()
    local promotion = vocation:getPromotion()
    if (vocID > 4) or player:getStorageValue(PlayerStorageKeys.promotion) == 1 then
        player:sendCancelMessage("You are already promoted!")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        player:setStorageValue(PlayerStorageKeys.promotion, 1)
        return false
    end
    if (vocID == 0) then
       player:sendCancelMessage("No vocation cannot get a promotion.")
       player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    -- Check if player is high enough level
    if player:getLevel() < config.level then
        player:sendCancelMessage("You can only be promoted once you have reached level " .. config.level .. ".")
        return false
    end

    -- Check if player can afford promotion
    if not player:removeTotalMoney(config.price) then
        player:sendCancelMessage("You do not have enough money!")
        return false
    end
    if vocationsforfirstpromo[vocID] ~= nil then
    if table.contains({4, 3, 2, 1}, vocID) then
    player:setVocation(Vocation(vocationsforfirstpromo[vocID]))
    player:setStorageValue(PlayerStorageKeys.promotion, 1)
    player:save()
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Congratulations! You have succesfully upgraded from "..vocationName.." to "..Vocation(vocationsforfirstpromo[vocID]):getName()..".")
    player:sendTextMessage(MESSAGE_EVENT_ORANGE, "Congratulations! You are now promoted.")
    player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
    else
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your vocation cannot use this promotion.")
    end
    end
    return false
end

TA_promotion:register()
I add many checks and kept trying for long but it only sends
player:sendCancelMessage("You are already promoted!")
but continues and promotes me to second promotion instead of returning false.
Post automatically merged:

Solved.
I changed fromvoc to same as vocation id in vocations.xml but I wonder why it doesn't work when I have the correct fromvoc? like Epic master sorcerer fromvoc mastersorcerer so fromvoc = "5"?
Is it safe to keep it fromvoc same as vocation id?
Post automatically merged:

I want to use the correct fromvoc because this is a promotion not a whole new custom vocation.
Any idea?
Post automatically merged:

I noticed one thing after changing fromvoc when I try to use it I get this client message
You cannot use this object.
It is like it doesn't read the checks [level check, storage check, money check] its trying to make next promotion and then it fails [because it doesn't exist anymore] I changed fromvoc/vocid so instead of sending the [level check, storage check, money check] error message it just send this one
You cannot use this object.
It seems that the entire promotion system was tossed away in favour of only vocation changes.
I don't see a way to set a promotion inside of the sources anymore.

While they are very similar, promotions were specifically tied into the premium features, where if you lost premium, you also were reverted back to the base vocation.

Can reproduce this function with Lua code I guess, but I'm not sure why it got changed. xD
 
It could have been useful if it still exist. This line fucks it too every time a player relogin.
Any idea why the player:sendCancelMessage not working?
It only send You cannot use this object.
 
It could have been useful if it still exist. This line fucks it too every time a player relogin.
Any idea why the player:sendCancelMessage not working?
It only send You cannot use this object.
Most likely the script is erroring.
If you don't see an error in console when using the item, it probably errored during start-up of the server.

For everything else, I'd suggest putting prints into the script, and figure out exactly where it stops.

If it's skipping past an if statement that it should be stopping at, then print the values that it is checking, and ensure the values are showing up as you expect them too. More often then not, the values are showing up as something you didn't expect them to be, and that's what is causing your issue.
 
when I changed it to player:sendTextMessage(MESSAGE_EVENT_ADVANCE,
it worked and showed both messages
You cannot use this object. and player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "message")
I think something else send this message You cannot use this object. Could be source message.
 
Last edited by a moderator:
when I changed it to player:sendTextMessage(MESSAGE_EVENT_ADVANCE,
it worked and showed both messages
You cannot use this object. and player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "message")
I think something else send this message You cannot use this object. Could be source message.
Oh, I see.
Change your return false's to return true's

If you're using an object in onUse, return false is not a good thing to use.
If you're using a talkaction, then return false is good to use, so that words don't show up in chat channel.
 
Solution
Back
Top