• 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 checking vocation

d4rkbl0od

Member
Joined
Mar 21, 2008
Messages
160
Reaction score
7
Hi peopple, its me again, hehehe

Anyone know how to make a npc asks player vocation?
Like the Dead Bureaucrat NPC from poi, he asks playername,
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local talkState = {}
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 doNPCTalkALot(msgs,interval)
  local e={}
  local ret={}
  if interval==nil then interval=3000 end --3 seconds is default time between messages
  for aux=1,table.getn(msgs) do
      e[aux]={}
      doCreatureSayWithDelay(getNpcCid(),msgs[aux],TALKTYPE_PRIVATE_NP,(aux-1)*interval,e[aux])
      table.insert(ret,e[aux])
  end
  return(ret)
end


function creatureSayCallback(cid, type, msg)
	if (msgcontains(msg, 'hi') or msgcontains(msg, 'hello') or msgcontains(msg, 'salutations')) and getPlayerSex(cid) == 0 and not npcHandler:isFocused(cid) then
		npcHandler:say('Hello beautiful lady, welcome to the atrium of Pumin\'s Domain. We require some information from you before we canlet you pass. Where do you want to go?', cid, TRUE)
		npcHandler:addFocus(cid)
		Topic[cid] = 0
		
		elseif (msgcontains(msg, 'hi') or msgcontains(msg, 'hello') or msgcontains(msg, 'salutations')) and getPlayerSex(cid) == 1 and not npcHandler:isFocused(cid) then
		npcHandler:say('Welcome to the atrium of Pumin\'s domain, young man. We need some information before we can let you pass. Where do you want to go?', cid, TRUE)		
		Topic[cid] = 0
		end
		
		
function getVocationName(id)	
		local vocations = {
		[1] = {'druid'},
		[2] = {'sorcerer'},
		[3] = {'paladin'},
		[4] = {'knight'},
		[5] = {'druid'},
		[6] = {'sorcerer'},
		[7] = {'paladin'},
		[8] = {'knight'},
		}
      local VocName = vocations[id]
	return VocName
 end
			
		
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    local namee = getPlayerName(cid)
    


    
 if (msgcontains(msg, 'Pumin') or msgcontains(msg, 'pumin') ) then
  selfSay('Sure, where else. Everyone likes to meet my master, he is a great demon, isn\'t he? Your name is ...?',cid)
  talkState[talkUser] = 1

  elseif msg == getCreatureName(cid) and  talkState[talkUser] == 1 then
   selfSay('Alright '.. getCreatureName(cid) .. '. Vocation?',cid)
   talkState[talkUser] = 2
  		
  			 
  			 
elseif msg == getVocationName(getPlayerVocation(cid))  and  talkState[talkUser] == 2  then

  		selfSay('Alright '.. VocName .. '..........' ,cid)
  			 talkState[talkUser] = 0
  		
					
  	
       end
 

    return TRUE    
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

This script is only an example, NPC asks for player name, and the player aswers with his name, then npc asks vocation...
here is where come the problem, actualy the function is getPlayerVocation, and it check player vocation with numbers, 1 2 3 4 5 6 7 8, how can i make this npc check if the player says Sorcerer for example?
 
first
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local t = {}

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 function f(a)
	if a > 4 then
		a = a - 4
	end
	return a==1 and 'sorcerer' or a==2 and 'druid' or a==3 and 'paladin' or 'knight'
end

function free(cid)
	if npcHandler:isFocused(cid) then
		t[cid] = nil
	end
	return true
end

function thinkCallback(cid)
	if math.random(400) == 1 then
		npcHandler:say('<sigh>')
	end
	return true
end

function greetCallback(cid)
	t[cid] = nil
	local s = getCreatureStorage(cid, 356)
	if s == 2 then
		npcHandler:setMessage(MESSAGE_GREET, 'You again. What do you need this time?') --
	elseif s ~= -1 then
		npcHandler:setMessage(MESSAGE_GREET, 'You again. I told my master that you wish to end your stupid life in his domain but you need Form 356 to get there. What do you need this time?')
	else
		npcHandler:setMessage(MESSAGE_GREET,
		getPlayerSex(cid) == 0 and
			'Hello beautiful lady, welcome to the atrium of Pumin\'s Domain. We require some information from you before we can let you pass. Where do you want to go?'
		or
			'Welcome to the atrium of Pumin\'s domain, young man. We need some information before we can let you pass. Where do you want to go?'
		)
	end
	return true
end

function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	elseif not t[cid] then
		if msgcontains(msg, 'pumin') and getCreatureStorage(cid, 356) == -1 then
			npcHandler:say('Sure, where else. Everyone likes to meet my master, he is a great demon, isn\'t he? Your name is ...?', cid)
			t[cid] = 1
		elseif msgcontains(msg, '411') and getCreatureStorage(cid, 411) == 0 then
			npcHandler:say('Form 411? You need Form 287 to get that! Do you have it?', cid)
			t[cid] = 4
		elseif msgcontains(msg, '356') and getCreatureStorage(cid, 356) == 1 then
			npcHandler:say('INCREDIBLE, you did it!! Have fun at Pumin\'s Domain!', cid)
			doCreatureSetStorage(cid, 356, 2)
		end
	elseif t[cid] == 1 then
		if msg:lower() == getCreatureName(cid):lower() then
			npcHandler:say('Alright '.. getCreatureName(cid) .. '. Vocation?', cid)
			t[cid] = 2
		end
	elseif t[cid] == 2 then
		if msg:lower() == f(getPlayerVocation(cid)) then
			-- needs different replies
			npcHandler:say('Huhu, please don\'t hurt me with your wand! Reason of your visit?', cid)
			t[cid] = 3
		end
	elseif t[cid] == 3 then
		if msgcontains(msg, 'visit') and msgcontains(msg, 'pumin') then
			npcHandler:say('How very interesting. I need to tell that to my master immediately. Please go to my colleagues and ask for Form 356. You will need it in order to proceed.', cid)
			doCreatureSetStorage(cid, 356, 0)
			t[cid] = nil
		end
	elseif t[cid] == 4 then
		local s = getCreatureStorage(cid, 287)
		if msgcontains(msg, 'yes') and s == 1 then
			npcHandler:say('Great. Here you are. Form 411. Come back anytime you want to talk. Bye.', cid)
			doCreatureSetStorage(cid, 411, 1)
		else
			npcHandler:say('Oh, what a pity. Go see one of my colleagues. I give you the permission to get Form 287. Bye!', cid)
			if s == -1 then
				doCreatureSetStorage(cid, 287, 0)
			end
		end
		npcHandler:releaseFocus(cid)
		t[cid] = nil
	end
	return true
end

npcHandler:setMessage(MESSAGE_FAREWELL, 'Good bye and don\'t forget me!')
npcHandler:setMessage(MESSAGE_WALKAWAY, 'Good bye and don\'t forget me!')
npcHandler:setCallback(CALLBACK_FAREWELL, free)
npcHandler:setCallback(CALLBACK_CREATURE_DISAPPEAR, free)
npcHandler:setCallback(CALLBACK_ONTHINK, thinkCallback)
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
second
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 thinkCallback(cid)
	if math.random(400) == 1 then
		npcHandler:say('<sigh>')
	end
	return true
end

function greetCallback(cid)
	npcHandler:setMessage(MESSAGE_GREET,
	getPlayerSex(cid) == 0 and
		'Hello beautiful lady, welcome to the atrium of Pumin\'s Domain. What do you need?'
	or
		'Welcome to the atrium of Pumin\'s domain, young man. What do you need?'
	)
	return true
end

function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	elseif msgcontains(msg, '287') and getCreatureStorage(cid, 287) == 0 then
		npcHandler:say('Sure, you can get it from me. Here you are. Bye!', cid)
		doCreatureSetStorage(cid, 287, 1)
		npcHandler:releaseFocus(cid)
	end
	return true
end

npcHandler:setMessage(MESSAGE_FAREWELL, 'Good bye and don\'t forget me!')
npcHandler:setMessage(MESSAGE_WALKAWAY, 'Good bye and don\'t forget me!')
npcHandler:setCallback(CALLBACK_ONTHINK, thinkCallback)
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
third
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local t = {}

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 function f(a)
	if a > 4 then
		a = a - 4
	end
	return a==1 and 'sorcerer' or a==2 and 'druid' or a==3 and 'paladin' or 'knight'
end

function free(cid)
	if npcHandler:isFocused(cid) then
		t[cid] = nil
	end
	return true
end

function thinkCallback(cid)
	if math.random(400) == 1 then
		npcHandler:say('<sigh>')
	end
	return true
end

function greetCallback(cid)
	t[cid] = nil
	if getCreatureStorage(cid, 411) ~= -1 then
		npcHandler:setMessage(MESSAGE_GREET, 'Back again? How can I help you this time?')
	else
		npcHandler:setMessage(MESSAGE_GREET,
		getPlayerSex(cid) == 0 and
			'Hello beautiful lady, welcome to the atrium of Pumin\'s Domain. We require some information from you before we can let you pass. Where do you want to go?'
		or
			'Welcome to the atrium of Pumin\'s domain, young man. We need some information before we can let you pass. Where do you want to go?'
		)
	end
	return true
end

function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	elseif not t[cid] then
		if msgcontains(msg, 'pumin') and getCreatureStorage(cid, 411) == -1 then
			npcHandler:say('Tell me if you liked it when you come back. What is your name?', cid)
			t[cid] = 1
		elseif msgcontains(msg, '145') and getCreatureStorage(cid, 411) == 1 and getCreatureStorage(cid, 145) == 0 then
			npcHandler:say('Well done! You have form 411!! Here is Form 145. Have fun with it.', cid)
			doCreatureSetStorage(cid, 145, 1)
		end
	elseif t[cid] == 1 then
		if msg:lower() == getCreatureName(cid):lower() then
			npcHandler:say('Alright '.. getCreatureName(cid) .. '. Vocation?', cid)
			t[cid] = 2
		end
	elseif t[cid] == 2 then
		local s = f(getPlayerVocation(cid))
		if msg:lower() == s then
			-- needs different replies?
			npcHandler:say('I was a ' .. s .. ', too, before I died!! What do you want from me?', cid)
			t[cid] = 3
		end
	elseif t[cid] == 3 then
		if msgcontains(msg, '145') then
			npcHandler:say('That\'s right, you can get Form 145 from me. However, I need Form 411 first. Come back when you have it.', cid)
			doCreatureSetStorage(cid, 411, 0)
			t[cid] = nil
		end
	end
	return true
end

npcHandler:setMessage(MESSAGE_FAREWELL, 'Good bye and don\'t forget me!')
npcHandler:setMessage(MESSAGE_WALKAWAY, 'Good bye and don\'t forget me!')
npcHandler:setCallback(CALLBACK_FAREWELL, free)
npcHandler:setCallback(CALLBACK_CREATURE_DISAPPEAR, free)
npcHandler:setCallback(CALLBACK_ONTHINK, thinkCallback)
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
fourth
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local t = {}

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 function f(a)
	if a > 4 then
		a = a - 4
	end
	return a==1 and 'sorcerer' or a==2 and 'druid' or a==3 and 'paladin' or 'knight'
end

function free(cid)
	if npcHandler:isFocused(cid) then
		t[cid] = nil
	end
	return true
end

function thinkCallback(cid)
	if math.random(400) == 1 then
		npcHandler:say('<sigh>')
	end
	return true
end

function greetCallback(cid)
	t[cid] = nil
	if getCreatureStorage(cid, 145) ~= -1 then
		npcHandler:setMessage(MESSAGE_GREET, 'Hey! You are back!! How can I help you this time?')
	else
		npcHandler:setMessage(MESSAGE_GREET,
		getPlayerSex(cid) == 0 and
			'Hello beautiful lady, welcome to the atrium of Pumin\'s Domain. We require some information from you before we can let you pass. Where do you want to go?'
		or
			'Welcome to the atrium of Pumin\'s domain, young man. We need some information before we can let you pass. Where do you want to go?'
		)
	end
	return true
end

function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	elseif not t[cid] then
		if msgcontains(msg, 'pumin') and getCreatureStorage(cid, 145) == -1 then
			npcHandler:say('I\'m not sure if you know what you are doing but anyway. Your name is?', cid)
			t[cid] = 1
		elseif msgcontains(msg, '356') and getCreatureStorage(cid, 145) == 1 and getCreatureStorage(cid, 356) == 0 then
			npcHandler:say('You are better than I thought! Congratulations, here you are: Form 356!', cid)
			doCreatureSetStorage(cid, 356, 1)
		end
	elseif t[cid] == 1 then
		if msg:lower() == getCreatureName(cid):lower() then
			npcHandler:say('Alright '.. getCreatureName(cid) .. '. Vocation?', cid)
			t[cid] = 2
		end
	elseif t[cid] == 2 then
		local s = f(getPlayerVocation(cid))
		if msg:lower() == s then
			npcHandler:say(s:upper():gsub('%a', '%1 '):gsub('%s$', ',') .. ' is that right?! What do you want from me?', cid)
			t[cid] = 3
		end
	elseif t[cid] == 3 and msgcontains(msg, '356') then
		npcHandler:say('Sorry, you need Form 145 to get Form 356. Come back when you have it.', cid)
		doCreatureSetStorage(cid, 145, 0)
		t[cid] = nil
	end
	return true
end

npcHandler:setMessage(MESSAGE_FAREWELL, 'Good bye and don\'t forget me!')
npcHandler:setMessage(MESSAGE_WALKAWAY, 'Good bye and don\'t forget me!')
npcHandler:setCallback(CALLBACK_FAREWELL, free)
npcHandler:setCallback(CALLBACK_CREATURE_DISAPPEAR, free)
npcHandler:setCallback(CALLBACK_ONTHINK, thinkCallback)
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
lol cyko that was really weak, you could've done it in one file (only if npcs have different names though)

: D
 
Back
Top