• 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 Promotion doesn't work [Solved]

jakub742

Member
Joined
May 1, 2010
Messages
144
Solutions
2
Reaction score
20
Location
Slovakia
Hello. Im using 7.72 OTHire distro version 0.0.3 and i have an issue with promotion. On previous version 0.0.2 it worked just fine. Both NPC or through talkaction script.

Now i keep getting the same error with isPromoted() function.

Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/promote.lua:onSay

data/talkactions/scripts/promote.lua:16: attempt to call global 'isPromoted' (a nil value)
stack traceback:
        data/talkactions/scripts/promote.lua:16: in function <data/talkactions/scripts/promote.lua:1>

Here is my promotion.lua script from talkactions - PASTEBIN

Same thing with NpcSystem
Code:
Lua Script Error: [Npc interface]
data/npc/scripts/king.lua:onCreatureSay

data/npc/scripts/lib/npcsystem/modules.lua:93: attempt to index field 'promotions' (a nil value)
stack traceback:
        data/npc/scripts/lib/npcsystem/modules.lua:93: in function 'callback'
        data/npc/scripts/lib/npcsystem/keywordhandler.lua:47: in function 'processMessage'
        data/npc/scripts/lib/npcsystem/keywordhandler.lua:180: in function 'processNodeMessage'
        data/npc/scripts/lib/npcsystem/keywordhandler.lua:133: in function 'processMessage'
        data/npc/scripts/lib/npcsystem/npchandler.lua:298: in function 'onCreatureSay'
        data/npc/scripts/king.lua:7: in function <data/npc/scripts/king.lua:7>
 
Solution
So i added a function isPromoted to functions.lua
Code:
function isPromoted(cid)
    if (isPlayer(cid) == TRUE) then
        local voc = getPlayerVocation(cid)
        if (voc >= 5 and voc <= 8) then
            return TRUE
        end
    end

    return FALSE
end

Then i rewrite the modules.lua in NpcSystem bcs there was still and error with some local variable promotions
Code:
function StdModule.promotePlayer(cid, message, keywords, parameters, node)
        local npcHandler = parameters.npcHandler
        if(npcHandler == nil) then
            error('StdModule.promotePlayer called without any npcHandler instance.')
        end
        if(cid ~= npcHandler.focus) then
            return false
        end

        local oldVoc =...
Anytime you see something along the lines as (a nil value), this means that whatever is in the quotes is not defined on your server.
The number right next to lua:n where n is a number, that is the line number that the server thinks the error could be on.
This whole line is full of useful information
data/talkactions/scripts/promote.lua:16: attempt to call global 'isPromoted' (a nil value)

the path to the file

the file the error appeared in
the line number of where the error might be
the reason the server gave
what could be the problem, is it a table, function or variable?
and the error

 
Yea youre right there is no isPromoted function in functions.lua. Idk how is that possible if previous version had that function. Anyway thanks the explanation.
 
So i added a function isPromoted to functions.lua
Code:
function isPromoted(cid)
    if (isPlayer(cid) == TRUE) then
        local voc = getPlayerVocation(cid)
        if (voc >= 5 and voc <= 8) then
            return TRUE
        end
    end

    return FALSE
end

Then i rewrite the modules.lua in NpcSystem bcs there was still and error with some local variable promotions
Code:
function StdModule.promotePlayer(cid, message, keywords, parameters, node)
        local npcHandler = parameters.npcHandler
        if(npcHandler == nil) then
            error('StdModule.promotePlayer called without any npcHandler instance.')
        end
        if(cid ~= npcHandler.focus) then
            return false
        end

        local oldVoc = getPlayerVocation(cid)
        if (oldVoc >= 5 and oldVoc <= 8) then
            npcHandler:say('You are already promoted!')
        elseif(getPlayerLevel(cid) < parameters.level) then
            npcHandler:say('I am sorry, but I can only promote you once you have reached level ' .. parameters.level .. '.')
        elseif(doPlayerRemoveMoney(cid, parameters.cost) ~= TRUE) then
            npcHandler:say('You do not have enough money!')
        else
            doPlayerSetVocation(cid, oldVoc + 4)
            npcHandler:say(parameters.text)
        end

        npcHandler:resetNpc()
        return true


    end

Everything works now.
 
Solution
Back
Top