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

Whats wrong with this NPC? >.<

furstwin

New Member
Joined
Aug 9, 2007
Messages
486
Reaction score
1
Location
Sweden
Code:
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

	queststatus = getPlayerStorageValue(cid, 9517)
	dairy = doPlayerRemoveItem(cid, 1985, 1)
	dairyStatus = getPlayerStorageValue(cid, 1985)


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

-- Confirm yes --
elseif msgcontains(msg, 'yes') and talk_state == 1 and queststatus == -1 then
		npcHandler:say("Go and find it brave warrior!")
		setPlayerStorageValue(cid, 9517, 1)
		focus = 0
else
npcHandler:say("You have already accepted this task..")
end

elseif msgcontains(msg, 'no') and talk_state == 1 then
		npcHandler:say("Come back when you have grown up!")
		talk_state = 0
end
	
elseif msgcontains(msg, 'dairy') then
npcHandler:say("Did you find my dairy?")
talk_state = 2	

elseif msgcontains(msg, 'yes') and talk_state == 2 and dairy == TRUE and dairyStatus == TRUE then
npcHandler:say("Thank you! Here you got some money!")
		doPlayerAddItem(cid, 2152, 27)
		focus = 0
else
npcHandler:say("You dont have my dairy.")
end

elseif msgcontains(msg, 'no') and talk_state == 2 then
		npcHandler:say("Please find it for me.")
		talk_state = 0

	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())

Heres the Error
Code:
Warning: [NpcScript::NpcScript] Can not load script. data/npc/scripts/Mission.lu
a
data/npc/scripts/Mission.lua:43: 'end' expected (to close 'function' at line 19)
 near 'elseif'

I'd be really thank full if you help me =)
(Im using the latest TFS)

sincerely,
Furstwin.
 
Last edited by a moderator:
EVERYTHING is wrong with it. I take back what I said to the guy I tried to help earlier... THIS is the messiest script I've ever seen... o.O I'll try to help you.
 
I'll try to help you
... Doesn't that tell you that I'm going to help him? I'll edit this post soon.


EDIT: Try this, it should work.

Code:
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 dairy = doPlayerRemoveItem(cid, 1985, 1)
    local dairyStatus = getPlayerStorageValue(cid, 1985)


-- getmission --        
    if msgcontains(msg, 'mission') then
        if queststatus < 1 then
            npcHandler:say("I have lost my dairy... 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("You have already accepted this task..")
            end
        elseif talkNode == 2 then
            if queststatus == 1 then
                if dairyStatus == 1 then
                    selfSay('Thank you! Here you got some money!')
                    doPlayerAddItem(cid, 2152, 27)
                    setPlayerStorageValue(cid, 9517, 2)
                    focus = 0
                else
                    selfSay('You don\'t have my dairy.')
                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, 'dairy') then
        selfSay("Did you find my dairy?")
        talk_state = 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())
 
Last edited:
18:58 Imforital [3]: hi
18:58 Mission: Welcome, Imforital! I have been expecting you.
18:58 Imforital [3]: mission
18:58 Mission: I have lost my dairy... I were exploring east of Rhyves when they came, could you please find it?
18:58 Imforital [3]: yes
18:58 Mission: Go and find it brave warrior!
18:58 You have found Lisas dairy..
18:58 Imforital [3]: hi
18:58 Mission: Welcome, Imforital! I have been expecting you.
18:58 Imforital [3]: dairy
(Here he took the dairy)
18:58 Mission: Did you find my dairy?
18:58 Imforital [3]: yes
Here he should have taken it and give me the money <.<
 
Try this one:
Code:
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("You have already accepted this task..")
            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?")
        talk_state = 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())
 
I'll help you but first i'll move you to the lua section

i'v edite it very fast but try it out

Code:
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

	queststatus = getPlayerStorageValue(cid, 9517)
	dairy = doPlayerRemoveItem(cid, 1985, 1)
	dairyStatus = getPlayerStorageValue(cid, 1985)


                 -- getmission --		
            if msgcontains(msg, 'mission') then
               selfSay('I have lost my dairy... I were exploring east of Rhyves when they came, could you please find it?')
            talk_state = 1	

            -- Confirm yes --
            elseif msgcontains(msg, 'yes') and talk_state == 1 then
                if queststatus == -1 then
                   selfSay('Go and find it brave warrior!')
                   setPlayerStorageValue(cid, 9517, 1)
            else
            selfSay('You have already accepted this task.')
            end
	
            elseif msgcontains(msg, 'dairy') then
                   selfSay('Did you find my dairy?')
                   talk_state = 2	
            elseif msgcontains(msg, 'yes') and talk_state == 2 and dairy == TRUE and dairyStatus == TRUE then
                   selfSay('Thank you! Here you got some money!')
		        doPlayerAddItem(cid, 2152, 27)
            else
                selfSay('You dont have my dairy.')
                end

        elseif msgcontains(msg, 'no') and talk_state == 1 or talk_state == 2 then
		        selfSay("Come back when you have grown up!")
		        talk_state = 0
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
-- Makes sure the npc reacts when you say hi, bye etc.
npcHandler:addModule(FocusModule:new())
 
Last edited:
I made some changes and now all works perfectly except that the book doesnt remove, the quest chest where you get the book does! >.<
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)
    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("You have already accepted this task..")
            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())
 
Last edited:
Back
Top