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

Strack

Member
Joined
May 15, 2009
Messages
199
Reaction score
14
well i've done an npc, i'm not good on this, but I think its correct, and I dont know what it doesnt runs properly. When I say me: hi,
it says: hi 'name', are u rdy?,
me: yes
npc: well then in what side u will fight?

and when i respond it says nothing, but if I say 'yes' again it says again: well then in what side u will fight? what's wrong in the script?


Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Trainer" script="script.lua" walkinterval="0" floorchange="0">
	<health now="150" max="150"/>
	<look type="371" head="114" body="119" legs="114" feet="114" corpse="2212"/>
    <parameters>
        <parameter key="module_travel" value="1"/>
		<parameter key="message_greet" value="Hi |PLAYERNAME|. Are u rdy?"/>
   
    </parameters>
</npc>

script:
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)
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	--[[
	REMEMBER TO SET YOUR STORAGE AS YOURSTORAGE!
	]]--
	local storage = 12101
	local xxx = {x=1000, y=1000, z=7}
	local xx = {x=1000, y=1000, z=7}
	local x = {x=1448, y=928, z=7}

	if(msgcontains(msg, 'si') or msgcontains(msg, 'yes')) then
		if(getPlayerStorageValue(cid, storage) > 0) then
			npcHandler:say("Que haces tu aqui?", cid)
			talkState[talkUser] = 0
		else
			if getPlayerLevel(cid) >= 8 then
				npcHandler:say("well then in what side u will fight?", cid)
				talkState[talkUser] = 1
				if(msgcontains(msg, 'XXXX') and talkState[talkUser] == 1) then
				npcHandler:say("bla bla bla.", cid)
				talkState[talkUser] = 1
					if(msgcontains(msg, 'xxxxx')) then
					npcHandler:say("Estas seguro?", cid)
						if(msgcontains(msg, 'si') or msgcontains(msg, 'yes')) then
						doPlayerSetVocation(cid, 1)
						doTeleportThing(cid, xxx)
							if getPlayerSex(cid) == 0 then
							doCreatureChangeOutfit(cid, 423)
							else
							doCreatureChangeOutfit(cid, 424)
							end
						elseif msgcontains(msg, 'no') then
						npcHandler:say("Vuelve cuando lo tengas decidido.", cid)
						talkState[talkUser] = 0
						end
					elseif (msgcontains(msg, 'wevev')) then
					npcHandler:say("Estas seguro?", cid)
						if(msgcontains(msg, 'si') or msgcontains(msg, 'yes')) then
						doPlayerSetVocation(cid, 2)
						doTeleportThing(cid, xxx)
							if getPlayerSex(cid) == 0 then
							doCreatureChangeOutfit(cid, 425)
							else
							doCreatureChangeOutfit(cid, 391)
							end
						elseif msgcontains(msg, 'no') then
						npcHandler:say("Vuelve cuando lo tengas decidido.", cid)
						talkState[talkUser] = 0
						end
					elseif (msgcontains(msg, 'nvec')) then
					npcHandler:say("Estas seguro?", cid)
						if(msgcontains(msg, 'si') or msgcontains(msg, 'yes')) then
						doPlayerSetVocation(cid, 3)
						doTeleportThing(cid, xxx)
							if getPlayerSex(cid) == 0 then
							doCreatureChangeOutfit(cid, 429)
							else
							doCreatureChangeOutfit(cid, 406)
							end
						elseif msgcontains(msg, 'no') then
						npcHandler:say("Vuelve cuando lo tengas decidido.", cid)
						talkState[talkUser] = 0
						end
					elseif (msgcontains(msg, 'eeeeeeeeee')) then
					npcHandler:say("Estas seguro?", cid)
						if(msgcontains(msg, 'si') or msgcontains(msg, 'yes')) then
						doPlayerSetVocation(cid, 4)
						doTeleportThing(cid, xxx)
							if getPlayerSex(cid) == 0 then
							doCreatureChangeOutfit(cid, 426)
							else
							doCreatureChangeOutfit(cid, 393)
							end
						elseif msgcontains(msg, 'no') then
						npcHandler:say("Vuelve cuando lo tengas decidido.", cid)
						talkState[talkUser] = 0
						end
					elseif (msgcontains(msg, 'vrrrr')) then
					npcHandler:say("Estas seguro?", cid)
						if(msgcontains(msg, 'si') or msgcontains(msg, 'yes')) then
						doPlayerSetVocation(cid, 5)
						doTeleportThing(cid, xxx)
							if getPlayerSex(cid) == 0 then
							doCreatureChangeOutfit(cid, 428)
							else
							doCreatureChangeOutfit(cid, 404)
							end
						elseif msgcontains(msg, 'no') then
						npcHandler:say("Vuelve cuando lo tengas decidido.", cid)
						talkState[talkUser] = 0
						end
					elseif (msgcontains(msg, 'hvrrr')) then
					npcHandler:say("Estas seguro?", cid)
						if(msgcontains(msg, 'si') or msgcontains(msg, 'yes')) then
						doPlayerSetVocation(cid, 6)
						doTeleportThing(cid, xxx)
							if getPlayerSex(cid) == 0 then
							doCreatureChangeOutfit(cid, 399)
							else
							doCreatureChangeOutfit(cid, 394)
							end
						elseif msgcontains(msg, 'no') then
						npcHandler:say("Vuelve cuando lo tengas decidido.", cid)
						talkState[talkUser] = 0
						end
					elseif (msgcontains(msg, 'btrnber')) then
					npcHandler:say("Estas seguro?", cid)
						if(msgcontains(msg, 'si') or msgcontains(msg, 'yes')) then
						doPlayerSetVocation(cid, 12)
						doTeleportThing(cid, xxx)
							if getPlayerSex(cid) == 0 then
							doCreatureChangeOutfit(cid, 398)
							else
							doCreatureChangeOutfit(cid, 398)
							end
						elseif msgcontains(msg, 'no') then
						npcHandler:say("Vuelve cuando lo tengas decidido.", cid)
						talkState[talkUser] = 0
						end
					end
				elseif (msgcontains(msg, 'brtert')) then
				npcHandler:say("bla bla bla.", cid)
				talkState[talkUser] = 1
					if(msgcontains(msg, 'sddddu')) then
					npcHandler:say("Estas seguro?", cid)
						if(msgcontains(msg, 'si') or msgcontains(msg, 'yes')) then
						doPlayerSetVocation(cid, 7)
						doTeleportThing(cid, xx)	
							if getPlayerSex(cid) == 0 then
							doCreatureChangeOutfit(cid, 431)
							else
							doCreatureChangeOutfit(cid, 395)
							end
						elseif msgcontains(msg, 'no') then
						npcHandler:say("Vuelve cuando lo tengas decidido.", cid)
						talkState[talkUser] = 0
						end
					elseif (msgcontains(msg, 'pvdser')) then
					npcHandler:say("Estas seguro?", cid)
						if(msgcontains(msg, 'si') or msgcontains(msg, 'yes')) then
						doPlayerSetVocation(cid, 8)
						doTeleportThing(cid, xx)	
							if getPlayerSex(cid) == 0 then
							doCreatureChangeOutfit(cid, 434)
							else
							doCreatureChangeOutfit(cid, 396)
							end
						elseif msgcontains(msg, 'no') then
						npcHandler:say("Vuelve cuando lo tengas decidido.", cid)
						talkState[talkUser] = 0
						end
					elseif (msgcontains(msg, 'wivsser')) then
					npcHandler:say("Estas seguro?", cid)
						if(msgcontains(msg, 'si') or msgcontains(msg, 'yes')) then
						doPlayerSetVocation(cid, 9)
						doTeleportThing(cid, xx)
							if getPlayerSex(cid) == 0 then
							doCreatureChangeOutfit(cid, 402)
							else
							doCreatureChangeOutfit(cid, 435)
							end
						elseif msgcontains(msg, 'no') then
						npcHandler:say("Vuelve cuando lo tengas decidido.", cid)
						talkState[talkUser] = 0
						end
					end
				elseif (msgcontains(msg, 'ddt')) then
				npcHandler:say("bla bla bla", cid)
				talkState[talkUser] = 1
					if(msgcontains(msg, 'nda')) then
					npcHandler:say("Estas seguro?", cid)
						if(msgcontains(msg, 'si') or msgcontains(msg, 'yes')) then
						doPlayerSetVocation(cid, 10)
						doTeleportThing(cid, x)
							if getPlayerSex(cid) == 0 then
							doCreatureChangeOutfit(cid, 433)
							else
							doCreatureChangeOutfit(cid, 432)
							end
						elseif msgcontains(msg, 'no') then
						npcHandler:say("Vuelve cuando lo tengas decidido.", cid)
						talkState[talkUser] = 0
						end
					elseif (msgcontains(msg, 'kasa')) then
					npcHandler:say("Estas seguro?", cid)
						if(msgcontains(msg, 'si') or msgcontains(msg, 'yes')) then
						doPlayerSetVocation(cid, 11)
						doTeleportThing(cid, x)
							if getPlayerSex(cid) == 0 then
							doCreatureChangeOutfit(cid, 430)
							else
							doCreatureChangeOutfit(cid, 430)
							end
						elseif msgcontains(msg, 'no') then
						npcHandler:say("Vuelve cuando lo tengas decidido.", cid)
						talkState[talkUser] = 0
						end
					end
				end
			else 
				npcHandler:say("Aun no estas preparado.", cid)
				talkState[talkUser] = 0
			end
		end
	end
	return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic, Side = {}, {}
local storage = 12101
local xxx = {x=1000, y=1000, z=7}
local xx = {x=1000, y=1000, z=7}
local x = {x=1448, y=928, z=7}

local sides = {
	['XXXX'] = {
		pos = xxx,
		msg = 'bla bla bla.',
		['xxxxx'] = {
			vocation = 1,
			outfit = {423, 424}
		},
		['wevev'] = {
			vocation = 2,
			outfit = {425, 391}
		},
		['nvec'] = {
			vocation = 3,
			outfit = {429, 406}
		},
		['vrrrr'] = {
			vocation = 5,
			outfit = {428, 404}
		},
		['hvrrr'] = {
			vocation = 6,
			outfit = {399, 394}
		},
		['btrnber'] = {
			vocation = 12,
			outfit = {398, 398}
		}
	},
	['brtert'] = {
		pos = xx,
		msg = 'bla bla bla.',
		['sddddu'] = {
			vocation = 7,
			outfit = {431, 395}
		},
		['pvdser'] = {
			vocation = 8,
			outfit = {434, 396}
		},
		['wivsser'] = {
			vocation = 9,
			outfit = {402, 435}
		}
	},
	['ddt'] = {
		pos = x,
		msg = 'bla bla bla.',
		['nda'] = {
			vocation = 10,
			outfit = {433, 432}
		},
		['kasa'] = {
			vocation = 12,
			outfit = {430, 430}
		}
	}
}

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], Side[cid] = 1, 0
	return true
end

function creatureSayCallback(cid, type, msg)
	if Topic[cid] == 1 and (msgcontains(msg, 'si') or msgcontains(msg, 'yes')) then
		if(getPlayerStorageValue(cid, storage) > 0) then
			npcHandler:say("Que haces tu aqui?", cid)
			Topic[cid] = 0
		elseif getPlayerLevel(cid) >= 8 then
			npcHandler:say("Well then, in which side you will fight?", cid)
			Topic[cid] = 2
		else
			npcHandler:say("Aun no estas preparado.", cid)
			Topic[cid] = 0
		end
	elseif Topic[cid] == 2 then
		for txt, v in pairs(sides) do
			if msgcontains(msg, txt) then
				Topic[cid] = txt
				npcHandler:say(v.msg, cid)
				break
			end
		end
	elseif sides[Topic[cid]] then
		local i = sides[Topic[cid]]
		if Side[cid] == 0 then
			for txt, v in pairs(i) do
				if msgcontains(msg, txt) then
					npcHandler:say("Estas seguro?", cid)
					Side[cid] = txt
					break
				end
			end
		else
			if msgcontains(msg, 'si') or msgcontains(msg, 'yes') then
				local v = i[Side[cid]]
				doPlayerSetVocation(cid, v.vocation)
				npcHandler:releaseFocus(cid)
				doTeleportThing(cid, i.pos)
				doSendMagicEffect(i.pos, CONST_ME_TELEPORT)
				local k = getCreatureOutfit(cid)
				k.lookType = v.outfit[getPlayerSex(cid)+1]
				doCreatureChangeOutfit(cid, k)
				Topic[cid] = 0
			elseif msgcontains(msg, 'no') then
				npcHandler:say("Vuelve cuando lo tengas decidido.", cid)
				Topic[cid] = 0
			end
		end
	end
	return true
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
runs perfectly thanks ^^, rep 4 u,
but I dont know the only thing dont work is change of outfit
Code:
[Error - Npc interface] 
[31/07/2010 15:03:06] data/npc/scripts/train.lua:onCreatureSay
[31/07/2010 15:03:06] Description: 
[31/07/2010 15:03:06] attempt to index a nil value
[31/07/2010 15:03:06] stack traceback:
[31/07/2010 15:03:06] 	[C]: in function 'doCreatureChangeOutfit'
[31/07/2010 15:03:06] 	data/npc/scripts/train.lua:117: in function 'callback'
[31/07/2010 15:03:06] 	data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[31/07/2010 15:03:06] 	data/npc/scripts/train.lua:72: in function <data/npc/scripts/train.lua:72>
 
thanks ^^

edit: stills same error:
Code:
 [Error - Npc interface] 
[31/07/2010 16:55:05] data/npc/scripts/train.lua:onCreatureSay
[31/07/2010 16:55:05] Description: 
[31/07/2010 16:55:05] attempt to index a number value
[31/07/2010 16:55:05] stack traceback:
[31/07/2010 16:55:05] 	[C]: in function 'doCreatureChangeOutfit'
[31/07/2010 16:55:05] 	data/npc/scripts/train.lua:117: in function 'callback'
[31/07/2010 16:55:05] 	data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[31/07/2010 16:55:05] 	data/npc/scripts/train.lua:72: in function <data/npc/scripts/train.lua:72>
 
Last edited:
Back
Top