data/npc/scripts/troca7npc.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 playerHaveItems(cid, itemid) -- by MatheusMkalo
local items = type(itemid) == "table" and itemid or {itemid}
for i = 1, items do
if getPlayerItemCount(cid, items[i]) <= 0 then
return false
end
end
return true
end
function doPlayerRemoveItems(cid, itemid, count) -- by MatheusMkalo
local items = type(itemid) == "table" and itemid or {itemid}
for i = 1, items do
doPlayerRemoveItem(cid, items[i], count ~= nil and count or 1)
end
return nil
end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
if msgcontains(msg, "trocar") then
if playerHaveItems(cid, {2335, 2336, 2337, 2338, 2339, 2340, 2341}) then
doPlayerRemoveItems(cid, {2335, 2336, 2337, 2338, 2339, 2340, 2341}, 1)
doPlayerAddItem(cid, 2342, 1)
else
selfSay("Voce nao tem os items nescessarios para trocar por um novo.")
end
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
data/npc/Trocador de Items.xml:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Trocador" script="troca7npc.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="128" head="17" body="54" legs="114" feet="0" addons="2"/>
<parameters>
<parameter key="message_greet" value="Ola, diga {trocar} para trocar 7 items por 1."/>
</parameters>
</npc>
Nao testei, se nao funcionar avise.