• 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 0.X tfs 0.4 Npc boat bug

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,188
Solutions
34
Reaction score
200
I use tfs 0.4, tibia 8.6.
I have a boat script that after some time running, it starts to give a bug and gets spamming this bug, how do I solve it?

Script:
Lua:
   local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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
function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    --//////////////////////GUEST CARD//////////////////////--
    -- [City Name]
    -- TALK = switching 1, 2, 3, 4 accoring to the number of cities
    -- COST = How many will costs the travel (gold coins)
    -- LEVEL = level needed to travel with this NPC
    -- STOR = True or False,
    ---------[True] if the player needs a certain storage in DATABASE.
    ---------[False] if you wanna disable this function.
    -- STORID = In case you put 'True', paste this your StorageID, required to travel.
    -- DESTINATION = X, Y, Z Position of place where will be teleported.
    --//////////////////////GUEST CARD//////////////////////--
    local travels = {
    ["thais"] = {talk=1, cost=0, level=0, prem=false, stor=false, storId=0, destination={x=486, y=1067, z=7}},
    ["venore"] = {talk=2, cost=0, level=0, prem=false, stor=false, storId=0, destination={x=1163, y=1173, z=7}},
    ["edron"] = {talk=3, cost=0, level=0, prem=false, stor=false, storId=0, destination={x=1040, y=892, z=5}},
    ["carlin"] = {talk=4, cost=0, level=0, prem=false, stor=false, storId=0, destination={x=972, y=1471, z=6}}
    }
  

     for k, v in pairs(travels) do
        if(msgcontains(msg:lower(), k)) then
            if isPlayerPzLocked(cid) then
                selfSay('Cant travel with pz', cid)
                return true
            elseif getCreatureSkull(cid) >= 3 then
                selfSay('Can travel black or red!', cid)
            return true
            end

        talkState[talkUser] = v.talk
            if v.stor then
                    if getPlayerStorageValue(cid, v.storId) > 0 then
                    selfSay('Do you want to travel to '..k..' for '..v.cost..' gold coins?', cid)
                    talkState[talkUser] = v.talk
                    else
                        selfSay('You must got Norseman Mission\'s to travel with me. Hics! Hi ckS ! Hic.', cid)
                        talkState[talkUser] = 0
                    end
            elseif(talkState[talkUser] == v.talk) then
                            if not isPremium(cid) and v.prem then
                                selfSay('Only p.a go to this city.', cid)                      
                            else
                                if getPlayerLevel(cid) >= v.level then
                                        if(doPlayerRemoveMoney(cid, v.cost) == TRUE) then
                                      
                                                                      
                                      
                                            function effectTp(cid)
                                                if isPlayer(cid) then
                                                    doTeleportThing(cid, v.destination, FALSE)
                                                    selfSay('Going to '..k..'.', cid)
                                                                                              
                                                    doSendMagicEffect(getCreaturePosition(cid),4)
                                                end
                                            end
                                          
                                            doSendMagicEffect(getCreaturePosition(cid),4)
                                            addEvent(effectTp,200,cid)
                                        else
                                        selfSay('Sorry, you don\'t have enough gold coins.', cid)
                                        end
                                else
                                selfSay('Sorry, you don\'t have enough level.', cid)
                                end
                            end
                talkState[talkUser] = 0
            elseif(msgcontains(msg, 'no') and isInArray({v.talk}, talkState[talkUser]) == TRUE) then
                        talkState[talkUser] = 0
                        selfSay('Ok then.', cid)
            end
        end
    end
  
  
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


error:
OBS: This error spam forever, i need to use /reload npc to stop a spam
Code:
[9:44:55.262] [Error - NpcScript Interface]
[9:44:55.262] data/npc/scripts/travel/boat.lua:onThink
[9:44:55.262] Description:
[9:44:55.262] (luaGetNpcDistanceTo) Thing not found

[9:44:55.262] [Error - NpcScript Interface]
[9:44:55.262] data/npc/scripts/travel/boat.lua:onThink
[9:44:55.262] Description:
[9:44:55.262] (luaGetCreatureName) Creature not found

[9:44:55.262] [Error - NpcScript Interface]
[9:44:55.262] data/npc/scripts/travel/boat.lua:onThink
[9:44:55.262] Description:
[9:44:55.262] data/npc/lib/npcsystem/npchandler.lua:308: bad argument #3 to 'gsub' (string/function/table expected)
[9:44:55.262] stack traceback:
[9:44:55.262]     [C]: in function 'gsub'
[9:44:55.262]     data/npc/lib/npcsystem/npchandler.lua:308: in function 'parseMessage'
[9:44:55.262]     data/npc/lib/npcsystem/npchandler.lua:545: in function 'onWalkAway'
[9:44:55.262]     data/npc/lib/npcsystem/npchandler.lua:480: in function 'onThink'
[9:44:55.262]     data/npc/scripts/travel/boat.lua:9: in function <data/npc/scripts/travel/boat.lua:9>
 
Last edited by a moderator:
use that:
npcscripts/travel.lua
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local talkState, xmsg = {}, {}

function onCreatureAppear(cid)         npcHandler:eek:nCreatureAppear(cid) end
function onCreatureDisappear(cid)       npcHandler:eek:nCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)       npcHandler:eek:nCreatureSay(cid, type, msg) end
function onThink()           npcHandler:eek:nThink() end

local locations = {
     ["Thais"] = {pos = {x = 776, y = 860, z = 7}, gold = 100},
     ["Carlin"] = {pos = {x = 777, y = 860, z = 7}, gold = 120},
     ["Venore"] = {pos = {x = 777, y = 861, z = 7}, gold = 90}
}

local function Cptl(f, r)
     return f:upper()..r:lower()
end

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

     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

     local x = locations[msg:gsub("(%a)([%w_']*)", Cptl)]
     if msgcontains(msg, 'offer') then
         if getPlayerPremiumDays(cid) >= 1 then
             selfSay('Hello,where do you want to go? I can bring you to Thais, Carlin or Venore.', cid)
             talkState[talkUser] = 1
         else
             selfSay('Travel is only for premium.', cid)
         end
     elseif x and talkState[talkUser] == 1 then
         selfSay('Do you want to travel to '..msg..' for '..x.gold..' gold?', cid)
         xmsg[cid] = msg
         talkState[talkUser] = 2
     elseif msgcontains(msg, 'yes') and talkState[talkUser] == 2 then
         x = locations[xmsg[cid]:gsub("(%a)([%w_']*)", Cptl)]
         if doPlayerRemoveMoney(cid, x.gold) then
             selfSay('Here you go, have a fun trip to '..xmsg[cid]..'.', cid)
             doTeleportThing(cid, x.pos)
             talkState[talkUser] = 0
         else
             selfSay('You don\'t have enough money.', cid)
             talkState[talkUser] = 0
         end
     else
         selfSay('Say "offer"..... I don\'t understand what you mean with '..msg..'.', cid)
     end
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

XML:
<npc name="Town callback" script="travel.lua" walkinterval="2000" floorchange="0">
    <health now="100" max="100"/>
    <look type="132" head="20" body="39" legs="45" feet="7" addons="0"/>
</npc>
 
Last edited by a moderator:

Similar threads

Back
Top