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

TFS 1.X+ TFS 1.3 promotion script

wick3dr0se

Member
Joined
Sep 24, 2020
Messages
44
Solutions
1
Reaction score
12
I've browsed the forum and come upon many promotion talkaction scripts but I've yet to get one fully functioning. I managed to get the script to give feedback but it does not actually promote the character.

Lua:
local config = {
 promotion = 1, -- promotion level, default = 1 . Ignore if you don't have new vocations.
 minLevel = 20, -- Level needed to buy promotion
 cost = 20000,  -- Promotion cost in gp
 premium = "yes"  -- is premium needed to buy promotion?
}

local disabledVocations = {0}

function onSay(cid, words, param)
 if(isInArray(disabledVocations, getPlayerVocation(cid)) == TRUE) then
  doPlayerSendCancel(cid, "Your vocation cannot buy promotion.")
 elseif(config.premium == TRUE and isPremium(cid) == FALSE) then
  doPlayerSendCancel(cid, "You need a premium account.")
 elseif(getPlayerPromotionLevel(cid) >= config.promotion) then
  doPlayerSendCancel(cid, "You are already promoted.")
 elseif(getPlayerLevel(cid) < config.minLevel) then
  doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You need " .. config.minLevel .. " to get promotion.")
 elseif(doPlayerRemoveMoney(cid, config.cost) ~= TRUE) then
  doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You do not have enought money! (Promotion cost " .. config.cost .. " gp.")
 else
  setPlayerPromotionLevel(cid, config.promotion)
  doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have been succesful promoted to " .. getVocationInfo(getPlayerVocation(cid)).name .. ".")
 end
 return TRUE
end
 
Solution
Lua:
local vocations = {
    [1] = 5,
    [2] = 6,
    [3] = 7,
    [4] = 8,
}


function onSay(player, words, param)
       local vocation = player:getVocation()
       local vocID = vocation:getId()
       local PromotionPrice = 20000
       if vocations[vocID] then
       if player:removeMoney(PromotionPrice) then
       player:setVocation(Vocation(vocations[vocID]))
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have been promoted!.")
       player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
    else
    player:sendCancelMessage("Sorry, You don't have enough money.")
    end
    else
    player:sendCancelMessage("Sorry, you are already promoted.")
    end
    return true
end
Lua:
local vocations = {
    [1] = 5,
    [2] = 6,
    [3] = 7,
    [4] = 8,
}


function onSay(player, words, param)
       local vocation = player:getVocation()
       local vocID = vocation:getId()
       local PromotionPrice = 20000
       if vocations[vocID] then
       if player:removeMoney(PromotionPrice) then
       player:setVocation(Vocation(vocations[vocID]))
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have been promoted!.")
       player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
    else
    player:sendCancelMessage("Sorry, You don't have enough money.")
    end
    else
    player:sendCancelMessage("Sorry, you are already promoted.")
    end
    return true
end
 
Solution
Lua:
local vocations = {
    [1] = 5,
    [2] = 6,
    [3] = 7,
    [4] = 8,
}


function onSay(player, words, param)
       local vocation = player:getVocation()
       local vocID = vocation:getId()
       local PromotionPrice = 20000
       if vocations[vocID] then
       if player:removeMoney(PromotionPrice) then
       player:setVocation(Vocation(vocations[vocID]))
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have been promoted!.")
       player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
    else
    player:sendCancelMessage("Sorry, You don't have enough money.")
    end
    else
    player:sendCancelMessage("Sorry, you are already promoted.")
    end
    return true
end
Awesome man! Thanks so much!. It works perfectly. Is there a way to send it to console in orange like before? Great to see the contributions for people moving to TFS 1.3 as well
 
You can change to any of the following
C++:
    MESSAGE_STATUS_CONSOLE_BLUE = 4, /*FIXME Blue message in the console*/

    MESSAGE_STATUS_CONSOLE_RED = 13, /*Red message in the console*/

    MESSAGE_STATUS_DEFAULT = 17, /*White message at the bottom of the game window and in the console*/
    MESSAGE_STATUS_WARNING = 18, /*Red message in game window and in the console*/
    MESSAGE_EVENT_ADVANCE = 19, /*White message in game window and in the console*/

    MESSAGE_STATUS_SMALL = 21, /*White message at the bottom of the game window"*/
    MESSAGE_INFO_DESCR = 22, /*Green message in game window and in the console*/
    MESSAGE_DAMAGE_DEALT = 23,
    MESSAGE_DAMAGE_RECEIVED = 24,
    MESSAGE_HEALED = 25,
    MESSAGE_EXPERIENCE = 26,
    MESSAGE_DAMAGE_OTHERS = 27,
    MESSAGE_HEALED_OTHERS = 28,
    MESSAGE_EXPERIENCE_OTHERS = 29,
    MESSAGE_EVENT_DEFAULT = 30, /*White message at the bottom of the game window and in the console*/
    MESSAGE_LOOT = 31,

    MESSAGE_GUILD = 33, /*White message in channel (+ channelId)*/
    MESSAGE_PARTY_MANAGEMENT = 34, /*White message in channel (+ channelId)*/
    MESSAGE_PARTY = 35, /*White message in channel (+ channelId)*/
    MESSAGE_EVENT_ORANGE = 36, /*Orange message in the console*/
    MESSAGE_STATUS_CONSOLE_ORANGE = 37,  /*Orange message in the console*/
Just change this line
Lua:
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have been promoted!.")
 
Made a version with revscriptsys, plop it down on data/scripts/talkaction/promotion.lua
(if the folder dont exist, just create it).

Lua:
-- Promotion script TFS 1.3 revScriptSys
-- place in data/scripts/talkaction/promotion.lua
local config = {
    ["premium"] = true,
    ["price"] = 20000,
    ["level"] = 20
}

local TA_promotion = TalkAction("!promotion")

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 promotion = vocation:getPromotion()
    if vocation == promotion or player:getStorageValue(PlayerStorageKeys.promotion) == 1 then
        player:sendCancelMessage("You are already promoted!")
        player:setStorageValue(PlayerStorageKeys.promotion, 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

    -- Check if player can afford promotion
    if not player:removeTotalMoney(config.price) then
        player:sendCancelMessage("You do not have enough money!")
        return false
    end

    player:setVocation(promotion)
    player:setStorageValue(PlayerStorageKeys.promotion, 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)
 
    return true
end

TA_promotion:register()
 
Last edited:
Made a version with revscriptsys, plop it down on data/scripts/talkaction/promotion.lua
(if the folder dont exist, just create it).

Lua:
-- Promotion script TFS 1.3 revScriptSys
-- place in data/scripts/talkaction/promotion.lua
local config = {
    ["premium"] = true,
    ["price"] = 20000,
    ["level"] = 20
}

local TA_promotion = TalkAction("!promotion")

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 promotion = vocation:getPromotion()
    if vocation == promotion or player:getStorageValue(PlayerStorageKeys.promotion) == 1 then
        player:sendCancelMessage("You are already promoted!")
        player:setStorageValue(PlayerStorageKeys.promotion, 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

    -- Check if player can afford promotion
    if not player:removeTotalMoney(config.price) then
        player:sendCancelMessage("You do not have enough money!")
        return false
    end

    player:setVocation(promotion)
    player:setStorageValue(PlayerStorageKeys.promotion, 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)

    return true
end

TA_promotion:register()
This is awesome. I wasn't much aware of revscriptsys and how it rids the need of a seperate XML file. I did as suggested and copied the script in to promotion.lua inside of /data/scripts/talkactions. I noticed your directory said /data/scripts/talkaction not talkactions. Idk if that makes a difference but my folder is talkactions and in there is an example revscriptsys position.lua. When I run !promotion in game after recompile it does nothing. I even tried another compile removing promotion.lua from /data/talkactions/scripts and the entry from talkactions.xml. Still the same result
 
1605334676781.png

Placed it in data\scripts\talkactions\promotion.lua
Worked fine. You need to restart the server or gamble with a /reload scripts for it to load. And make sure the talkaction isn't already in use somewhere else. !promotion

So you need to remove it from data/talkactions/talkactions.xml
 
and for second promote?
With this script, you need to change these values, whats inside [ ] is the currently vocationid and whats after "=" is the New vocationid.
Lua:
local vocations = {
    [5] = 9, -- promotes from master sorcerer to another vocation with id 9
    [6] = 10,
    [7] = 11,
    [8] = 12,
}
 
Last edited:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local vocation = player:getVocation():getId()
    if vocation >= 5 and vocation <= 8 then
        vocation = vocation + 4
        player:setVocation(vocation)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You've been promoted! Congratulations!")
        item:remove()
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You're already at the maximum promotion level. Unable to utilize this item.")
    end
    return true
end
For sec promotion
 
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local vocation = player:getVocation():getId()
    if vocation >= 5 and vocation <= 8 then
        vocation = vocation + 4
        player:setVocation(vocation)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You've been promoted! Congratulations!")
        item:remove()
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You're already at the maximum promotion level. Unable to utilize this item.")
    end
    return true
end
For sec promotion
and price, level?
 
Back
Top