• 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 TROUBLE] New NPC isn't working

kessykins

Intermediate OT User
Joined
Mar 15, 2010
Messages
297
Reaction score
105
Hey,

As the title says, I'm having NPC troubles with a new npc.

I'm trying to make it so she'll accept a specific item for special fish bait but she isn't responding to the usual 'hi'

What am I doing wrong >.<
HTML:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState= {}
 
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 creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
 
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
        local evamsg = 'Here you are!!'
        local noimsg = 'What are you trying to do? You dont have the appropriate items!'
        local deny      = 'Not sure eh? Okay.'
  
 
--------------------MESSAGES------------------------------------------------------------------------------
    if msgcontains(msg, 'trade') then
                selfSay('I sell fish bait for (Deep-Sea Fishing), (Ice Fishing) and (Lava Fishing). What type of fishing do you plan on doing?', cid)
 
		if msgcontains(msg, 'help') then
		selfSay('To learn more about the different types of fishing speak with Fishing Guru, Marvin.', cid)
 
        elseif msgcontains(msg, 'Deep-Sea Fishing') then
        selfSay('The secret to Deep-Sea Fishing is to use the right kind of bait. I can sell you 100 special worms in exchange for 10 White Pearls. Interested?', cid)
        talkState[talkUser] = 1
 
    elseif msgcontains(msg, 'Ice Fishing') then
        selfSay('The secret to Ice Fishing is to use the right kind of bait. I can sell you 100 Shrimp in exchange for 3 Ice Cubes. Interested?', cid)
                talkState[talkUser] = 2
 
    elseif msgcontains(msg, 'Lava Fishing') then
        selfSay('The secret to Lava Fishing is to use the right kind of bait. I can sell you 100 Nails in exchange for 50 Talons. Interested?', cid)
                talkState[talkUser] = 3
 
 
-------------GETTING BAIT FROM HER-------------------
 
        -- Deep-Sea Fishing
        elseif talkState[talkUser] == 1 then
                if msgcontains(msg, 'yes') then
                        if doPlayerTakeItem(cid, ITEM_WHITE_PEARL, 10) == true then
                                doPlayerAddItem(cid, ITEM_WORM, 100)
                                selfSay(evamsg, cid)
                                talkState[talkUser] = 0
                        else
                                selfSay(noimsg, cid)
                                talkState[talkUser] = 0
                        end
                else
                        selfSay(deny, cid)
                        talkState[talkUser] = 0
                end
        -- Ice Fishing
        elseif talkState[talkUser] == 2 then
                if msgcontains (msg, 'yes') then
                        if doPlayerTakeItem(cid, ITEM_ICE_CUBE, 3) == true then
                                doPlayerAddItem(cid, ITEM_SHRIMP, 100)
                                selfSay(evamsg, cid)
                                talkState[talkUser] = 0
                        else
                                selfSay(noimsg, cid)
                                talkState[talkUser] = 0
                        end
                else
                        selfSay(deny, cid)
                        talkState[talkUser] = 0
                end
        -- Lava Fishing
        elseif talkState[talkUser] == 3 then
                if msgcontains (msg, 'yes') then
                        if doPlayerTakeItem(cid, ITEM_TALON, 50) == true then
                                doPlayerAddItem(cid, ITEM_NAIL, 100)
                                selfSay(evamsg, cid)
                                talkState[talkUser] = 0
                        else
                                selfSay(noimsg, cid)
                                talkState[talkUser] = 0
                        end
                else
                        selfSay(deny, cid)
                        talkState[talkUser] = 0
                end                        
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
end
end
 
Last edited:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic= {}

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 evamsg = 'Here you are!!'
local noimsg = 'What are you trying to do? You dont have the appropriate items!'
local deny      = 'Not sure eh? Okay.'

function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	elseif msgcontains(msg, 'trade') then
		selfSay('I sell fish bait for (Deep-Sea Fishing), (Ice Fishing) and (Lava Fishing). What type of fishing do you plan on doing?', cid)
		Topic[cid] = 0
	elseif msgcontains(msg, 'help') then
		selfSay('To learn more about the different types of fishing speak with Fishing Guru, Marvin.', cid)
		Topic[cid] = 0
	elseif msgcontains(msg, 'Deep-Sea Fishing') then
		selfSay('The secret to Deep-Sea Fishing is to use the right kind of bait. I can sell you 100 special worms in exchange for 10 White Pearls. Interested?', cid)
		Topic[cid] = 1
	elseif msgcontains(msg, 'Ice Fishing') then
		selfSay('The secret to Ice Fishing is to use the right kind of bait. I can sell you 100 Shrimp in exchange for 3 Ice Cubes. Interested?', cid)
		Topic[cid] = 2
	elseif msgcontains(msg, 'Lava Fishing') then
		selfSay('The secret to Lava Fishing is to use the right kind of bait. I can sell you 100 Nails in exchange for 50 Talons. Interested?', cid)
		Topic[cid] = 3


-------------GETTING BAIT FROM HER-------------------

	-- Deep-Sea Fishing
	elseif Topic[cid] == 1 then
		if msgcontains(msg, 'yes') then
			if doPlayerRemoveItem(cid, ITEM_WHITE_PEARL, 10) then
				doPlayerAddItem(cid, ITEM_WORM, 100)
				selfSay(evamsg, cid)
			else
				selfSay(noimsg, cid)
			end
		else
			selfSay(deny, cid)
		end
		Topic[cid] = 0
	-- Ice Fishing
	elseif Topic[cid] == 2 then
		if msgcontains (msg, 'yes') then
			if doPlayerRemoveItem(cid, ITEM_ICE_CUBE, 3) then
				doPlayerAddItem(cid, ITEM_SHRIMP, 100)
				selfSay(evamsg, cid)
			else
				selfSay(noimsg, cid)
			end
		else
			selfSay(deny, cid)
		end
		Topic[cid] = 0
	-- Lava Fishing
	elseif Topic[cid] == 3 then
		if msgcontains (msg, 'yes') then
			if doPlayerRemoveItem(cid, ITEM_TALON, 50) then
				doPlayerAddItem(cid, ITEM_NAIL, 100)
				selfSay(evamsg, cid)
			else
				selfSay(noimsg, cid)
			end
		else
			selfSay(deny, cid)
		end                   
		Topic[cid] = 0     
	end
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
It's probably because of the hyphen. It is a magic character that's used in patterns in Lua.
Code:
	elseif msgcontains(msg, 'Deep[B][COLOR="red"][SIZE="5"]-[/SIZE][/COLOR][/B]Sea Fishing') then
Remove it, and it will hopefully work.
 
Cykotitan.. you're awesome! IT WORKS!! I'm so happy =DD

cykotitanrocks.pngp


+++REP!
 
Back
Top