• 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 Problem with function

Herwiak

New Member
Joined
Jun 20, 2010
Messages
9
Reaction score
0
Hello. I'm using TFS 1.1
I've got problem with function:
Code:
function getAccountLanguage(cid)
    local resultId = db.executeQuery("SELECT `language` FROM `accounts` WHERE `id` = " .. getPlayerAccountId(cid)) -- this is 122 line in global.lua
    if resultId ~= false then
        local days = result.getDataInt(resultId, "language")
        result.free(resultId)
        return days
    end
    return 0
end
I have definied function getPlayerAccountId(cid):
Code:
function getPlayerAccountId(cid) local p = Player(cid) return p ~= nil and p:getAccountId() or false end
but when i'm trying to use it in npc script:
http://pastebin.com/5aPqg8r3

I have definied in lib:
Code:
ENGLISH = 0
POLISH = 1

I'm getting this error in console:
colin.png


Please help me with this problem.

Regards,
Herwiak

 
The function getAccountLanguage is currently being used outside an function where cid is not defined (hence the error regarding a boolean value).

However you can use CALLBACK_GREET, and CALLBACK_FAREWELL:
Code:
    local config = {
        greetMessage = {
            [ENGLISH] = "Hello. How may I help you |PLAYERNAME|? Ask me for a {trade} if you want to buy something. I can also explain the {mail} system.",
            [POLISH] = "Witaj. |PLAYERNAME|, jak moge Ci pomoc? Zapytaj mnie o {trade} jesli chcesz cos kupic. Moge ci tez wyjasnic {mail} system."
        },
        farewellMessage = {
            [ENGLISH] = "It was a pleasure to help you, |PLAYERNAME|.",
            [POLISH] = "To byla przyjemnosc, aby Ci pomoc, |PLAYERNAME|."
        }
    }

    local function greetCallback(cid)
        local greetMessage = config.greetMessage[getAccountLanguage(cid)]
        if greetMessage then
            npcHandler:setMessage(MESSAGE_GREET, greetMessage)
        end
        return true
    end

    local function farewellCallback(cid)
        local farewellMessage = config.farewellMessage[getAccountLanguage(cid)]
        if farewellMessage then
              npcHandler:setMessage(MESSAGE_FAREWELL, farewellMessage)
        end
        return true
    end

    npcHandler:setCallback(CALLBACK_GREET, greetCallback)
    npcHandler:setCallback(CALLBACK_FAREWELL, farewellCallback)
Just an example.
 
The error says you are returning a BOOLEAN value, which you cant concatenate. So check first if the value from account is not false or nill then concatenate
 
Wow. Now npc sends me hello message in specified language, but there are errors in console and he don't want to say anythink on "bye" only he says default "Good bye." when i go away.

Console error:
colin2.png


//edit
Trade message works, but still farewell wont work :( same error
Code:
local config = {
        greetMessage = {
            [0] = "Hello. How may I help you |PLAYERNAME|? Ask me for a {trade} if you want to buy something. I can also explain the {mail} system.",
            [1] = "Witaj. |PLAYERNAME|, jak moge Ci pomoc? Zapytaj mnie o {trade} jesli chcesz cos kupic. Moge ci tez wyjasnic system {mail}'owy."
        },
        ontradeMessage = {
            [0] = "Here. Don't forget that you need to buy a label too if you want to send a parcel. Always write the name of the {receiver} in the first line.",
            [1] = "Prosze. Nie zapomnij zakupic label jesli chcesz wyslać parcel. Pamietaj, aby zawsze w pierszej linii wpisac nazwe {odbiorcy}"
        },
        farewellMessage = {
            [0] = "It was a pleasure to help you, |PLAYERNAME|.",
            [1] = "To byla przyjemnosc, aby Ci pomoc, |PLAYERNAME|."
        }
    }

    local function greetCallback(cid)
        local greetMessage = config.greetMessage[getAccountLanguage(cid)]
        if greetMessage then
            npcHandler:setMessage(MESSAGE_GREET, greetMessage)
        end
        return true
    end
 
      local function ontradeCallback(cid)
        local ontradeMessage = config.ontradeMessage[getAccountLanguage(cid)]
        if ontradeMessage then
              npcHandler:setMessage(MESSAGE_SENDTRADE, ontradeMessage)
        end
        return true
    end

    local function farewellCallback(cid)
        local farewellMessage = config.farewellMessage[getAccountLanguage(cid)]
        if farewellMessage then
              npcHandler:setMessage(MESSAGE_FAREWELL, farewellMessage)
        end
        return true
    end

    npcHandler:setCallback(CALLBACK_GREET, greetCallback)
    npcHandler:setCallback(CALLBACK_ONTRADEREQUEST, ontradeCallback)
    npcHandler:setCallback(CALLBACK_FAREWELL, farewellCallback)
 
Last edited:
Back
Top