Este é o .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
local items = {
item1 = {20972, 12832}, -- item1 item que será pedido e que será dado na primeira troca
item2 = {20972, 20959} -- item2 item que será pedido e que será dado na segunda troca
}
local counts = {
count1 = {1, 1}, -- count1 quantidade que será pedido e que será dado na primeira troca
count2 = {15, 1} -- count2 quantidade que será pedido e que será dado na segunda troca
}
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, 'master ball') then
selfSay('You want to swap '.. counts.count1[1] ..' '.. getItemNameById(items.item1[1]) ..' for '.. counts.count1[2] ..' '.. getItemNameById(items.item1[2]) ..'.',cid)
talkState[talkUser] = 1
elseif talkState[talkUser] == 1 then
if msgcontains(msg, 'yes') then
if getPlayerItemCount(cid, items.item1[1]) >= counts.count1[1] then
doPlayerRemoveItem(cid, items.item1[1], counts.count1[1])
doPlayerAddItem(cid, items.item1[2], counts.count1[2])
selfSay('You just swap '.. counts.count1[1] ..' '.. getItemNameById(items.item1[1]) ..' for '.. counts.count1[2] ..' '.. getItemNameById(items.item1[2]) ..'.', cid)
talkState[talkUser] = 0
else
selfSay('You need '.. counts.count1[1] ..' '.. getItemNameById(items.item1[1]) ..'.', cid)
end
else
selSay('Ok then!', cid)
talkState[talkUser] = 0
end
elseif msgcontains(msg, 'blazikenite') then
selfSay('You want to swap '.. counts.count2[1] ..' '.. getItemNameById(items.item2[1]) ..' for '.. counts.count2[2] ..' '.. getItemNameById(items.item2[2]) ..'.', cid)
talkState[talkUser] = 2
elseif talkSate[talkUser] == 2
if msgcontains(msg, 'yes') then
if getPlayerItemCount(cid, items.item2[1]) >= counts.count2[1] then
doPlayerRemoveItem(cid, items.item2[1], counts.count2[1])
doPlayerAddItem(cid, items.item2[2], counts.count2[2])
selfSay('You just swap '.. counts.count2[1] ..' '.. getItemNameById(items.item2[1]) ..' for '.. counts.count2[2] ..' '.. getItemNameById(items.item2[2]) ..'.', cid)
talkState[talkUser] = 0
else
selfSay('You need '.. counts.count2[1] ..' '.. getItemNameById(items.item2[1]) ..'.', cid)
end
else
selfSay('Ok then!', cid)
talkState[talkUser] = 0
end
end
return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
e este é o .xml:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Jax" script="Jax.lua" walkinterval="2000" floorchange="0">
<health now="150" max="150" />
<look type="134" head="57" body="59" legs="40" feet="76" corpse="2212" />
<parameters>
<parameter key="message_greet" value="Hello |PLAYERNAME|. Do not want to make an exchange? I have {master ball} and {blazikenite}." />
<parameter key="message_farewell" value="Bye bye!" />
</parameters>
</npc>