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

NPCs

bomba

Member
Joined
Feb 26, 2008
Messages
635
Reaction score
7
Location
Brazil
[TFS 8.31]

I wish someone help me...
I wanted someone there is an NPC in which he speaks two languages, example:

Code:
--English
Player: Hi
NPC Test: Hello dear player.

--Portugues
Jogador: Oi
NPC Teste: Ola querido jogador.
Code:
--English
Player: Hi
NPC Test: Hi, I see some things that are not very precious.
Player: Trade
*Open trade window*

--Portugues
Jogador: Oi
NPC Teste: Oi, eu vendo algumas coisas que [COLOR="Red"]não são[/COLOR] muito preciosas.
Jogador: Trocar
*Abre a janela de trocas*

n\ão s\ão
 
Code:
focus = 0
talk_start = 0
target = 0
following = false
attacking = false
language = ""

function onThingMove(creature, thing, oldpos, oldstackpos)

end
function onCreatureAppear(creature)

end
function onCreatureDisappear(cid, pos)
  	if focus == cid then
          selfSay('Good bye then.')
          focus = 0
          talk_start = 0
  	end
end
function onCreatureTurn(creature)

end
function msgcontains(txt, str)
  	return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end

function onCreatureSay(cid, type, msg)
  	msg = string.lower(msg)
  	if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
  		selfSay('Hello ' .. getCreatureName(cid) .. '!')
  		focus = cid
  		talk_start = os.clock()
		language = "en"
	elseif (msgcontains(msg, 'oi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
		selfSay('Oi ' .. getCreatureName(cid) .. '!')
		focis = cid
		talk_start = os.clock()
		language = "pt"
  	elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
  		selfSay('Sorry, ' .. getCreatureName(cid) .. '! I talk to you in a minute.')
	elseif msgcontains(msg, 'oi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
		selfSay('Desculpa fdp...............')
	elseif focus == cid then
		talk_start = os.clock()
	elseif msgcontains(msg, 'help') and language == "en" and getDistanceToCreature(cid) < 4 then
		selfSay('I am multi-language NPC.')
	elseif msgcontains(msg, 'ajuda') and language == "pt" and getDistanceToCreature(cid) < 4 then
		selfSay('Eu sou ??????? NPC.')
	elseif string.find(msg, '(%a*)bye(%a*)') and language == "en" and getDistanceToCreature(cid) < 4 then
		selfSay('Good bye, ' .. getCreatureName(cid) .. '!')
		focus = 0
		talk_start = 0
		language = ""
	elseif string.find(msg, '(%a*)xau(%a*)') and language == "pt" and getDistanceToCreature(cid) < 4 then
		selfSay('Xau, ' .. getCreatureName(cid) .. '!')
		focis = 0
		talk_start = 0
		language = ""
	end
end

function onCreatureChangeOutfit(creature)

end

function onThink()
  	if (os.clock() - talk_start) > 30 then
  		if focus > 0 then
			if language == "en" then
				selfSay('Next Please...')
			else
				selfSay('queeeeeeeee...')
			end
  		end
		language = ""
  		focus = 0
  	end
 	if focus ~= 0 then
 		if getDistanceToCreature(focus) > 5 then
			if language == "en" then
				selfSay('Good bye then.')
			else
				selfSay('Xau...')
			end
			language = ""
 			focus = 0
		end
	end
end

Probably won't work, but its worth a try. :p
 
Fixed...
PHP:
12:34 Testowany Test [100]: hi
12:34 Language Master: Hello Testowany Test!
12:34 Testowany Test [100]: help
12:34 Language Master: I am multi-language NPC.
12:34 Testowany Test [100]: bye
12:34 Language Master: Good bye, Testowany Test!
12:34 Testowany Test [100]: oi
12:34 Language Master: Oi Testowany Test!
12:34 Testowany Test [100]: ajuda
12:34 Language Master: Eu sou ??????? NPC.
12:34 Testowany Test [100]: xau
12:34 Language Master: Xau, Testowany Test!

Code:
focus = 0
talk_start = 0
target = 0
following = false
attacking = false
language = 0 -- 1 = english, 2 = pt-br

function onThingMove(creature, thing, oldpos, oldstackpos)
end
function onCreatureAppear(creature)
end
function onCreatureDisappear(cid, pos)
  	if focus == cid then
		if language == 1 then
			selfSay('Good bye then.')
		elseif language == 2 then
			selfSay('Xau...')
		end
		focus = 0
		talk_start = 0
		language = 0
  	end
end
function onCreatureTurn(creature)
end
function msgcontains(txt, str)
  	return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end

function onCreatureSay(cid, type, msg)
  	msg = string.lower(msg)
  	if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
  		selfSay('Hello ' .. getCreatureName(cid) .. '!')
  		focus = cid
  		talk_start = os.clock()
		language = 1
	elseif (msgcontains(msg, 'oi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
		selfSay('Oi ' .. getCreatureName(cid) .. '!')
		focus = cid
		talk_start = os.clock()
		language = 2
	end
  	if msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
  		selfSay('Sorry, ' .. getCreatureName(cid) .. '! I talk to you in a minute.')
	elseif msgcontains(msg, 'oi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
		selfSay('Desculpa fdp...............')
	end
	if focus == cid then
		talk_start = os.clock()
	end
	if msgcontains(msg, 'help') and language == 1 and getDistanceToCreature(cid) < 4 then
		selfSay('I am multi-language NPC.')
	elseif msgcontains(msg, 'bye') and language == 1 and getDistanceToCreature(cid) < 4 then
		selfSay('Good bye, ' .. getCreatureName(cid) .. '!')
		focus = 0
		talk_start = 0
		language = 0
	end
	if msgcontains(msg, 'ajuda') and language == 2 and getDistanceToCreature(cid) < 4 then
		selfSay('Eu sou ??????? NPC.')
	elseif msgcontains(msg, 'xau') and language == 2 and getDistanceToCreature(cid) < 4 then
		selfSay('Xau, ' .. getCreatureName(cid) .. '!')
		focus = 0
		talk_start = 0
		language = 0
	end
end

function onCreatureChangeOutfit(creature)

end

function onThink()
  	if (os.clock() - talk_start) > 30 then
  		if focus > 0 then
			if language == 1 then
				selfSay('Next Please...')
			elseif language == 2 then
				selfSay('queeeeeeeee...')
			end
  		end
		language = 0
  		focus = 0
  	end
 	if focus ~= 0 then
 		if getDistanceToCreature(focus) > 5 then
			if language == 1 then
				selfSay('Good bye then.')
			elseif language == 2 then
				selfSay('Xau...')
			end
			language = 0
 			focus = 0
		end
	end
end

He just doesnt want to stop walking when greeted. ;p

@ If you want the NPC to react on 'trocar' or other words, go to data\npc\lib\npcsystem\modules.lua and add 'trocar' to that table:
-- The words for requesting trade window.
SHOP_TRADEREQUEST = {'offer', 'trade'}
 
Last edited:
I like, you do a good job!

Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Derunok" script="data/npc/scripts/test.lua" walkinterval="2000" floorchange="0">
	<health now="1337" max="1337"/>
	<look type="289" head="78" body="88" legs="0" feet="88" addons="1"/>
</npc>
Code:
focus = 0
talk_start = 0
target = 0
following = false
attacking = false
language = 0 -- 1 = english, 2 = pt-br

function onThingMove(creature, thing, oldpos, oldstackpos)
end
function onCreatureAppear(creature)
end
function onCreatureDisappear(cid, pos)
  	if focus == cid then
		if language == 1 then
			selfSay('Good bye then.')
		elseif language == 2 then
			selfSay('At\é logo ' .. getCreatureName(cid) .. '.')
		end
		focus = 0
		talk_start = 0
		language = 0
  	end
end
function onCreatureTurn(creature)
end
function msgcontains(txt, str)
  	return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end

function onCreatureSay(cid, type, msg)
  	msg = string.lower(msg)
  	if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
  		selfSay('Hello ' .. getCreatureName(cid) .. '!')
  		focus = cid
  		talk_start = os.clock()
		language = 1
	elseif (msgcontains(msg, 'oi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
		selfSay('Ol\á ' .. getCreatureName(cid) .. '!')
		focus = cid
		talk_start = os.clock()
		language = 2
	end
  	if msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
  		selfSay('Sorry, ' .. getCreatureName(cid) .. ', I talk to you in a minute.')
	elseif msgcontains(msg, 'oi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
		selfSay('Espere! logo irei lhe atender, ' .. getCreatureName(cid) .. '.')
	end
	if focus == cid then
		talk_start = os.clock()
	end
	if msgcontains(msg, 'help') and language == 1 and getDistanceToCreature(cid) < 4 then
		selfSay('I don\'t help.')
	elseif msgcontains(msg, 'bye') and language == 1 and getDistanceToCreature(cid) < 4 then
		selfSay('Good bye, ' .. getCreatureName(cid) .. '!')
		focus = 0
		talk_start = 0
		language = 0
	end
	if msgcontains(msg, 'ajuda') and language == 2 and getDistanceToCreature(cid) < 4 then
		selfSay('Desculpa mas eu n\ão irei lhe ajudar.')
	elseif msgcontains(msg, 'tchau') and language == 2 and getDistanceToCreature(cid) < 4 then
		selfSay('Tchau, ' .. getCreatureName(cid) .. '!')
		focus = 0
		talk_start = 0
		language = 0
	end
end

function onCreatureChangeOutfit(creature)

end

function onThink()
  	if (os.clock() - talk_start) > 30 then
  		if focus > 0 then
			if language == 1 then
				selfSay('Next Please...')
			elseif language == 2 then
				selfSay('O pr\óximo por favor.')
			end
  		end
		language = 0
  		focus = 0
  	end
 	if focus ~= 0 then
 		if getDistanceToCreature(focus) > 5 then
			if language == 1 then
				selfSay('Good bye then.')
			elseif language == 2 then
				selfSay('Tchau.')
			end
			language = 0
 			focus = 0
		end
	end
end

Bugs:
*Need fix the 'walk' of NPC.
*Need fix NPC-Channel.
 
Last edited:
If you want him to speak in channel, I guess you can change selfSay to selfSayChannel. If that wont work change selfSay to:
npcHandler:say and after the message add ,cid
e.g.
npcHandler:say("Oi", cid)

About the walking bug, I have no idea how to fix that one, you could always ask Gesior, I think he fixed this thing in his old banker script.
 
Fixed the NPC-Channel bug(by me):
Code:
focus = 0
talk_start = 0
target = 0
following = false
attacking = false
language = 0 -- 1 = english, 2 = pt-br

function onThingMove(creature, thing, oldpos, oldstackpos)
end
function onCreatureAppear(creature)
end
function onCreatureDisappear(cid, pos)
  	if focus == cid then
		if language == 1 then
			selfSay('Good bye then.')
		elseif language == 2 then
			selfSay('At\é logo ' .. getCreatureName(cid) .. '.')
		end
		focus = 0
		talk_start = 0
		language = 0
  	end
end
function onCreatureTurn(creature)
end
function msgcontains(txt, str)
  	return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end

function onCreatureSay(cid, type, msg)
  	msg = string.lower(msg)
  	if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
  		selfSay('Hello ' .. getCreatureName(cid) .. '!', cid)
  		focus = cid
  		talk_start = os.clock()
		language = 1
	elseif (msgcontains(msg, 'oi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
		selfSay('Ol\á ' .. getCreatureName(cid) .. '!', cid)
		focus = cid
		talk_start = os.clock()
		language = 2
	end
  	if msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
  		selfSay('Sorry, ' .. getCreatureName(cid) .. ', I talk to you in a minute.', cid)
	elseif msgcontains(msg, 'oi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
		selfSay('Espere! logo irei lhe atender, ' .. getCreatureName(cid) .. '.', cid)
	end
	if focus == cid then
		talk_start = os.clock()
	end
	if msgcontains(msg, 'help') and language == 1 and getDistanceToCreature(cid) < 4 then
		selfSay('I don\'t help.', cid)
	elseif msgcontains(msg, 'bye') and language == 1 and getDistanceToCreature(cid) < 4 then
		selfSay('Good bye, ' .. getCreatureName(cid) .. '!', cid)
		focus = 0
		talk_start = 0
		language = 0
	end
	if msgcontains(msg, 'ajuda') and language == 2 and getDistanceToCreature(cid) < 4 then
		selfSay('Desculpa mas eu n\ão irei lhe ajudar.', cid)
	elseif msgcontains(msg, 'tchau') and language == 2 and getDistanceToCreature(cid) < 4 then
		selfSay('Tchau, ' .. getCreatureName(cid) .. '!', cid)
		focus = 0
		talk_start = 0
		language = 0
	end
end

function onCreatureChangeOutfit(creature)

end

function onThink()
  	if (os.clock() - talk_start) > 30 then
  		if focus > 0 then
			if language == 1 then
				selfSay('Next Please...')
			elseif language == 2 then
				selfSay('O pr\óximo por favor.')
			end
  		end
		language = 0
  		focus = 0
  	end
 	if focus ~= 0 then
 		if getDistanceToCreature(focus) > 5 then
			if language == 1 then
				selfSay('Good bye then.')
			elseif language == 2 then
				selfSay('Tchau.')
			end
			language = 0
 			focus = 0
		end
	end
end
*Need fix the 'walk'.
 
Back
Top