• 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 talk_state bug?

ond

Veteran OT User
Joined
Mar 24, 2008
Messages
2,775
Solutions
25
Reaction score
483
Location
Sweden
I have a problem with my script down below. The problem is that you can't script it like this:

if msgcontains(msg, 'hat') then
selfSay('What ever!')
talk_state = 1

elseif talk_state == 1 and msgcontains(msg, 'hat') then
selfSay('What ever again!')
talk_state = 2

BUT you can script it like this (Without start: hat)

if msgcontains(msg, 'random word') then
selfSay('What ever!')
talk_state = 1

elseif talk_state == 1 and msgcontains(msg, 'hat') then
selfSay('What ever again!')
talk_state = 2

elseif talk_state == 2 and msgcontains(msg, 'hat') then
selfSay('What ever again!')
talk_state = 3

Does anyone have an idea how to make it work Anyway?

Quote 1 = Not Work
Quote 2 = Works



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


creaturepos1 = {x=32921, y=32074, z=9}
reaturepos2 = {x=32923, y=32074, z=9}
creaturepos3 = {x=32921, y=32076, z=9}
creaturepos4 = {x=32923, y=32076, z=9}

keywordHandler:addKeyword({'name'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "My name is not of your concern."})
keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "That's only my business, not yours."})
keywordHandler:addKeyword({'david'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I never heard that name and now get lost."})
keywordHandler:addKeyword({'brassacres'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I never heard that name and now get lost."})



function creatureSayCallback(cid, type, msg)
	if(npcHandler.focus ~= cid) then
		return false
	end
	
	msg = msg:lower()

	
if msgcontains(msg, 'hat') and getPlayerStorageValue(cid, 5209) == 1 then
selfSay('What? My hat?? Theres... nothing special about it!')
talk_state = 1

elseif talk_state == 1 and msgcontains(msg, 'hat') then
selfSay('Stop bugging me about that hat, do you listen?')
talk_state = 2

elseif talk_state == 2 and msgcontains(msg, 'hat') then
selfSay('Hey! Don\'t touch that hat! Leave it alone!!! Don\'t do this!!!!')
talk_state = 3

elseif talk_state == 3 and msgcontains(msg, 'hat') then
selfSay('Noooooo! Argh, ok, ok, I guess I can\'t deny it anymore, I am David Brassacres, the magnificent, so what do you want?')
doSummonCreature("Rat", creaturepos1)
doSummonCreature("Rat", creaturepos2)
doSummonCreature("Rat", creaturepos3)
doSummonCreature("Rat", creaturepos4)
setPlayerStorageValue(cid, 5210, 1)
talk_state = 4

elseif getPlayerStorageValue(cid, 5210) == 1  and msgcontains(msg, 'bill') and talk_state == 4 then
selfSay('A bill? Oh boy so you are delivering another bill to poor me?')
talk_state = 5

elseif talk_state == 5 and msgcontains(msg, 'yes') then
selfSay('Ok, ok, I\'ll take it. I guess I have no other choice anyways. And now leave me alone in my misery please.')
setPlayerStorageValue(cid, 5211, 1)
doPlayerRemoveItem(cid, 2329, 1)
talk_state = 6

-- Without Value --

elseif getPlayerStorageValue(cid, 5209) == -1 and msgcontains(msg, 'bill') then
selfSay('Thats not my concern, you are probably looking for someone else and now get lost!')
talk_state = 0
npcHandler:releaseFocus()

elseif msgcontains(msg, 'hat') and getPlayerStorageValue(cid, 5209) == -1 then
selfSay('Get lost!')
npcHandler:releaseFocus()
talk_state = 0

-- Without Value -- 

-- After Quest Questions --

elseif msgcontains(msg, 'david') and getPlayerStorage(cid, 5211) == 1 then
selfSay('Yes, yes... Its me .. you exposed me! Stop nagging me with that.')
talk_state = 0

elseif msgcontains(msg, 'brassacres') and getPlayerStorage(cid, 5211) == 1 then
selfSay('Yes, yes... Its me .. you exposed me! Stop nagging me with that.')
talk_state = 0

-- After Quest Questions --

elseif talk_state ~= 0 then
selfSay('Ok')

end
return true
end
	
	
	npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Code:
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
 
 
creaturepos1 = {x=32921, y=32074, z=9}
reaturepos2 = {x=32923, y=32074, z=9}
creaturepos3 = {x=32921, y=32076, z=9}
creaturepos4 = {x=32923, y=32076, z=9}
 
keywordHandler:addKeyword({'name'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "My name is not of your concern."})
keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "That's only my business, not yours."})
keywordHandler:addKeyword({'david'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I never heard that name and now get lost."})
keywordHandler:addKeyword({'brassacres'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I never heard that name and now get lost."})
 
 
 
function creatureSayCallback(cid, type, msg)
	if(npcHandler.focus ~= cid) then
		return false
	end
 
	msg = msg:lower()
 
 
if msgcontains(msg, 'hat') and getPlayerStorageValue(cid, 5209) == 1 then
selfSay('What? My hat?? Theres... nothing special about it!')
talk_state = 1
 
elseif talk_state == 1 and msgcontains(msg, 'hat') then
selfSay('Stop bugging me about that hat, do you listen?')
talk_state = 2
 
elseif talk_state == 2 and msgcontains(msg, 'hat') then
selfSay('Hey! Don\'t touch that hat! Leave it alone!!! Don\'t do this!!!!')
talk_state = 3
 
elseif talk_state == 3 and msgcontains(msg, 'hat') then
selfSay('Noooooo! Argh, ok, ok, I guess I can\'t deny it anymore, I am David Brassacres, the magnificent, so what do you want?')
doSummonCreature("Rat", creaturepos1)
doSummonCreature("Rat", creaturepos2)
doSummonCreature("Rat", creaturepos3)
doSummonCreature("Rat", creaturepos4)
setPlayerStorageValue(cid, 5210, 1)
talk_state = 4
 
elseif getPlayerStorageValue(cid, 5210) == 1 and msgcontains(msg, 'bill') and talk_state == 4 then
selfSay('A bill? Oh boy so you are delivering another bill to poor me?')
talk_state = 5
 
elseif talk_state == 5 and msgcontains(msg, 'yes') then
selfSay('Ok, ok, I\'ll take it. I guess I have no other choice anyways. And now leave me alone in my misery please.')
setPlayerStorageValue(cid, 5211, 1)
doPlayerRemoveItem(cid, 2329, 1)
talk_state = 6
 
-- Without Value --
 
elseif getPlayerStorageValue(cid, 5209) == -1 and msgcontains(msg, 'bill') then
selfSay('Thats not my concern, you are probably looking for someone else and now get lost!')
talk_state = 0
npcHandler:releaseFocus()
 
elseif msgcontains(msg, 'hat') and getPlayerStorageValue(cid, 5209) == -1 then
selfSay('Get lost!')
npcHandler:releaseFocus()
talk_state = 0
 
-- Without Value -- 
 
-- After Quest Questions --
 
elseif msgcontains(msg, 'david') and getPlayerStorage(cid, 5211) == 1 then
selfSay('Yes, yes... Its me .. you exposed me! Stop nagging me with that.')
talk_state = 0
 Why so weakly? = 'słaby'=0
elseif msgcontains(msg, 'brassacres') and getPlayerStorage(cid, 5211) == 1 then
selfSay('Yes, yes... Its me .. you exposed me! Stop nagging me with that.')
talk_state = 0
 
-- After Quest Questions --
 
elseif talk_state ~= 0 then
selfSay('Ok')
 
end
return true
end
 
 
	npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic = 0

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 = 0
	return true
end

function creatureSayCallback(cid, type, msg)
	if npcHandler.focus ~= cid then
		return false
	end
	
	msg = msg:lower()
	local v = getPlayerStorageValue(cid, 5209)

	if Topic == 5 then
		if msgcontains(msg, 'yes') then
			if doPlayerRemoveItem(cid, 2329, 1) == TRUE then
				selfSay("Ok, ok, I'll take it. I guess I have no other choice anyways. And now leave me alone in my misery please.")
				setPlayerStorageValue(cid, 5209, 3)
			else
				selfSay("Ha Ha! You have none!! Naanaanaanaaanaaaa!")
				npcHandler:releaseFocus()
			end
		else
			selfSay("Hoooraaaay! Uhm... I mean, thats fine...")
		end
		Topic = 0
	elseif msgcontains(msg, 'david') or msgcontains(msg, 'brassacres') then
		selfSay(v > 1 and "Yes, yes... Its me .. you exposed me! Stop nagging me with that." or "I never heard that name and now get lost.")
		Topic = 0
	elseif msgcontains(msg, 'bill') then
		if v == 2 then
			selfSay("A bill? Oh boy so you are delivering another bill to poor me?")
			Topic = 5
		else
			selfSay("Thats not my concern, you are probably looking for someone else and now get lost!")
			npcHandler:releaseFocus()
			Topic = 0
		end
	elseif msgcontains(msg, 'hat') then
		if Topic == 1 then
			selfSay("Stop bugging me about that hat, do you listen?")
			Topic = 2
		elseif Topic == 2 then
			selfSay("Hey! Don't touch that hat! Leave it alone!!! Don't do this!!!!")
			Topic = 3
		elseif Topic == 3 then
			selfSay("Noooooo! Argh, ok, ok, I guess I can't deny it anymore, I am David Brassacres, the magnificent, so what do you want?")
			local p = getCreaturePosition(getNpcCid())
			for i = 1, 4 do
				doSummonCreature('Rabbit', p)
			end
			setPlayerStorageValue(cid, 5209, 2)
			Topic = 0
		elseif v == 1 then
			selfSay("What? My hat?? Theres... nothing special about it!")
			Topic = 1
		else
			selfSay("Get lost!")
			npcHandler:releaseFocus()
			Topic = 0
		end
	elseif msgcontains(msg, 'name') then
		selfSay("My name is not of your concern.")
		Topic = 0
	elseif msgcontains(msg, 'job') then
		selfSay("That's only my business, not yours.")
		Topic = 0
	end
	return true
end

npcHandler:setMessage(MESSAGE_GREET, "Uh? What do you want?!")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Still I am better in vanishing!")
npcHandler:setMessage(MESSAGE_FAREWELL, "Good riddance.")

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Back
Top