\data\npc\scripts crie scarabitens.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
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
local shopWindow = {}
local moeda = 2159 -- [ID DO SCARAB COIN]
local t = {
[1234] = {price = 15} -- [ID DO ITEM QUE SERÁ VENDIDO] = {QUANTO IRÁ CUSTAR}
[5678] = {price = 15}
[9101] = {price = 15}
[1213] = {price = 15}
}
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
if t[item] and not doPlayerRemoveItem(cid, moeda, t[item].price) then
selfSay("você não tem "..t[item].price.." "..getItemNameById(moeda), cid)
else
doPlayerAddItem(cid, item)
selfSay("aqui está seu item!", cid)
end
return true
end
if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then
for var, ret in pairs(t) do
table.insert(shopWindow, {id = var, subType = 0, buy = ret.price, sell = 0, name = getItemNameById(var)})
end
openShopWindow(cid, shopWindow, onBuy, onSell)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
\data\npc crie trocador.xml (ou qualquer nome que quiser, mas lembre de trocar no script abaixo também)
<?xml version="1.0"?>
<npc name="Trocador" script="data/npc/scripts/scarabitens.lua" access="5" lookdir="2" walkinterval="0">
<health now="200" max="200" />
<look type="324" head="95" body="95" legs="95" feet="95" addons="3" />
<parameters>
<parameter key="message_greet" value="Ola |PLAYERNAME|. Veio trocar uns scarabs coins por itens? Diga {trade}." />
</parameters>
</npc>