Ir para conteúdo
  • 0

[ Resolvido ]Ajuda No Script Npc


Pergunta

Rapaiz, todo dia tenho uma dúvida smile_positivo.gif

 

TFS: 0.4

Cliente: 8.6

 

Bom, eu queria criar um npc que quando o player fosse "male" ele falasse:

"Welcome Mr. |PLAYERNAME|, want look my pearls? {Trade} with me!"

 

e quando fosse "female" falasse:

"Welcome Mrs. |PLAYERNAME|, want look my pearls? {Trade} with me!

 

Ou seja, só muda o Mr. e o Mrs.

 

Eu percebi que não sei nada de LUA quando tentei fazer esse mísero script e não consegui blush.png

 

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

getPlayerSex(cid)
PLAYERSEX_FEMALE = 0
PLAYERSEX_MALE = 1
ifgetPlayerSex(cid) == PLAYERSEX_FEMALE and (msgcontains(msg, 'hi','hello') then
  selfSay('Welcome Mrs. ' .. creatureGetName(cid) .. ',want to look my pearls? {Trade} with me!')
 else
selfSay('Welcome Mr. ' .. creatureGetName(cid) .. 'want to look my pearls? {Trade} with me!')

end
npcHandler:addModule(FocusModule:new())

 

Então, quem puder (e quiser) ajudar essa pobre alma que não sabe fazer nenhum script, por favor.

Link para o comentário
https://xtibia.com/forum/topic/184177-resolvido-ajuda-no-script-npc/
Compartilhar em outros sites

8 respostass a esta questão

Posts Recomendados

  • 0

Não ha necessidade disso.

 

 

getPlayerSex(cid)

PLAYERSEX_FEMALE = 0

PLAYERSEX_MALE = 1

 

 

 

e isso

 

ifgetPlayerSex(cid) == PLAYERSEX_FEMALE and (msgcontains(msg, 'hi','hello') then

 

deve ter espaço

 

if getPlayerSex(cid) == PLAYERSEX_FEMALE and (msgcontains(msg, 'hi','hello') then

Link para o comentário
https://xtibia.com/forum/topic/184177-resolvido-ajuda-no-script-npc/#findComment-1237801
Compartilhar em outros sites

  • 0

function onCreatureSay(cid, type, msg)
local cid_Say = msg:lower()
if ((cid_Say == "hi") and not (isFocused(cid, focuses))) then
selfSay('Welcome '.. (getPlayerSex(cid) == PLAYERSEX_FEMALE and 'Mrs' or 'Mr') ..'. ' .. getPlayerName(cid) .. ',want to look my pearls? {Trade} with me!')
end
end

 

 

---

editando a lib do npc fica mais fácil, pq dai da pra fazer pelo xml usando por exemplo |PLAYERSEX|

Editado por Vodkart
Link para o comentário
https://xtibia.com/forum/topic/184177-resolvido-ajuda-no-script-npc/#findComment-1237855
Compartilhar em outros sites

  • 0
  Em 10/04/2012 em 17:55, chavephilips disse:

O script não funcionou muito bem, mas como você disse, seria melhor editar a lib.

 

Você poderia me ajudar com isso? seria em modules.lua?

 

Obrigado por enquanto mdr.gif

jura que não funcionou? nem passei todo o script, e essa função 'creatureGetName(cid)' não existe.

 

------------------------------------------------------------------

 

 

nome do seu npc.xml

<?xml version="1.0" encoding="UTF-8"?>
<npc name="Nome do seu npc" script="nome do seu script.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="133" head="114" body="119" legs="132" feet="114"/>
</npc>

 

 

 

nome do seu script.lua

dofile("data/npc/lib/npc-func.lua")
local focuses = {} -- do not change
function onCreatureSay(cid, type, msg)
local cid_Say = msg:lower()
if ((cid_Say == "hi") and not (isFocused(cid, focuses))) then
selfSay('Welcome '.. (getPlayerSex(cid) == PLAYERSEX_FEMALE and 'Mrs' or 'Mr') ..'. ' .. getPlayerName(cid) .. ',want to look my pearls? {Trade} with me!')
end
end
function onThink()
for _, focus in pairs(focuses) do
	if not isCreature(focus) then
	 removeFocus(focus, focuses)
	  talk_step = 0
	else
	 local distance = getDistanceTo(focus) or 5
		if distance > 4 then
			selfSay("Hmpf!", focus)
			removeFocus(focus, focuses)
		   talk_step = 0
		end
	end
end
setFocus(focuses)
end

 

 

crie um arquivo chamado "npc-func.lua" em "data/npc/lib" e poe isso

 

local focuses = {}
function isFocused(cid, t)
for i, v in pairs(t) do
	if(v == cid) then
		return true
	end
end
return false
end

function addFocus(cid, t)
if(not isFocused(cid, t)) then
	table.insert(t, cid)
end
end

function setFocus(t)
for i, v in pairs(t) do
	if(isPlayer(v)) then
		doNpcSetCreatureFocus(v)
		return
	end
end
doNpcSetCreatureFocus(0)
end

function removeFocus(cid, t)
for i, v in pairs(t) do
	if(v == cid) then
		table.remove(t, i)
		setFocus(focuses)
		break
	end
end
end

function onCreatureDisappear(cid)
if isFocused(cid, focuses) then
 removeFocus(cid, focuses)
	if isPlayer(cid) then
	 closeShopWindow(cid)
	end
end
end

Editado por Vodkart
Link para o comentário
https://xtibia.com/forum/topic/184177-resolvido-ajuda-no-script-npc/#findComment-1237894
Compartilhar em outros sites

  • 0

Caraca surprised.gif

 

Desculpa falar isso mas, o script não fala no NPC Channel (fala no default), mas o Mr. e o Mrs. funcionaram direito.

 

Não teria como fazer o que você falou lá em cima do |PLAYERSEX| ?

 

 

 

Muitíssimo obrigado por enquanto positive.gif

Link para o comentário
https://xtibia.com/forum/topic/184177-resolvido-ajuda-no-script-npc/#findComment-1237930
Compartilhar em outros sites

  • 0
  Em 10/04/2012 em 19:20, chavephilips disse:

Caraca surprised.gif

 

Desculpa falar isso mas, o script não fala no NPC Channel (fala no default), mas o Mr. e o Mrs. funcionaram direito.

 

Não teria como fazer o que você falou lá em cima do |PLAYERSEX| ?

 

 

 

Muitíssimo obrigado por enquanto positive.gif

ok

 

Primeiro vai em Data/lib/functions e adc essa função:

 

function getMrSex(cid)
return (getPlayerSex(cid) == PLAYERSEX_FEMALE and 'Mrs' or 'Mr')
end

 

Agora vamos para lib do npc

 

em Data/npc/lib/npcsystem

 

modules.lua

 

  Mostrar conteúdo oculto

 

 

npchandler.lua

 

  Mostrar conteúdo oculto

 

 

npcsystem.lua

 

  Mostrar conteúdo oculto

 

 

agora você pode usar assim:

 

<?xml version="1.0"?>
<npc name="Nome do seu npc" script="data/npc/scripts/script do seu npc.lua" walkinterval="50000" floorchange="0">
<health now="100" max="100"/>
<look type="129" head="95" body="116" legs="121" feet="115" addons="3"/>
<parameters>
<parameter key="message_greet" value="Hello |PLAYERSEX| |PLAYERNAME|. want to look my pearls? {Trade} with me!" />
</parameters>
</npc>

Link para o comentário
https://xtibia.com/forum/topic/184177-resolvido-ajuda-no-script-npc/#findComment-1237995
Compartilhar em outros sites

×
×
  • Criar Novo...