• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

TFS 1.X+ Mount NPC

SUMEKAZEKI

ADM Custom Rook
Joined
Sep 10, 2016
Messages
39
Reaction score
4
hello, i try to make npc and receive this error:
DkzI1hi.png

code:
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)            npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)        npcHandler:onCreatureDisappear(cid)            end
function onCreatureSay(cid, type, msg)        npcHandler:onCreatureSay(cid, type, msg)        end
function onThink()                npcHandler:onThink()                    end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    if msgcontains({'donkey'}, msg) then
        npcHandler:say('Do you want to taming a donkey for backpack of apple slices?', cid)
        npcHandler.topic[cid] = 1
                return true
            end

            npcHandler.topic[cid] == 1 then
            if player:setStorageValue(Storage.DonkeyMount, 1) then
                npcHandler:say('You already have a Donkey.', cid)
                return true
            end

            if not player:removeItem(13537, 1)) then
                npcHandler:say('You do not have a bag of apple slices to tamed donkey!', cid)
                return true
            end

            local mountId = {13}
            player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            player:addMount(mountId[math.random(#mountId)])
            player:setStorageValue(Storage.DonkeyMount, 1)
            npcHandler:say('I\'ll give you one of our experienced ones. Take care! Look out for low hanging branches.', cid)
        end
        npcHandler.topic[cid] = 0
    elseif msgcontains(msg, 'no') and npcHandler.topic[cid] > 0 then
        npcHandler:say('Then not.', cid)
        npcHandler.topic[cid] = 0
    end
    return true
end

npcHandler:setMessage(MESSAGE_GREET, 'Salutations, |PLAYERNAME| I guess you are here for the {donkey}.')

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
Fixed syntax error
added "if" before topic 1 check in line 23, also added a check if message contains "yes"
getStorageValue instead of setStorageValue in line 26
added some comments

LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)            npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)        npcHandler:onCreatureDisappear(cid)            end
function onCreatureSay(cid, type, msg)        npcHandler:onCreatureSay(cid, type, msg)        end
function onThink()                npcHandler:onThink()                    end

local function creatureSayCallback(cid, type, msg)
    if not...
Fixed syntax error
added "if" before topic 1 check in line 23, also added a check if message contains "yes"
getStorageValue instead of setStorageValue in line 26
added some comments

LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)            npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)        npcHandler:onCreatureDisappear(cid)            end
function onCreatureSay(cid, type, msg)        npcHandler:onCreatureSay(cid, type, msg)        end
function onThink()                npcHandler:onThink()                    end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    -- If player says donkey, add topic to 1
    if msgcontains({'donkey'}, msg) then
        npcHandler:say('Do you want to taming a donkey for backpack of apple slices?', cid)
        npcHandler.topic[cid] = 1
        return true
    end

    -- If topic is 1 and player says yes
    if npcHandler.topic[cid] == 1 and msgcontains({'yes'}, msg) then

        -- If he already have a donkey, inform him and stop executing
        if player:getStorageValue(Storage.DonkeyMount) == 1 then
            npcHandler:say('You already have a Donkey.', cid)
            return true
        end

        -- If we fail to remove required item, inform him and stop executing
        if not player:removeItem(13537, 1) then
            npcHandler:say('You do not have a bag of apple slices to tamed donkey!', cid)
            return true
        end

        -- Give player his mount 
        local mountId = 13
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        player:addMount(mountId)
        player:setStorageValue(Storage.DonkeyMount, 1)
        npcHandler:say('I\'ll give you one of our experienced ones. Take care! Look out for low hanging branches.', cid)
        npcHandler.topic[cid] = 0
    
    -- If he says no, reset topic to 0
    elseif msgcontains(msg, 'no') and npcHandler.topic[cid] > 0 then
        npcHandler:say('Then not.', cid)
        npcHandler.topic[cid] = 0
    end
    return true
end

-- Greeting message to NPC
npcHandler:setMessage(MESSAGE_GREET, 'Salutations, |PLAYERNAME| I guess you are here for the {donkey}.')

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
Back
Top