Solved broken function at boats

Felipe93

Ghost Member
Joined
Mar 21, 2015
Messages
1,142
Best answers
6
Likes
147
Location
Chile
#1
Hello otland

i've added bring me to functions to boat npcs
they works if i say for example:Hi, Venore, Yes it works
buy when i say bring me to venore the npc doesn't reply
and i get this error at my console exe
PD:Im using OTHIRE 1.0


Code:
Lua Script Error: [Npc interface]
data/npc/scripts/barco_thais.lua:onCreatureSay

data/npc/scripts/barco_thais.lua:34: attempt to call method 'isFocused' (a nil value)
stack traceback:
        data/npc/scripts/barco_thais.lua:34: in function 'callback'
        data/npc/scripts/lib/npcsystem/npchandler.lua:301: in function 'onCreatureSay'
        data/npc/scripts/barco_thais.lua:11: in function <data/npc/scripts/barco_thais.lua:11>

Lua Script Error: [Npc interface]
data/npc/scripts/barco_thais.lua:onCreatureSay

data/npc/scripts/barco_thais.lua:34: attempt to call method 'isFocused' (a nil value)
stack traceback:
        data/npc/scripts/barco_thais.lua:34: in function 'callback'
        data/npc/scripts/lib/npcsystem/npchandler.lua:301: in function 'onCreatureSay'
        data/npc/scripts/barco_thais.lua:11: in function <data/npc/scripts/barco_thais.lua:11>
THIS IS MY NPC .LUA
 
Last edited:

ond

Well-Known Member
Joined
Mar 24, 2008
Messages
2,645
Best answers
16
Likes
390
Location
Sweden
#3
isFocused isn't in othire, maybe something like this:

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 topic

function onPlayerGreet(cid)
    npcHandler:setMessage(MESSAGE_GREET, "a^2 + b^2 = c^2")
    topic = 0
    return true
end

npcHandler:setCallback(CALLBACK_GREET, onPlayerGreet)
npcHandler:setMessage(MESSAGE_PLACEDINQUEUE, "????????")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Stick")
npcHandler:setMessage(MESSAGE_FAREWELL, "Kamma dig")

local bord = {
    {destination = "Thais", pos = {x=100, y=100, z=7}, price = 100},
    {destination = "Carlin", pos = {x=101, y=101, z=7}, price = 101},
}

function creatureSayCallback(cid, type, msg)

    if npcHandler.focus ~= cid then
        for _, v in ipairs(bord) do
            if msgcontains(msg, v.destination) and doPlayerRemoveMoney(cid, v.price) then
                doTeleportThing(cid, v.pos)
            end
        end
        return false
    end
   
    local t

    if msgcontains(msg, "talk") and msgcontains(msg, "to") and msgcontains(msg, "me") then
        npcHandler:say("What do you want me to say, huh?")
        t = 1
    elseif topic == 1 then
        if msgcontains(msg, "anything") then
            npcHandler:say("Only a truly free mason can run the world.")
            t = 2
        else
            npcHandler:say("Stick")
            npcHandler:releaseFocus()
        end
    elseif topic == 2 then
        if msgcontains(msg, "lier lier pants on fire") then
            npcHandler:say("<gets angry>")
            npcHandler:releaseFocus()
        else
            npcHandler:say("Wrong keywords!")
            t = 3
        end
    elseif topic == 3 then
        if msgcontains(msg, "no it isn't") then
            npcHandler:say("Hunted.")
            npcHandler:releaseFocus()
        else
            npcHandler:say("Oh sometimes I get a good feeling, yeah.")
        end
    end
   
    topic = t
    return true
end

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

Felipe93

Ghost Member
Joined
Mar 21, 2015
Messages
1,142
Best answers
6
Likes
147
Location
Chile
#4
isFocused isn't in othire, maybe something like this:

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 topic

function onPlayerGreet(cid)
    npcHandler:setMessage(MESSAGE_GREET, "a^2 + b^2 = c^2")
    topic = 0
    return true
end

npcHandler:setCallback(CALLBACK_GREET, onPlayerGreet)
npcHandler:setMessage(MESSAGE_PLACEDINQUEUE, "????????")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Stick")
npcHandler:setMessage(MESSAGE_FAREWELL, "Kamma dig")

local bord = {
    {destination = "Thais", pos = {x=100, y=100, z=7}, price = 100},
    {destination = "Carlin", pos = {x=101, y=101, z=7}, price = 101},
}

function creatureSayCallback(cid, type, msg)

    if npcHandler.focus ~= cid then
        for _, v in ipairs(bord) do
            if msgcontains(msg, v.destination) and doPlayerRemoveMoney(cid, v.price) then
                doTeleportThing(cid, v.pos)
            end
        end
        return false
    end
 
    local t

    if msgcontains(msg, "talk") and msgcontains(msg, "to") and msgcontains(msg, "me") then
        npcHandler:say("What do you want me to say, huh?")
        t = 1
    elseif topic == 1 then
        if msgcontains(msg, "anything") then
            npcHandler:say("Only a truly free mason can run the world.")
            t = 2
        else
            npcHandler:say("Stick")
            npcHandler:releaseFocus()
        end
    elseif topic == 2 then
        if msgcontains(msg, "lier lier pants on fire") then
            npcHandler:say("<gets angry>")
            npcHandler:releaseFocus()
        else
            npcHandler:say("Wrong keywords!")
            t = 3
        end
    elseif topic == 3 then
        if msgcontains(msg, "no it isn't") then
            npcHandler:say("Hunted.")
            npcHandler:releaseFocus()
        else
            npcHandler:say("Oh sometimes I get a good feeling, yeah.")
        end
    end
 
    topic = t
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Thanks @ond i'll try that script tomorrow
Btw i should change isfocused function by which one? I'm on my cellphone ATM so i can't check it properly i Asks this by if can avoid re-do or use other script
 
Last edited:

Felipe93

Ghost Member
Joined
Mar 21, 2015
Messages
1,142
Best answers
6
Likes
147
Location
Chile
#5
It's not broken, in order to make it work the npc must be busy first.
Yea but it shouldn't he given errors neither at otx this does not occurs,and i tester it in ine way you said it doesnt work either
 
Last edited:

StreamSide

Joseluis Gonzalez
Joined
Aug 31, 2007
Messages
3,065
Best answers
18
Likes
677
Location
Arica - Chile
#7
isFocused isn't in othire, maybe something like this:

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 topic

function onPlayerGreet(cid)
    npcHandler:setMessage(MESSAGE_GREET, "a^2 + b^2 = c^2")
    topic = 0
    return true
end

npcHandler:setCallback(CALLBACK_GREET, onPlayerGreet)
npcHandler:setMessage(MESSAGE_PLACEDINQUEUE, "????????")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Stick")
npcHandler:setMessage(MESSAGE_FAREWELL, "Kamma dig")

local bord = {
    {destination = "Thais", pos = {x=100, y=100, z=7}, price = 100},
    {destination = "Carlin", pos = {x=101, y=101, z=7}, price = 101},
}

function creatureSayCallback(cid, type, msg)

    if npcHandler.focus ~= cid then
        for _, v in ipairs(bord) do
            if msgcontains(msg, v.destination) and doPlayerRemoveMoney(cid, v.price) then
                doTeleportThing(cid, v.pos)
            end
        end
        return false
    end
  
    local t

    if msgcontains(msg, "talk") and msgcontains(msg, "to") and msgcontains(msg, "me") then
        npcHandler:say("What do you want me to say, huh?")
        t = 1
    elseif topic == 1 then
        if msgcontains(msg, "anything") then
            npcHandler:say("Only a truly free mason can run the world.")
            t = 2
        else
            npcHandler:say("Stick")
            npcHandler:releaseFocus()
        end
    elseif topic == 2 then
        if msgcontains(msg, "lier lier pants on fire") then
            npcHandler:say("<gets angry>")
            npcHandler:releaseFocus()
        else
            npcHandler:say("Wrong keywords!")
            t = 3
        end
    elseif topic == 3 then
        if msgcontains(msg, "no it isn't") then
            npcHandler:say("Hunted.")
            npcHandler:releaseFocus()
        else
            npcHandler:say("Oh sometimes I get a good feeling, yeah.")
        end
    end
  
    topic = t
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
sick way, thanks for that :)
 

Felipe93

Ghost Member
Joined
Mar 21, 2015
Messages
1,142
Best answers
6
Likes
147
Location
Chile
#8
Where should i look by isfosuced function to add it on source example where should i look at at tfs 0.4 to implement it on othire?
I don't have the option "find on all files of this proyect" at msvc 2010 like in devcpp
@ond or do you have a software to do this? I use winmerge to compare but not a software to find declarations or definitions or Even the code itself
 

Felipe93

Ghost Member
Joined
Mar 21, 2015
Messages
1,142
Best answers
6
Likes
147
Location
Chile
#10
lmao he actually told you the solution but its too hard to read imo
I'm srry to tell you this but read my latest post. It's easy to use that script
Im asking how or where should i look to implement the function into source. So i'll be updating my source not the Lua files :s
Wasnt that because you were looking my otx \ othire sources instead of the main ones?? Lool
Regards
 
Last edited:

StreamSide

Joseluis Gonzalez
Joined
Aug 31, 2007
Messages
3,065
Best answers
18
Likes
677
Location
Arica - Chile
#11
You actually do not understand anything. Also I dont know what you talking about your otx/whatever shit so go kys.
He writed the solution and if you cant understand that its because you cant add that script or edit it to make it work. Maybe both.
Thats sad because I was trying to help you last night and you just take the working one thing and ask for another.
 

Felipe93

Ghost Member
Joined
Mar 21, 2015
Messages
1,142
Best answers
6
Likes
147
Location
Chile
#12
You actually do not understand anything. Also I dont know what you talking about your otx/whatever shit so go kys.
He writed the solution and if you cant understand that its because you cant add that script or edit it to make it work. Maybe both.
Thats sad because I was trying to help you last night and you just take the working one thing and ask for another.
Sure.
I'm talking about this because you menthioned that in our conversation Even more you suggested it in our pm talk(im ásking you this because you may have custom src editions on your src)
So don't behave this way now pls...
Don't make me post it,dont try to make me look as a fool talking related to the above post.,.
You pmed yo my both accs searching the same thing
GTFOH :)
 
Last edited:

Felipe93

Ghost Member
Joined
Mar 21, 2015
Messages
1,142
Best answers
6
Likes
147
Location
Chile
#14
You actually do not understand anything. Also I dont know what you talking about your otx/whatever shit so go kys.
He writed the solution and if you cant understand that its because you cant add that script or edit it to make it work. Maybe both.
Thats sad because I was trying to help you last night and you just take the working one thing and ask for another.
Ok
 

ond

Well-Known Member
Joined
Mar 24, 2008
Messages
2,645
Best answers
16
Likes
390
Location
Sweden
#15
Edit: Nvm, try THIS instead. Been a long time.

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

-- initial variables
local topic, cost, pos

function onPlayerGreet(cid)
    npcHandler:setMessage(MESSAGE_GREET, "Hello |PLAYERNAME|. Welcome to my Boat!")
    topic, cost, pos = 0, 0, nil
    return true
end

npcHandler:setCallback(CALLBACK_GREET, onPlayerGreet)
npcHandler:setMessage(MESSAGE_PLACEDINQUEUE, "Sorry |PLAYERNAME|, I am busy.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye.")
npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye.")

function creatureSayCallback(cid, type, msg)

    -- table with information about posistions, price, destination name
    local bord = {
        [1] = {pos = {x=32387, y=31820, z=7}, cost = 110, destination = "Carlin"},
        [2] = {pos = {x=32734, y=31669, z=7}, cost = 130, destination = "Ab'Dendriel"},
        [3] = {pos = {x=32954, y=32022, z=7}, cost = 170, destination = "Venore"},
        [4] = {pos = {x=33176, y=31767, z=7}, cost = 110, destination = "Edron"},
        [5] = {pos = {x=32532, y=32784, z=7}, cost = 160, destination = "Port Hope"},
    }
   
    local postman = getPlayerStorageValue(cid, 250) >= 2
    msg = msg:lower()
   
    -- Fast travel
    if npcHandler.focus ~= cid then
        for _, v in ipairs(bord) do
            if msgcontains(msg, v.destination) then
                v.cost = postman and v.cost - 10 or v.cost
                if doPlayerRemoveMoney(cid, v.cost) then
                    if isPremium(cid) then
                        doTeleportThing(cid, v.pos)
                    else
                        npcHandler:say("Only premium players are allowed to travel by boat.")
                    end
                else
                    npcHandler:say("Sorry, you don't have enough money.")
                end
            end
        end
        return false
    end
  
    -- Variables
    local t, c, p
   
    for _, v in ipairs(bord) do
        if msgcontains(msg, v.destination) then
            v.cost = postman and v.cost - 10 or v.cost
            npcHandler:say("Would you like to travel to " .. v.destination .. " for " .. v.cost .. " gold?")
            t, c, p = 1, v.cost, v.pos
        end   
    end

    -- Confirm travel
    if topic == 1 then
        if msgcontains(msg, "yes") then
            if doPlayerRemoveMoney(cid, cost) then
                if isPremium(cid) then
                    npcHandler:say("Hold on!")
                    doTeleportThing(cid, pos)
                else
                    npcHandler:say("Sorry, only premium players are allowed to travel by boat.")
                end
            else
                npcHandler:say("You don't have enough money.")
            end
        else
            npcHandler:say("Fine with me.")
        end
   
    -- Other keywords
    elseif msgcontains(msg, "job") then
        npcHandler:say("I am the captain now.")
    elseif msgcontains(msg, "name") then
        npcHandler:say("My name is " .. getCreatureName(getNpcCid()) .. ".")
    end   
       
    -- Below is used so you don't have to put "topic = 0, cost = 0" after each keyword   
    topic, cost, pos = t, c, p
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:

Felipe93

Ghost Member
Joined
Mar 21, 2015
Messages
1,142
Best answers
6
Likes
147
Location
Chile
#16
Edit: Nvm, try THIS instead. Been a long time.

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

-- initial variables
local topic, cost, pos

function onPlayerGreet(cid)
    npcHandler:setMessage(MESSAGE_GREET, "Hello |PLAYERNAME|. Welcome to my Boat!")
    topic, cost, pos = 0, 0, nil
    return true
end

npcHandler:setCallback(CALLBACK_GREET, onPlayerGreet)
npcHandler:setMessage(MESSAGE_PLACEDINQUEUE, "Sorry |PLAYERNAME|, I am busy.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye.")
npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye.")

function creatureSayCallback(cid, type, msg)

    -- table with information about posistions, price, destination name
    local bord = {
        [1] = {pos = {x=32387, y=31820, z=7}, cost = 110, destination = "Carlin"},
        [2] = {pos = {x=32734, y=31669, z=7}, cost = 130, destination = "Ab'Dendriel"},
        [3] = {pos = {x=32954, y=32022, z=7}, cost = 170, destination = "Venore"},
        [4] = {pos = {x=33176, y=31767, z=7}, cost = 110, destination = "Edron"},
        [5] = {pos = {x=32532, y=32784, z=7}, cost = 160, destination = "Port Hope"},
    }
 
    local postman = getPlayerStorageValue(cid, 250) >= 2
    msg = msg:lower()
 
    -- Fast travel
    if npcHandler.focus ~= cid then
        for _, v in ipairs(bord) do
            if msgcontains(msg, v.destination) then
                v.cost = postman and v.cost - 10 or v.cost
                if doPlayerRemoveMoney(cid, v.cost) then
                    if isPremium(cid) then
                        doTeleportThing(cid, v.pos)
                    else
                        npcHandler:say("Only premium players are allowed to travel by boat.")
                    end
                else
                    npcHandler:say("Sorry, you don't have enough money.")
                end
            end
        end
        return false
    end
 
    -- Variables
    local t, c, p
 
    for _, v in ipairs(bord) do
        if msgcontains(msg, v.destination) then
            v.cost = postman and v.cost - 10 or v.cost
            npcHandler:say("Would you like to travel to " .. v.destination .. " for " .. v.cost .. " gold?")
            t, c, p = 1, v.cost, v.pos
        end
    end

    -- Confirm travel
    if topic == 1 then
        if msgcontains(msg, "yes") then
            if doPlayerRemoveMoney(cid, cost) then
                if isPremium(cid) then
                    npcHandler:say("Hold on!")
                    doTeleportThing(cid, pos)
                else
                    npcHandler:say("Sorry, only premium players are allowed to travel by boat.")
                end
            else
                npcHandler:say("You don't have enough money.")
            end
        else
            npcHandler:say("Fine with me.")
        end
 
    -- Other keywords
    elseif msgcontains(msg, "job") then
        npcHandler:say("I am the captain now.")
    elseif msgcontains(msg, "name") then
        npcHandler:say("My name is " .. getCreatureName(getNpcCid()) .. ".")
    end
    
    -- Below is used so you don't have to put "topic = 0, cost = 0" after each keyword
    topic, cost, pos = t, c, p
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
amazing thanks by share this with me / us :) i liked alot the postman option at the code :*
i gonna check it now
 
Last edited:
Joined
Aug 1, 2009
Messages
234
Best answers
0
Likes
18
#20
@Felipe93
Ohh ok, no problem. And hail the open tibia spirit community :D

"I ask for help in forum, cmm get help to solve my problem and then i do not share because it gave me a lot of work".

Thxx!
 
Top