Ir para conteúdo

Pergunta

2 respostass a esta questão

Posts Recomendados

  • 0
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) 
if(not npcHandler:isFocused(cid)) then 
return false  
end  

local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid  

if(msgcontains(msg, 'travel')) then 
selfSay('Ola |PLAYERNAME|, me de o item xxx e posso te teleportar. Ok?', cid) 
talkState[talkUser] = 1 
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if getPlayerItemCount(cid,ID DO ITEM) >= 1 then
if(doPlayerRemoveItem(cid, ID DO ITEM,1) == true) then
selfSay('Boa Viagem!', cid) 
talkState[talkUser] = 0 
else 
selfSay('Voc\ê n\ão tem o iten.', cid) 
talkState[talkUser] = 0 
end 
else
selfSay('Voc\ê n\ão tem o iten.', cid) 
talkState[talkUser] = 0 
end
end
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) 
npcHandler:addModule(FocusModule:new())

Link para o comentário
https://xtibia.com/forum/topic/185685-pedido-npc-teleport/#findComment-1255095
Compartilhar em outros sites

  • 0

More shorter than the other:


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)
if(not npcHandler:isFocused(cid)) then
return false  
end  

local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid  

if(msgcontains(msg, 'travel')) then
selfSay('Ola |PLAYERNAME|, me de o item xxx e posso te teleportar. Ok?', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if(doPlayerRemoveItem(cid, ID DO ITEM,1) == true) then
selfSay('Boa Viagem!', cid)
talkState[talkUser] = 0
else
selfSay('Voc\ê n\ão tem o iten.', cid)
talkState[talkUser] = 0
end
end
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

 

That helps to save some RAM... With 1 script, not too much... But with 30 or 40, you are saving a lot...

Editado por Dantarrixx
Link para o comentário
https://xtibia.com/forum/topic/185685-pedido-npc-teleport/#findComment-1255149
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novos posts.
×
×
  • Criar Novo...