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

NPC problem

Rith

New Member
Joined
Jun 14, 2007
Messages
176
Reaction score
0
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local talktopic, town, destination = {}, {}, {}

--Home Town setup
local city1 = {name = "Ab'dendriel", id = 1, destination = {x=702, y=1016, z=7},
text = "So it's Ab'dendriel y'wanna live in? What y'say, yes or no?"}

local city2 = {name = "Carlin", id = 2, destination = {x=1153, y=1139, z=7},
text = "So it's Carlin y'wanna live in? What y'say, yes or no?"}

local city3 = {name = "Darashia", id = 3, destination = {x=1153, y=1139, z=7},
text = "So it's Darashia y'wanna live in? What y'say, yes or no?"}

local city4 = {name = "Edron", id = 4, destination = {x=1153, y=1139, z=7},
text = "So it's Edron y'wanna live in? What y'say, yes or no?"}

local city5 = {name = "Liberty bay", id = 4, destination = {x=1153, y=1139, z=7},
text = "So it's Libert y Bayy'wanna live in? What y'say, yes or no?"}

local city6 = {name = "Thais", id = 2, destination = {x=32369, y=32241, z=7},
text = "So it's Thais y'wanna live in? What y'say, yes or no?"}

local city7 = {name = "Venore", id = 4, destination = {x=1153, y=1139, z=7},
text = "So it's Venore y'wanna live in? What y'say, yes or no?"}


local towntext = "What city do you wish to live in? {".. city1.name .."}, {".. city2.name .."}, {".. city3.name .."}, {".. city4.name .."}, {".. city5.name .."}, {".. city6.name .."} or {".. city7.name .."}?"


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

        if(getPlayerLevel(cid) < requiredlevel) then
                npcHandler:say(lowlevel, cid)
                return false
        else
                local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
                talktopic[talkUser], town[talkUser], destination[talkUser] = 0, 0, 0
                return true
        end
end

function creatureSayCallback(cid, type, msg)

talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

        if(not npcHandler:isFocused(cid)) then
                return false
        end

        --Select Home Town control
                if talktopic[talkUser] == 0 and msgcontains(msg, "yes") then
                        talktopic[talkUser] = 1 --question one, what city do you want?
                        npcHandler:say(towntext, cid)
                       
                        elseif talktopic[talkUser] == 0 and msgcontains(msg, "no") then
                                talktopic[talkUser] = 0
                                npcHandler:unGreet(cid)
                       
                                elseif talktopic[talkUser] == 1 and msgcontains(msg, city1.name) then
                                        town[talkUser] = city1.id
                                        destination[talkUser] = city1.destination
                                        npcHandler:say(city1.text, cid)
                                        talktopic[talkUser] = 2 --question two, are  you sure?
                                       
                                elseif talktopic[talkUser] == 1 and msgcontains(msg, city2.name) then
                                        town[talkUser] = city2.id
                                        destination[talkUser] = city2.destination
                                        npcHandler:say(city2.text, cid)
                                        talktopic[talkUser] = 2 --question two, are  you sure?
                                       
                                elseif talktopic[talkUser] == 1 and msgcontains(msg, city3.name) then
                                        town[talkUser] = city3.id
                                        destination[talkUser] = city3.destination
                                        npcHandler:say(city3.text, cid)
                                        talktopic[talkUser] = 2 --question two, ware  you sure?
										
								elseif talktopic[talkUser] == 1 and msgcontains(msg, city4.name) then
                                        town[talkUser] = city4.id
                                        destination[talkUser] = city4.destination
                                        npcHandler:say(city4.text, cid)
                                        talktopic[talkUser] = 2 --question two, are  you sure?
										
								elseif talktopic[talkUser] == 1 and msgcontains(msg, city5.name) then
                                        town[talkUser] = city5.id
                                        destination[talkUser] = city5.destination
                                        npcHandler:say(city5.text, cid)
                                        talktopic[talkUser] = 2 --question two, are  you sure?
										
								elseif talktopic[talkUser] == 1 and msgcontains(msg, city6.name) then
                                        town[talkUser] = city6.id
                                        destination[talkUser] = city6.destination
                                        npcHandler:say(city6.text, cid)
                                        talktopic[talkUser] = 2 --question two, are  you sure?
										
								elseif talktopic[talkUser] == 1 and msgcontains(msg, city7.name) then
                                        town[talkUser] = city7.id
                                        destination[talkUser] = city7.destination
                                        npcHandler:say(city7.text, cid)
                                        talktopic[talkUser] = 2 --question two, are  you sure?
                             
							    elseif talktopic[talkUser] == 2 and msgcontains(msg, 'yes') then
                                        doPlayerSetVocation(cid, vocation[talkUser])
                                        doPlayerSetTown(cid, town[talkUser])
                                        npcHandler:resetNpc()
					                    local tmp = getCreaturePosition(cid)
                                        doTeleportThing(cid, destination[talkUser])
                                        doSendMagicEffect(tmp, CONST_ME_POFF)
                                        doSendMagicEffect(destination, CONST_ME_TELEPORT)
                       
                                elseif talktopic[talkUser] == 2 and msgcontains(msg, 'no') then
                                        talktopic[talkUser] = 0
                                        npcHandler:unGreet(cid)                 
                                        
                        						end
                         return true
			  end
               
    
               
        

npcHandler:setMessage(MESSAGE_GREET, "Harrr, a new sailor! Can't wait to get off this lousy island and head for adventure, eh? Want me to bring ya somewhere nice, |PLAYERNAME|?")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Goodbye adventurer!")
npcHandler:setMessage(MESSAGE_FAREWELL, "come back when you are ready!")

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
\
It' doesnt work, could anyone help me?
 
Back
Top