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

Action TFS 1.0 | Easy third promotion upgrader

Cornex

Web Developer
Staff member
Global Moderator
Joined
Jun 15, 2008
Messages
3,444
Solutions
5
Reaction score
1,166
Location
Sweden
Hello, after looking at this thread i decided to do something like this to TFS 1.0.. So, here is it.

actions.xml
Code:
<action itemid="5952" script="promotion.lua"/>

promotion.lua
Code:
local vocations = {
    -- Vocation id 1 gonna upgrade to vocation id 2
    -- Easy, huh?
    [1] = 2
}

-- Maybe it exist an better way than this function.
-- Just to lazy to look atm.
function vocationIDtoName(vocID)
    local vocation = Vocation(vocID)
    local vocname = vocation:getName()
    return vocname
end

function onUse(cid, item, fromPosition, itemEX, toPosition)
    local vocID = getPlayerVocation(cid)
    local vocationName = vocationIDtoName(vocID)
        if vocations[vocID] then
            doPlayerSendTextMessage(cid, 4, 'You have succesfully upgraded from a '..vocationName..' to a '..vocationIDtoName(vocations[vocID])..'. ')
            doPlayerSetVocation(cid, vocations[vocID])
        else
            doPlayerSendTextMessage(cid, 4, 'You cannot upgrade vocation.')
        end
   return true
end
 
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/custom/enhancedvocations.lua:onUse
data/actions/scripts/custom/enhancedvocations.lua:22: attempt to call global 'doPlayerSendTextMessage' (a nil value)
stack traceback:
    [C]: in function 'doPlayerSendTextMessage'
    data/actions/scripts/custom/enhancedvocations.lua:22: in function <data/actions/scripts/custom/enhancedvocations.lua:18>

I get this error message, but i can't find the fault.

Code:
local vocations = {
    -- Vocation id 1 gonna upgrade to vocation id 2
    -- Easy, huh?
    [5] = 9,
    [6] = 10,
    [7] = 11,
    [8] = 12,
}

-- Maybe it exist an better way than this function.
-- Just to lazy to look atm.
function vocationIDtoName(vocID)
    local vocation = Vocation(vocID)
    local vocname = vocation:getName()
    return vocname
end

function onUse(cid, item, fromPosition, itemEX, toPosition)
    local vocID = getPlayerVocation(cid)
    local vocationName = vocationIDtoName(vocID)
        if vocations[vocID] then
            doPlayerSendTextMessage(cid, 4, 'You have succesfully upgraded from a '..vocationName..' to a '..vocationIDtoName(vocations[vocID])..'. ')
            doPlayerSetVocation(cid, vocations[vocID])
        else
            doPlayerSendTextMessage(cid, 4, 'You cannot upgrade vocation.')
        end
   return true
end
 
Try this:
Code:
local vocations = {
    -- Vocation id 1 gonna upgrade to vocation id 2
    -- Easy, huh?
    [5] = 9,
    [6] = 10,
    [7] = 11,
    [8] = 12,
}

-- Maybe it exist an better way than this function.
-- Just to lazy to look atm.
function vocationIDtoName(vocID)
    local vocation = Vocation(vocID)
    local vocname = vocation:getName()
    return vocname
end

function onUse(cid, item, fromPosition, itemEX, toPosition)
local player = Player(cid)
    local vocID = player:getVocation()
    local vocationName = vocationIDtoName(vocID)
        if vocations[vocID] then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You have succesfully upgraded from a '..vocationName..' to a '..vocationIDtoName(vocations[vocID])..'. ')
            player:setVocation(vocations[vocID])
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You cannot upgrade vocation.')
        end
   return true
end
 
Just in-case you're unsure how to find that error:
attempt to call global 'doPlayerSendTextMessage' (a nil value)

Basically, what it is saying is that it's attempting to call a method that does not exist (nil value).
So, in other words, in your case, the error is basically saying that the method 'doPlayerSendTextMessage' does not exist.

The correct method to use is what @imkingran put:
Code:
player:sendTextMessage()

Please feel free to check out Wiki if you don't know which method to use: https://github.com/otland/forgottenserver/wiki

Cornex barely did anything to make this work for 1.0, there's tons of errors all over it.
I'm not sure if he even tested it.
 
Code:
[Warning - Vocations::getVocation] Vocation 65535 not found.

Lua Script Error: [Action Interface]
data/actions/scripts/custom/enhancedvocations.lua:onUse
data/actions/scripts/custom/enhancedvocations.lua:14: attempt to index local 'vocation' (a nil value)
stack traceback:
    [C]: in function '__index'
    data/actions/scripts/custom/enhancedvocations.lua:14: in function 'vocationIDtoName'
    data/actions/scripts/custom/enhancedvocations.lua:21: in function <data/actions/scripts/custom/enhancedvocations.lua:18>

nope, the new script didn't worked
 
Try this one:
Code:
local vocations = {
    -- Vocation id 1 gonna upgrade to vocation id 2
    -- Easy, huh?
    [5] = 9,
    [6] = 10,
    [7] = 11,
    [8] = 12,
}

function onUse(cid, item, fromPosition, itemEX, toPosition)
local player = Player(cid)
local vocation = player:getVocation()
local vocID = vocation:getId()
local vocationName = vocation:getName()
        if vocations[vocID] then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You have succesfully upgraded from a '..vocationName..' to a '..Vocation(vocations[vocID]):getName()..'. ')
            player:setVocation(vocations[vocID])
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You cannot upgrade vocation.')
        end
   return true
end
 
Try this one:
Code:
local vocations = {
    -- Vocation id 1 gonna upgrade to vocation id 2
    -- Easy, huh?
    [5] = 9,
    [6] = 10,
    [7] = 11,
    [8] = 12,
}

function onUse(cid, item, fromPosition, itemEX, toPosition)
local player = Player(cid)
local vocation = player:getVocation()
local vocID = vocation:getId()
local vocationName = vocation:getName()
        if vocations[vocID] then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You have succesfully upgraded from a '..vocationName..' to a '..Vocation(vocations[vocID]):getName()..'. ')
            player:setVocation(vocations[vocID])
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You cannot upgrade vocation.')
        end
   return true
end
it works for a part, i can use the item right now, it also say's that ive upgraded my vocation, but it won't remove the item, and it wont upgrade the vocation.
 
Try this:

Code:
local vocations = {
    -- Vocation id 1 gonna upgrade to vocation id 2
    -- Easy, huh?
    [5] = 9,
    [6] = 10,
    [7] = 11,
    [8] = 12,
}

function onUse(cid, item, fromPosition, itemEX, toPosition)
local player = Player(cid)
local vocation = player:getVocation()
local vocID = vocation:getId()
local vocationName = vocation:getName()
        if vocations[vocID] then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You have succesfully upgraded from a '..vocationName..' to a '..Vocation(vocations[vocID]):getName()..'. ')
            player:setVocation(Vocation(vocations[vocID]))
            Item(item.uid):remove()
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You cannot upgrade vocation.')
        end
   return true
end
 
Try this:

Code:
local vocations = {
    -- Vocation id 1 gonna upgrade to vocation id 2
    -- Easy, huh?
    [5] = 9,
    [6] = 10,
    [7] = 11,
    [8] = 12,
}

function onUse(cid, item, fromPosition, itemEX, toPosition)
local player = Player(cid)
local vocation = player:getVocation()
local vocID = vocation:getId()
local vocationName = vocation:getName()
        if vocations[vocID] then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You have succesfully upgraded from a '..vocationName..' to a '..Vocation(vocations[vocID]):getName()..'. ')
            player:setVocation(Vocation(vocations[vocID]))
            Item(item.uid):remove()
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You cannot upgrade vocation.')
        end
   return true
end
Can you make this script to check if this player is premium ?
 
Hello. I wanted to ask about version of this script used by command instead of action!
Something like !promotion
Could simple change actions.xml into talkactions.xml work?
 
Back
Top