Knight God
Member
- Joined
- Oct 19, 2008
- Messages
- 1,180
- Reaction score
- 21
NPC changing tokens for items, could someone give me a response to this request, please I need urgent: /
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
local tabla = {
["boots of haste"] = {10, 2195},
["demon helmet"] = {11, 2493},
["frozen starlight"] = {30, 2361},
["spellbook of dark mysteries"] = {20, 8918},
["royal crossbow"] = {20, 8851},
["stuffed dragon"] = {30, 5791},
["star tear"] = {100, 7735},
["jester staff"] = {100, 7958},
["vancini axe"] = {100, 8925},
["firewalker boots"] = {50, 9932},
["flame blade"] = {100, 8931}
}
local tokens = xxxx ---- ID of tokens
function creatureSayCallback(cid, type, msg)
local s = getPlayerItemCount
local msgn = "No tienes las TUITEMS necesarias"
if (msgcontains(msg, 'trade')) and s(cid,tokens) == 0 then
npcHandler:say('You dont have any ' .. getItemName(tokens) .. '', cid)
elseif msgcontains(msg, 'trade') and s(cid,tokens) >= 1 and s(cid,tokens) <= 0 then
npcHandler:say('You dont have enough ' .. getItemName(tokens) .. '!', cid)
elseif msgcontains(msg, 'trade') and s(cid,10581) >= 10 and s(cid,10581) <= 500 then
npcHandler:say('You can change your ' .. getItemName(tokens) .. ' for, {boots of haste}, {demon helmet}, {frozen starlight}, {spellbok of dark mysteries}, {royal crossbow} y {stuffed dragon} ... Y con mas de 30 fichas, {star tear}, {jester staff}, {vancini axe}, {flame blade} y {firewalker boots}', cid)
end
for txt, v in pairs(tabla) do
if msgcontains(msg, txt) then
if doPlayerRemoveItem(cid,tokens,v[1]) then
doPlayerAddItem(cid,v[2],1)
npcHandler:say("Aqui tienes tu ".. getItemNameById(v[2]) .."!", cid)
else
npcHandler:say("".. msgn .."", cid)
end
end
end
return true
end
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
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
local t = {
tokens = 5468, -- id of tokens
items = {
[1] = {"boots of haste", 10, 2195},
[2] = {"demon helmet", 10, 2493},
[3] = {"frozen starlight", 10, 2361},
[4] = {"spellbook of dark mysteries", 10, 8918},
[5] = {"royal crossbow", 10, 8851}
}
}
function creatureSayCallback(cid, type, msg)
imsexyandiknowit,s = 0, ""
for i = 1, #t.items do
imsexyandiknowit = imsexyandiknowit + 1
s = s .. "{" ..t.items[i][1].. "}"
b = i == #t.items and "." or i == (#t.items-1) and " and " or ", "
s = s .. b
end
if msgcontains(msg, 'trade') then
npcHandler:say("You can change your tokens for: " .. s .."", cid)
end
for i = 1, #t.items do
if msgcontains(msg, t.items[i][1]) then
if doPlayerRemoveItem(cid, t.tokens, t.items[i][2]) then
doPlayerAddItem(cid, t.items[i][3], 1)
npcHandler:say("Aqui tienes tu " .. t.items[i][1] .. "!", cid)
else
npcHandler:say("You don't have enough tokens!", cid)
end
end
end
return true
end
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())