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

Help with a NPC

furstwin

New Member
Joined
Aug 9, 2007
Messages
486
Reaction score
1
Location
Sweden
PHP:
local talkNode = 0

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

-- OTServ event handling functions start
function onCreatureSay(cid, type, msg)                             npcHandler:onCreatureSay(cid, type, msg) end
function onThingMove(creature, thing, oldpos, oldstackpos)                 npcHandler:onThingMove(creature, thing, oldpos, oldstackpos) end
function onCreatureAppear(creature)                             npcHandler:onCreatureAppear(creature) end
function onCreatureDisappear(id)                             npcHandler:onCreatureDisappear(id) end
function onCreatureTurn(creature)                             npcHandler:onCreatureTurn(creature) end
function onCreatureChangeOutfit(creature)                         npcHandler:onCreatureChangeOutfit(creature) end
function onThink()                                     npcHandler:onThink() end
-- OTServ event handling functions end


local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)
        
function creatureSayCallback(cid, type, msg)
    if(npcHandler.focus ~= cid) then
        return false
    end

    local queststatus = getPlayerStorageValue(cid, 9517)
    local diary = doPlayerRemoveItem(cid, 1985,1)
    local diaryStatus = getPlayerStorageValue(cid, 1985)


-- getmission --        
    if msgcontains(msg, 'mission') then
        if queststatus < 1 then
            npcHandler:say("I have lost my diary... I were exploring east of Rhyves when they came, could you please find it?")
            talkNode = 1   
        end
    end

-- Confirm yes --
    if msgcontains(msg, 'yes') then
        if talkNode == 1 then
            if queststatus < 1 then
                npcHandler:say("Go and find it brave warrior!")
                setPlayerStorageValue(cid, 9517, 1)
                focus = 0
                talkNode = 0
            else
                npcHandler:say("Get lost!")
            end
        elseif talkNode == 2 then
            if queststatus == 1 then
                if diaryStatus == 1 then
                    selfSay('Thank you! Here you got some money!')
                    doPlayerAddItem(cid,2152,27)
                    doRemoveItem(cid,1985,1)
                    setPlayerStorageValue(cid, 9517, 2)
                    focus = 0
                else
                    selfSay('You don\'t have my diary.')
                end
            end
        end
    end
    
-- Confirm no --
    if msgcontains(msg, 'no') then
        if talkNode == 1 then
            selfSay("Come back when you have grown up!")
            talk_state = 0
        elseif talkNode == 2 then
            selfSay('Please find it for me.')
            talkNode = 0
        end
    end
    
    if msgcontains(msg, 'diary') then
        selfSay("Did you find my diary?")
        talkNode = 2  
    end

    return TRUE
end



npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
-- Makes sure the npc reacts when you say hi, bye etc.
npcHandler:addModule(FocusModule:new())

00:50 Imforital [3]: hi
00:50 Mission: Welcome, Imforital! I have been expecting you.
00:50 Imforital [3]: mission
00:50 Mission: I have lost my diary... I were exploring east of Rhyves when they came, could you please find it?
00:50 Imforital [3]: yes
00:50 Mission: Go and find it brave warrior!
00:50 You have found Lisas diary..
00:50 Imforital [3]: diary
(Here he takes the book)
00:50 Mission: Did you find my diary?
00:50 Imforital [3]: yes
(Here he remove the quest box and give me money, and the quest box shouldnt dissapear)
00:50 Mission: Thank you! Here you got some money!
00:51 Mission: Good bye, Imforital!

I want it to be like:

00:50 Imforital [3]: hi
00:50 Mission: Welcome, Imforital! I have been expecting you.
00:50 Imforital [3]: mission
00:50 Mission: I have lost my diary... I were exploring east of Rhyves when they came, could you please find it?
00:50 Imforital [3]: yes
00:50 Mission: Go and find it brave warrior!
00:50 You have found Lisas diary..
00:50 Imforital [3]: diary
00:50 Mission: Did you find my diary?
00:50 Imforital [3]: yes
(Here he takes the book, give me 27 platinum coins)
00:50 Mission: Thank you! Here you got some money!
00:51 Mission: Good bye, Imforital!


Sincerely,
Furswin.
 
Last edited:
Code:
[COLOR=#000000][COLOR=#0000bb]local talkNode [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]0

local keywordHandler [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]KeywordHandler[/COLOR][COLOR=#007700]:new()
[/COLOR][COLOR=#0000bb]local npcHandler [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]NpcHandler[/COLOR][COLOR=#007700]:new([/COLOR][COLOR=#0000bb]keywordHandler[/COLOR][COLOR=#007700])
[/COLOR][COLOR=#0000bb]NpcSystem[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]parseParameters[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]npcHandler[/COLOR][COLOR=#007700])

-- [/COLOR][COLOR=#0000bb]OTServ event handling functions start
[/COLOR][COLOR=#007700]function [/COLOR][COLOR=#0000bb]onCreatureSay[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]cid[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]type[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]msg[/COLOR][COLOR=#007700])                             [/COLOR][COLOR=#0000bb]npcHandler[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000bb]onCreatureSay[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]cid[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]type[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]msg[/COLOR][COLOR=#007700]) [/COLOR][COLOR=#0000bb]end
[/COLOR][COLOR=#007700]function [/COLOR][COLOR=#0000bb]onThingMove[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]creature[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]thing[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]oldpos[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]oldstackpos[/COLOR][COLOR=#007700])                 [/COLOR][COLOR=#0000bb]npcHandler[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000bb]onThingMove[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]creature[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]thing[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]oldpos[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]oldstackpos[/COLOR][COLOR=#007700]) [/COLOR][COLOR=#0000bb]end
[/COLOR][COLOR=#007700]function [/COLOR][COLOR=#0000bb]onCreatureAppear[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]creature[/COLOR][COLOR=#007700])                             [/COLOR][COLOR=#0000bb]npcHandler[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000bb]onCreatureAppear[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]creature[/COLOR][COLOR=#007700]) [/COLOR][COLOR=#0000bb]end
[/COLOR][COLOR=#007700]function [/COLOR][COLOR=#0000bb]onCreatureDisappear[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]id[/COLOR][COLOR=#007700])                             [/COLOR][COLOR=#0000bb]npcHandler[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000bb]onCreatureDisappear[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]id[/COLOR][COLOR=#007700]) [/COLOR][COLOR=#0000bb]end
[/COLOR][COLOR=#007700]function [/COLOR][COLOR=#0000bb]onCreatureTurn[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]creature[/COLOR][COLOR=#007700])                             [/COLOR][COLOR=#0000bb]npcHandler[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000bb]onCreatureTurn[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]creature[/COLOR][COLOR=#007700]) [/COLOR][COLOR=#0000bb]end
[/COLOR][COLOR=#007700]function [/COLOR][COLOR=#0000bb]onCreatureChangeOutfit[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]creature[/COLOR][COLOR=#007700])                         [/COLOR][COLOR=#0000bb]npcHandler[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000bb]onCreatureChangeOutfit[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]creature[/COLOR][COLOR=#007700]) [/COLOR][COLOR=#0000bb]end
[/COLOR][COLOR=#007700]function [/COLOR][COLOR=#0000bb]onThink[/COLOR][COLOR=#007700]()                                     [/COLOR][COLOR=#0000bb]npcHandler[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000bb]onThink[/COLOR][COLOR=#007700]() [/COLOR][COLOR=#0000bb]end
[/COLOR][COLOR=#007700]-- [/COLOR][COLOR=#0000bb]OTServ event handling functions end


local shopModule [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]ShopModule[/COLOR][COLOR=#007700]:new()
[/COLOR][COLOR=#0000bb]npcHandler[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000bb]addModule[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]shopModule[/COLOR][COLOR=#007700])
        
function [/COLOR][COLOR=#0000bb]creatureSayCallback[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]cid[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]type[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]msg[/COLOR][COLOR=#007700])
    if([/COLOR][COLOR=#0000bb]npcHandler[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]focus [/COLOR][COLOR=#007700]~= [/COLOR][COLOR=#0000bb]cid[/COLOR][COLOR=#007700]) [/COLOR][COLOR=#0000bb]then
        [/COLOR][COLOR=#007700]return [/COLOR][COLOR=#0000bb]false
    end

    local queststatus [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]getPlayerStorageValue[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]cid[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]9517[/COLOR][COLOR=#007700])[/COLOR][COLOR=#007700]
    [/COLOR][COLOR=#0000bb]local diaryStatus [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]getPlayerStorageValue[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]cid[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]1985[/COLOR][COLOR=#007700])


-- [/COLOR][COLOR=#0000bb]getmission [/COLOR][COLOR=#007700]--        
    if [/COLOR][COLOR=#0000bb]msgcontains[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]msg[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]'mission'[/COLOR][COLOR=#007700]) [/COLOR][COLOR=#0000bb]then
        [/COLOR][COLOR=#007700]if [/COLOR][COLOR=#0000bb]queststatus [/COLOR][COLOR=#007700]< [/COLOR][COLOR=#0000bb]1 then
            npcHandler[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000bb]say[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"I have lost my diary... I were exploring east of Rhyves when they came, could you please find it?"[/COLOR][COLOR=#007700])
            [/COLOR][COLOR=#0000bb]talkNode [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]1   
        end
    end

[/COLOR][COLOR=#007700]-- [/COLOR][COLOR=#0000bb]Confirm yes [/COLOR][COLOR=#007700]--
    if [/COLOR][COLOR=#0000bb]msgcontains[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]msg[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]'yes'[/COLOR][COLOR=#007700]) [/COLOR][COLOR=#0000bb]then
        [/COLOR][COLOR=#007700]if [/COLOR][COLOR=#0000bb]talkNode [/COLOR][COLOR=#007700]== [/COLOR][COLOR=#0000bb]1 then
            [/COLOR][COLOR=#007700]if [/COLOR][COLOR=#0000bb]queststatus [/COLOR][COLOR=#007700]< [/COLOR][COLOR=#0000bb]1 then
                npcHandler[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000bb]say[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"Go and find it brave warrior!"[/COLOR][COLOR=#007700])
                [/COLOR][COLOR=#0000bb]setPlayerStorageValue[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]cid[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]9517[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700])
                [/COLOR][COLOR=#0000bb]focus [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]0
                talkNode [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]0
            [/COLOR][COLOR=#007700]else
                [/COLOR][COLOR=#0000bb]npcHandler[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000bb]say[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"Get lost!"[/COLOR][COLOR=#007700])
            [/COLOR][COLOR=#0000bb]end
        [/COLOR][COLOR=#007700]elseif [/COLOR][COLOR=#0000bb]talkNode [/COLOR][COLOR=#007700]== [/COLOR][COLOR=#0000bb]2 then
            [/COLOR][COLOR=#007700]if [/COLOR][COLOR=#0000bb]queststatus [/COLOR][COLOR=#007700]== [/COLOR][COLOR=#0000bb]1 then
                [/COLOR][COLOR=#007700]if [/COLOR][COLOR=#0000bb]diaryStatus [/COLOR][COLOR=#007700]== [/COLOR][COLOR=#0000bb]1 then
                    selfSay[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]'Thank you! Here you got some money!'[/COLOR][COLOR=#007700])
                    [/COLOR][COLOR=#0000bb]doPlayerAddItem[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]cid[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000bb]2152[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000bb]27[/COLOR][COLOR=#007700])
                    [/COLOR][COLOR=#0000bb]doPlayerRemoveItem[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]cid[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000bb]1985[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700])
                    [/COLOR][COLOR=#0000bb]setPlayerStorageValue[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]cid[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]9517[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]2[/COLOR][COLOR=#007700])
                    [/COLOR][COLOR=#0000bb]focus [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]0
                [/COLOR][COLOR=#007700]else
                    [/COLOR][COLOR=#0000bb]selfSay[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]'You don\'t have my diary.'[/COLOR][COLOR=#007700])
                [/COLOR][COLOR=#0000bb]end
            end
        end
    end
    
[/COLOR][COLOR=#007700]-- [/COLOR][COLOR=#0000bb]Confirm no [/COLOR][COLOR=#007700]--
    if [/COLOR][COLOR=#0000bb]msgcontains[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]msg[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]'no'[/COLOR][COLOR=#007700]) [/COLOR][COLOR=#0000bb]then
        [/COLOR][COLOR=#007700]if [/COLOR][COLOR=#0000bb]talkNode [/COLOR][COLOR=#007700]== [/COLOR][COLOR=#0000bb]1 then
            selfSay[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"Come back when you have grown up!"[/COLOR][COLOR=#007700])
            [/COLOR][COLOR=#0000bb]talk_state [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]0
        [/COLOR][COLOR=#007700]elseif [/COLOR][COLOR=#0000bb]talkNode [/COLOR][COLOR=#007700]== [/COLOR][COLOR=#0000bb]2 then
            selfSay[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]'Please find it for me.'[/COLOR][COLOR=#007700])
            [/COLOR][COLOR=#0000bb]talkNode [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]0
        end
    end
    
    [/COLOR][COLOR=#007700]if [/COLOR][COLOR=#0000bb]msgcontains[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]msg[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]'diary'[/COLOR][COLOR=#007700]) [/COLOR][COLOR=#0000bb]then
        selfSay[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"Did you find my diary?"[/COLOR][COLOR=#007700])
        [/COLOR][COLOR=#0000bb]talkNode [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]2  
    end

    [/COLOR][COLOR=#007700]return [/COLOR][COLOR=#0000bb]TRUE
end



npcHandler[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000bb]setCallback[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]CALLBACK_MESSAGE_DEFAULT[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]creatureSayCallback[/COLOR][COLOR=#007700])
-- [/COLOR][COLOR=#0000bb]Makes sure the npc reacts when you say hi[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]bye etc[/COLOR][COLOR=#007700].
[/COLOR][COLOR=#0000bb]npcHandler[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000bb]addModule[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]FocusModule[/COLOR][COLOR=#007700]:new()) [/COLOR][/COLOR]
Try
 
Back
Top