• 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 Promotion Scroll

T

Tibia Demon

Guest
What I have wrong here? It doesn't promote to epic promotions.
Lua:
local promotiontwo = Action()

local config = {
    ["premium"] = true,
    ["level"] = 20
}

function promotiontwo.onUse(player, item, fromPos, target, toPos, isHotkey)
    -- 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 promotiontwo = vocation:getPromotion()
    if vocation == promotiontwo or player:getStorageValue(PlayerStorageKeys.promotiontwo) == 1 then
        player:sendCancelMessage("You are already promoted!")
        player:setStorageValue(PlayerStorageKeys.promotiontwo, 1)
        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 8.")
        return false
    end
    player:setVocation(promotiontwo)
    player:setStorageValue(PlayerStorageKeys.promotiontwo, 1)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Congratulations! You are now promoted.")
    player:sendTextMessage(MESSAGE_EVENT_ORANGE, "Congratulations! You are now promoted.")
    player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
    item:remove(1)
    return true
end

promotiontwo:id(9112)
promotiontwo:register()
XML:
    <vocation id="9" clientid="3" name="Epic Master Sorcerer" description="an epic master sorcerer" gaincap="10" gainhp="5" gainmana="30" gainhpticks="4" gainhpamount="10" gainmanaticks="2" gainmanaamount="10" manamultiplier="1.1" attackspeed="2000" basespeed="220" soulmax="200" gainsoulticks="15" fromvoc="5">
        <formula meleeDamage="1.0" distDamage="1.0" defense="1.0" armor="1.0" />
        <skill id="0" multiplier="1.5" />
        <skill id="1" multiplier="2.0" />
        <skill id="2" multiplier="2.0" />
        <skill id="3" multiplier="2.0" />
        <skill id="4" multiplier="2.0" />
        <skill id="5" multiplier="1.5" />
        <skill id="6" multiplier="1.1" />
    </vocation>
    <vocation id="10" clientid="4" name="Epic Elder Druid" description="an epic elder druid" gaincap="10" gainhp="5" gainmana="30" gainhpticks="4" gainhpamount="10" gainmanaticks="2" gainmanaamount="10" manamultiplier="1.1" attackspeed="2000" basespeed="220" soulmax="200" gainsoulticks="15" fromvoc="6">
        <formula meleeDamage="1.0" distDamage="1.0" defense="1.0" armor="1.0" />
        <skill id="0" multiplier="1.5" />
        <skill id="1" multiplier="1.8" />
        <skill id="2" multiplier="1.8" />
        <skill id="3" multiplier="1.8" />
        <skill id="4" multiplier="1.8" />
        <skill id="5" multiplier="1.5" />
        <skill id="6" multiplier="1.1" />
    </vocation>
    <vocation id="11" clientid="2" name="Epic Royal Paladin" description="an epic royal paladin" gaincap="20" gainhp="10" gainmana="15" gainhpticks="3" gainhpamount="10" gainmanaticks="3" gainmanaamount="10" manamultiplier="1.4" attackspeed="2000" basespeed="220" soulmax="200" gainsoulticks="15" fromvoc="7">
        <formula meleeDamage="1.0" distDamage="1.0" defense="1.0" armor="1.0" />
        <skill id="0" multiplier="1.2" />
        <skill id="1" multiplier="1.2" />
        <skill id="2" multiplier="1.2" />
        <skill id="3" multiplier="1.2" />
        <skill id="4" multiplier="1.1" />
        <skill id="5" multiplier="1.1" />
        <skill id="6" multiplier="1.1" />
    </vocation>
    <vocation id="12" clientid="1" name="Epic Elite Knight" description="an epic elite knight" gaincap="25" gainhp="15" gainmana="5" gainhpticks="2" gainhpamount="10" gainmanaticks="4" gainmanaamount="10" manamultiplier="3.0" attackspeed="2000" basespeed="220" soulmax="200" gainsoulticks="15" fromvoc="8">
        <formula meleeDamage="1.0" distDamage="1.0" defense="1.0" armor="1.0" />
        <skill id="0" multiplier="1.1" />
        <skill id="1" multiplier="1.1" />
        <skill id="2" multiplier="1.1" />
        <skill id="3" multiplier="1.1" />
        <skill id="4" multiplier="1.4" />
        <skill id="5" multiplier="1.1" />
        <skill id="6" multiplier="1.1" />
    </vocation>
Post automatically merged:

Fixed it.
I think I might have had a misunderstanding on how prevoc works because I thought it should get next promotions as long as it was set correct but I couldn't get it to work so I just added a table like old times.
Lua:
local vocationsforsecondpromo = {
    [5] = 9,
    [6] = 10,
    [7] = 11,
    [8] = 12,
}
 
Last edited by a moderator:
Solution
1. You don't need this if, since you are checking the voc anyways.
Code:
player:getStorageValue(PlayerStorageKeys.promotiontwo) == 1

2. This and that is pretty much the same check in this case.
Code:
if vocationsforsecondpromo[vocID] then
Code:
if table.contains({8, 7, 6, 5}, vocID) then

3. You can do something like this:
Code:
if vocationsforsecondpromo[vocID] ~= nil then
   if player:getLevel() >= config.level then
       promote
   else
       too low level
   end
else
   you are already promoted
end
^In this case you need another if to check if player got first promotion.
This is the script after I am done.
It works perfect in game but is it alright script side?
Lua:
local promotionTwo = Action()

local config = {
    ["premium"] = true,
    ["level"] = 20
}
local vocationsforsecondpromo = {
    [5] = 9,
    [6] = 10,
    [7] = 11,
    [8] = 12,
}

function promotionTwo.onUse(player, item, fromPos, target, toPos, isHotkey)
    -- 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 vocationName = vocation:getName()
    local vocID = player:getVocation():getId()
    local promotiontwo = vocation:getPromotion()
    if table.contains({9, 10, 11, 12}, vocID) or player:getStorageValue(PlayerStorageKeys.promotiontwo) == 1 then
        player:sendCancelMessage("You are already promoted!")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        player:setStorageValue(PlayerStorageKeys.promotiontwo, 1)
        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
    if vocationsforsecondpromo[vocID] then
    if table.contains({8, 7, 6, 5}, vocID) then
    player:setVocation(Vocation(vocationsforsecondpromo[vocID]))
    player:setStorageValue(PlayerStorageKeys.promotiontwo, 1)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Congratulations! You have succesfully upgraded from "..vocationName.." to "..Vocation(vocationsforsecondpromo[vocID]):getName()..".")
    player:sendTextMessage(MESSAGE_EVENT_ORANGE, "Congratulations! You are now promoted.")
    player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
    item:remove(1)
    end
    return true
    end
end

promotionTwo:id(9112)
promotionTwo:register()
 
1. You don't need this if, since you are checking the voc anyways.
Code:
player:getStorageValue(PlayerStorageKeys.promotiontwo) == 1

2. This and that is pretty much the same check in this case.
Code:
if vocationsforsecondpromo[vocID] then
Code:
if table.contains({8, 7, 6, 5}, vocID) then

3. You can do something like this:
Code:
if vocationsforsecondpromo[vocID] ~= nil then
   if player:getLevel() >= config.level then
       promote
   else
       too low level
   end
else
   you are already promoted
end
^In this case you need another if to check if player got first promotion.
 
Last edited:
Solution
Thank you.
I edited my script with your instructions. Removed storage check and kept only vocations one.
Removed the second vocation check too.
If anything else you see bad tell me.
 
Back
Top