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

Lua NPC's don't respond?

Ecstacy

Mothafuckaaa
Joined
Dec 26, 2008
Messages
3,836
Reaction score
108
Location
The Netherlands
Hey,

I'm having a problem with the NPC system of TFS.
No custom made npc responds :s.

Npc file:
Lua:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Private" script="privacc.lua" walkinterval="2000" floorchange="0">
	<health now="100" max="100"/>
	<look type="134" head="78" body="88" legs="0" feet="88" addons="3"/>
</npc>

Npc dummy script:
Lua:
local keywordHandler = KeywordHandler:new()--------------------------------------------------
local npcHandler = NpcHandler:new(keywordHandler)--------------------------------------------
NpcSystem.parseParameters(npcHandler)--------------------------------------------------------
---------------------------------------------------------------------------------------------
---OTServ event handling functions start-----------------------------------------------------
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----------------------
---OTServ event handling functions end-------------------------------------------------------
---------------------------------------------------------------------------------------------
local topic,name,pass = {},{},{}
function creatureSayCallback(cid, type, msg)
	if msgcontains(msg:lower(),'hi')
		if getPlayerLevel(cid) < 200 then
			npcHandler:say('hello',cid)
			topic[cid] = 1
		else
			npcHandler:say('kanker',cid)
		end
	elseif topic[cid] == 1 then
		if msgcontains(msg:lower(),'kanker') then
			npcHandler:say('ok mon, ganja is die shit',cid)
			topic[cid] = 0
		else
			npcHandler:say('ganja',cid)
			topic[cid] = 0
		end
	end
	return true
end
 
I think this might work
Lua:
local keywordHandler = KeywordHandler:new()--------------------------------------------------
local npcHandler = NpcHandler:new(keywordHandler)--------------------------------------------
NpcSystem.parseParameters(npcHandler)--------------------------------------------------------
---------------------------------------------------------------------------------------------
---OTServ event handling functions start-----------------------------------------------------
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----------------------
---OTServ event handling functions end-------------------------------------------------------
---------------------------------------------------------------------------------------------
local topic,name,pass = {},{},{}
function creatureSayCallback(cid, type, msg)
	if msgcontains(msg:lower(),'hi')
		if getPlayerLevel(cid) < 200 then
			npcHandler:say('hello',cid)
			topic[cid] = 1
		else
			npcHandler:say('kanker',cid)
		end
	elseif topic[cid] == 1 then
		if msgcontains(msg:lower(),'kanker') then
			npcHandler:say('ok mon, ganja is die shit',cid)
			topic[cid] = 0
		else
			npcHandler:say('ganja',cid)
			topic[cid] = 0
		end
	end
	return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

or else try to replace
Lua:
topic[cid] = 1
to
Lua:
talkState[talkUser] = 1

I am not a good NPC scripter but to me it looks fine.

Or he just arrogant that he ignores you :eek:
 
not the problem as this doesn't even work :s?

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

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 buyAddons(cid, message, keywords, parameters, node)
	if msgcontains(msg,'ganja') then
		npcHandler:say('Ja mon',cid)
	end
end

edit:
normal npcs scripts do work
 
Sorry guys have to say this in Dutch. This npc is to evul to translate in English haha:
Vanwaar deze vloekende npc maat?

This is Grof, the Guard. Edit this with your text.

Code:
  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 storage = getPlayerStorageValue(cid, 1889)

if msgcontains(msg, 'trouble') then
	if storage == 16 then
		npcHandler:say("I think it'll rain soon and I left some laundry out for drying.", cid)
		setPlayerStorageValue(cid, 1889, 17)
	else
		npcHandler:say("I don't feel like chatting.", cid)
	end
elseif msgcontains(msg, 'authorities') then	
	if storage == 17 then
		npcHandler:say("Yes I'm pretty sure they have failed to send the laundry police to take care of it, you fool.", cid)
		setPlayerStorageValue(cid, 1889, 18)
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_HOLYAREA)
	else
		npcHandler:say("I don't feel like chatting.", cid)
	end
end
return TRUE
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
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)			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

if(msgcontains(msg, 'kanker')) then
			npcHandler:say('ok mon, ganja is die shit',cid)
		else
			npcHandler:say('ganja',cid)
	end
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

But I don´t really see the meaning of this script :p.. why you would even want it
 
it was just a quick test if it would work or not, does now but this script doesnt.

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)                     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 storage = getPlayerStorageValue(cid, 1889)

	local s,l = 50124,100,0,0 -- storage&level.
	if getPlayerStorageValue(cid,s) <= 0 then
		if msgcontains(msg:lower(),'yes') then
			if getPlayerLevel(cid) >= 200 then
				npcHandler:say('Then lets get on, creating your private account. what do you wish as username?',cid)
				talkState[talkUser] = 1
			else
				npcHandler:say('You must reach level '..l..' before being able to create a private account.',cid)
				npcHandler:releaseFocus(cid)
				talkState[talkUser] = 0
			end
		elseif talkState[talkUser] == 1 then
			if string.find(msg,'%s') then
				npcHandler:say('You can\'t use a space in your username, please try again.',cid)
				talkState[talkUser] = 1
			else
				setPlayerStorageValue(cid,1890,msg:lower())
				npcHandler:say('Are you sure you want "'..getPlayerStorageValue(cid,1890)..'" to be your username?',cid)
				talkState[talkUser] = 2
			end
		elseif talkState[talkUser] == 2 then
			if msgcontains(msg:lower(),'yes') then
				npcHandler:say('Ok, then lets continue to the password, what do you wish to have as password?',cid)
				talkState[talkUser] = 3
			else
				npcHandler:say('Alright, no problem, what do you want as username then?',cid)
				talkState[talkUser] = 1
			end
		elseif talkState[talkUser] == 3 then
			if string.find(msg,'%s') then
				npcHandler:say('You can\'t use a space in your password, please try again.',cid)
				talkState[talkUser] = 3
			else
				setPlayerStorageValue(cid,1891,msg:lower())
				npcHandler:say('Are you sure you want "'..getPlayerStorageValue(cid,1891)..'" to be your password?',cid)
				talkState[talkUser] = 4
			end
		elseif talkState[talkUser] == 4 then
			if msgcontains(msg:lower(),'yes') then
				db.executeQuery("INSERT INTO `accounts` (`id`, `name`, `password`, `premdays`, `lastday`, `email`, `key`, `blocked`, `warnings`, `group_id`) VALUES (NULL, '"..getPlayerStorageValue(cid,1890).."', '"..getPlayerStorageValue(cid,1891).."', '0', '0', '', '0', '0', '0', '1');")
				setPlayerStorageValue(cid,s,1)
				npcHandler:say('Ok, your account has been created!',cid)
				talkState[talkUser] = 0
			else
				npcHandler:say('Alright, no problem, what do you want as password then?',cid)
				talkState[talkUser] = 3
			end
		end
	else
		npcHandler:say('You can only make a private account once.',cid)
		npcHandler:releaseFocus(cid)
	end
return TRUE
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
it was just a quick test if it would work or not, does now but this script doesnt.

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)                     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 storage = getPlayerStorageValue(cid, 1889)

	local s,l = 50124,100,0,0 -- storage&level.
	if getPlayerStorageValue(cid,s) <= 0 then
		if msgcontains(msg:lower(),'yes') then
			if getPlayerLevel(cid) >= 200 then
				npcHandler:say('Then lets get on, creating your private account. what do you wish as username?',cid)
				talkState[talkUser] = 1
			else
				npcHandler:say('You must reach level '..l..' before being able to create a private account.',cid)
				npcHandler:releaseFocus(cid)
				talkState[talkUser] = 0
			end
		elseif talkState[talkUser] == 1 then
			if string.find(msg,'%s') then
				npcHandler:say('You can\'t use a space in your username, please try again.',cid)
				talkState[talkUser] = 1
			else
				setPlayerStorageValue(cid,1890,msg:lower())
				npcHandler:say('Are you sure you want "'..getPlayerStorageValue(cid,1890)..'" to be your username?',cid)
				talkState[talkUser] = 2
			end
		elseif talkState[talkUser] == 2 then
			if msgcontains(msg:lower(),'yes') then
				npcHandler:say('Ok, then lets continue to the password, what do you wish to have as password?',cid)
				talkState[talkUser] = 3
			else
				npcHandler:say('Alright, no problem, what do you want as username then?',cid)
				talkState[talkUser] = 1
			end
		elseif talkState[talkUser] == 3 then
			if string.find(msg,'%s') then
				npcHandler:say('You can\'t use a space in your password, please try again.',cid)
				talkState[talkUser] = 3
			else
				setPlayerStorageValue(cid,1891,msg:lower())
				npcHandler:say('Are you sure you want "'..getPlayerStorageValue(cid,1891)..'" to be your password?',cid)
				talkState[talkUser] = 4
			end
		elseif talkState[talkUser] == 4 then
			if msgcontains(msg:lower(),'yes') then
				db.executeQuery("INSERT INTO `accounts` (`id`, `name`, `password`, `premdays`, `lastday`, `email`, `key`, `blocked`, `warnings`, `group_id`) VALUES (NULL, '"..getPlayerStorageValue(cid,1890).."', '"..getPlayerStorageValue(cid,1891).."', '0', '0', '', '0', '0', '0', '1');")
				setPlayerStorageValue(cid,s,1)
				npcHandler:say('Ok, your account has been created!',cid)
				talkState[talkUser] = 0
			else
				npcHandler:say('Alright, no problem, what do you want as password then?',cid)
				talkState[talkUser] = 3
			end
		end
	else
		npcHandler:say('You can only make a private account once.',cid)
		npcHandler:releaseFocus(cid)
	end
return TRUE
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

any errors? or what isnt working.. explain :p
 
'No errors, but when it asks if I'm sure to use the username and I say yes, it just says "Then lets get on, creating your private account. what do you wish as username?" all over again
 
Back
Top Bottom