• 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!

Hunter npc (find person)

Tbol

Member
Joined
Apr 7, 2019
Messages
154
Best answers
0
Reaction score
19
Tfs 1.2

This npc should help you find person you want for price which is money. It should be like this
Player: Hi
Npc: Hello PLAYERNAME i can help you {find} any person you want blabla
Player: find "Carl Jhonson
Npc: I saw him far west (if its possible to give as much information as possible, like steps how far he is or something)

Thanks guys
 
OP
Tbol

Tbol

Member
Joined
Apr 7, 2019
Messages
154
Best answers
0
Reaction score
19
still looking
 
OP
Tbol

Tbol

Member
Joined
Apr 7, 2019
Messages
154
Best answers
0
Reaction score
19
Still looking
 
OP
Tbol

Tbol

Member
Joined
Apr 7, 2019
Messages
154
Best answers
0
Reaction score
19
Still looking
 

Yalasari

Active Member
Joined
Jul 16, 2017
Messages
81
Best answers
8
Reaction score
44
This should work just fine, all you need to do is adjust cost and bind this script to xml npc file
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 cost = 500
local target = nil
local position = nil

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

    if msgcontains(msg, "find") and npcHandler.topic[cid] == 0 then
        npcHandler:say("Who do you want me to find for you?", cid)
        npcHandler.topic[cid] = 1
    elseif npcHandler.topic[cid] == 1 then
        target = Player(msg)
        if target then
            if target:getSex() == PLAYERSEX_FEMALE then
                npcHandler:say("Indeed i know where she is, however, this information will cost you " .. cost .. " gp. Are you willing to know too?", cid)
            else
                npcHandler:say("Indeed i know where he is, however, this information will cost you " .. cost .. " gp. Are you willing to know too?", cid)
            end
            position = target:getPosition()
            npcHandler.topic[cid] = 2
        else
            npcHandler:say("Unfortunately i didn\'t saw anybody of this name.", cid)
            npcHandler.topic[cid] = 0
        end
    elseif npcHandler.topic[cid] == 2
        if msgcontains(msg, "yes") then
            if Player(cid):removeMoney(cost) then
                local message = target:getName() .. " is "
                local horizontal = Player(cid):getPosition().x - position.x
                local vertical = Player(cid):getPosition().y - position.y
                local floor = Player(cid):getPosition().z - position.z

                if horizontal < 0 then
                    message = message .. math.abs(horizontal) .. "steps to East, "
                elseif horizontal > 0 then
                    message = message .. math.abs(horizontal) .. "steps to West, "
                end

                if vertical < 0 then
                    message = message .. math.abs(vertical) .. "steps to North, "
                elseif vertical > 0 then
                    message = message .. math.abs(vertical) .. "steps to South, "
                end

                if floor < 0 then
                    message = message .. "above us, "
                elseif floor > 0 then
                    message = message .. "beneath us, "
                end

                if math.abs(horizontal) < 2 and math.abs(vertical) < 2 and floor = 0 then
                    message = target:getName() .. " is here, "
                end

                npcHandler:say(message .. "This is all what i know.", cid)
                npcHandler.topic[cid] == 0

            else
                npcHandler:say("Im sorry but you don\'t have enough money.", cid)
                npcHandler.topic[cid] == 0
            end
        else
            npcHandler:say("Come back when you\'ve decided.", cid)
            npcHandler.topic[cid] == 0
        end
    end
    return true
end

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

Tbol

Member
Joined
Apr 7, 2019
Messages
154
Best answers
0
Reaction score
19
This should work just fine, all you need to do is adjust cost and bind this script to xml npc file
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 cost = 500
local target = nil
local position = nil

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

    if msgcontains(msg, "find") and npcHandler.topic[cid] == 0 then
        npcHandler:say("Who do you want me to find for you?", cid)
        npcHandler.topic[cid] = 1
    elseif npcHandler.topic[cid] == 1 then
        target = Player(msg)
        if target then
            if target:getSex() == PLAYERSEX_FEMALE then
                npcHandler:say("Indeed i know where she is, however, this information will cost you " .. cost .. " gp. Are you willing to know too?", cid)
            else
                npcHandler:say("Indeed i know where he is, however, this information will cost you " .. cost .. " gp. Are you willing to know too?", cid)
            end
            position = target:getPosition()
            npcHandler.topic[cid] = 2
        else
            npcHandler:say("Unfortunately i didn\'t saw anybody of this name.", cid)
            npcHandler.topic[cid] = 0
        end
    elseif npcHandler.topic[cid] == 2
        if msgcontains(msg, "yes") then
            if Player(cid):removeMoney(cost) then
                local message = target:getName() .. " is "
                local horizontal = Player(cid):getPosition().x - position.x
                local vertical = Player(cid):getPosition().y - position.y
                local floor = Player(cid):getPosition().z - position.z

                if horizontal < 0 then
                    message = message .. math.abs(horizontal) .. "steps to East, "
                elseif horizontal > 0 then
                    message = message .. math.abs(horizontal) .. "steps to West, "
                end

                if vertical < 0 then
                    message = message .. math.abs(vertical) .. "steps to North, "
                elseif vertical > 0 then
                    message = message .. math.abs(vertical) .. "steps to South, "
                end

                if floor < 0 then
                    message = message .. "above us, "
                elseif floor > 0 then
                    message = message .. "beneath us, "
                end

                if math.abs(horizontal) < 2 and math.abs(vertical) < 2 and floor = 0 then
                    message = target:getName() .. " is here, "
                end

                npcHandler:say(message .. "This is all what i know.", cid)
                npcHandler.topic[cid] == 0

            else
                npcHandler:say("Im sorry but you don\'t have enough money.", cid)
                npcHandler.topic[cid] == 0
            end
        else
            npcHandler:say("Come back when you\'ve decided.", cid)
            npcHandler.topic[cid] == 0
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Mmm you forgot then at 36 line and at 62 line you forgot to add double equals if im not wrong managed to adjust that much but now it gives = expected near == at line 67, not sure how to adjust those
 
Joined
Sep 3, 2011
Messages
3,737
Best answers
22
Reaction score
2,423
Location
Sweden
Mmm you forgot then at 36 line and at 62 line you forgot to add double equals if im not wrong managed to adjust that much but now it gives = expected near == at line 67, not sure how to adjust those
Remove one = at line 67, 71, 75.
Should be like this:
Lua:
npcHandler.topic[cid] = 0
One equal (=) means you set the npcHandler.topic[cid] to 0.
 

Shadow_

Advanced OT User
Joined
Jun 2, 2018
Messages
583
Best answers
20
Reaction score
163
Location
Cairo, Egypt
Remove one = at line 67, 71, 75.
Should be like this:
Lua:
npcHandler.topic[cid] = 0
One equal (=) means you set the npcHandler.topic[cid] to 0.
you can tell him one equal means this variable is going to be stored with 0 value "==" makes comparison between the variable value and the value on the right so you can add it in (Examples : If, for, while....etc)
Note :
in programming languages
x = 5 mean x becomes equal 5
 
OP
Tbol

Tbol

Member
Joined
Apr 7, 2019
Messages
154
Best answers
0
Reaction score
19
Thanks guys what about not to allow to search for GM/Admin?
 

Yalasari

Active Member
Joined
Jul 16, 2017
Messages
81
Best answers
8
Reaction score
44
try changing line 24 from
if target then
to
if target and target:getAccountType() == ACCOUNT_TYPE_NORMAL then
 

HjugO

Member
Joined
Feb 7, 2015
Messages
57
Best answers
3
Reaction score
11
Thanks guys what about not to allow to search for GM/Admin?
Lua:
elseif npcHandler.topic[cid] == 1 then
    if target and target:getAccountType() == ACCOUNT_TYPE_NORMAL then
        npcHandler:say("Indeed i know where " .. (target:getSex() == PLAYERSEX_FEMALE and "she" or "he") .. " is, however, this information will cost you " .. cost .. " gp. Are you willing to know too?", cid)
        position = target:getPosition()
        npcHandler.topic[cid] = 2
    else
        npcHandler:say("Unfortunately i didn\'t saw anybody of this name.", cid)
        npcHandler.topic[cid] = 0
    end
 
Last edited:

Andréew

Humble mapper.
Joined
Apr 14, 2015
Messages
719
Best answers
2
Reaction score
1,161
Location
Sweden
This would be awesome if worked on npc’s!

I feel like going to a npc at a specific location to find a player that is constantly moving is not working for me, before you get there player will be gone and you have to go back to npc to find the player again, and so on.

And exiva is out of the question i guess since why have a npc that does what the spell does?

Having so called ”hunter npc’s” to help you locate other quest npc’s or shops is something that i would find useful.
 
OP
Tbol

Tbol

Member
Joined
Apr 7, 2019
Messages
154
Best answers
0
Reaction score
19
This would be awesome if worked on npc’s!

I feel like going to a npc at a specific location to find a player that is constantly moving is not working for me, before you get there player will be gone and you have to go back to npc to find the player again, and so on.

And exiva is out of the question i guess since why have a npc that does what the spell does?

Having so called ”hunter npc’s” to help you locate other quest npc’s or shops is something that i would find useful.
Nah its enough to know a clue where he is. Its an realistic factor. If you know map well its enough to track an player and it makes stuff even more fun
 
Top