• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

NPC Support!

Ancores

Active Member
Joined
Jan 17, 2010
Messages
538
Reaction score
28
I'm a total noob in scripting npcs and can't get this to work lol.

I want to change the talk_state when saying "huhu" to the npc to talk_state 50 and then if I say "bye" or leave the npcs the talk_state should be changed back to 0 so I can say huhu again.

LUA:
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)
	talk_state = 0                    
end
function onCreatureSay(cid, type, msg)                  npcHandler:onCreatureSay(cid, type, msg)                end
function onThink()                                      npcHandler:onThink()                                    end
function creatureSayCallback(cid, type, msg)
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	if(not npcHandler:isFocused(cid)) then 
        talk_state = 0 
        return false 
    end 
	
	if msgcontains(msg, 'huhu') and talk_state ~= 50 then			
		npcHandler:say("Lalala", cid)
		talk_state = 50
	end
	return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

When I say "hi", "huhu" the first time it works and changes to talk_state 50, but then if I say "bye" and then "hi", "huhu" it doesn't work because the talk_state hasn't changed.
But if I say something (just some random letters) when he isn't focused (after saying bye) the talk_state changes back to 0 oO
 
Last edited:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic = {}

function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) Topic[cid] = nil npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end

function greetCallback(cid)
	Topic[cid] = 0
	return true
end

function farewellCallback(cid)
	Topic[cid] = nil
	return true
end

function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	elseif msgcontains(msg, 'huhu') and Topic[cid] ~= 50 then                  
		npcHandler:say('Lalala', cid)
		Topic[cid] = 50
	end
	return true
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_FAREWELL, farewellCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Here:
Edit: Cykotian is too fast. =o

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

function greetCallback(cid)
	Topic[cid] = 0
	return true
end

function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	elseif msgcontains(msg, "huhu") then
		npcHandler:say("Lalala, cid)
	end
end

npcHandler:addModule(FocusModule:new())
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
@Cyko
It works but he doesn't say anything when saying bye and still focuses on the player. :o

@Black Reaper
Works nice

Thanks both of you
 
Back
Top