Ray Rewind
Doctor
Hey I try to make an NPC which trades certain amount of items for another item
Code:
16:10 GOD Rewind [500]: enchanted chicken wing
16:10 Yaman: Are you sure you would like to trade your boots of haste for an enchanted chicken wing?
16:10 GOD Rewind [500]: yes
16:10 Yaman: Sorry, you do not have four Warrior Helmets.
Code:
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, "warrior's sweat") then
if getPlayerItemCount(cid, 2475) >= 4 then
npcHandler:say("Are you sure you would like to trade {four} or your helmet's for a {flask of warrior's sweat}?", cid)
talkState[talkUser] = 1
else
npcHandler:say("Sorry, you do not have {four} Warrior Helmets.", cid)
talkState[talkUser] = 0
end
elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
if getPlayerItemCount(cid, 2475) >= 4 then
doPlayerRemoveItem(cid, 2475, 4)
npcHandler:say("Here you are.", cid)
doPlayerAddItem(cid, 5885, 1)
talkState[talkUser] = 0
else
npcHandler:say("Sorry, you do not have {four} Warrior Helmets.", cid)
talkState[talkUser] = 0
end
elseif msgcontains(msg, "no") then
npcHandler:say("Then not.", cid)
talkState[talkUser] = 0
elseif msgcontains(msg, "enchanted chicken wing") then
if getPlayerItemCount(cid, 2195) >= 1 then
npcHandler:say("Are you sure you would like to trade your boots of haste for an {enchanted chicken wing}?", cid)
talkState[talkUser] = 1
else
npcHandler:say("Sorry, you do not have a pair of Boots of Haste.", cid)
talkState[talkUser] = 0
end
elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
if getPlayerItemCount(cid, 2195) >= 1 then
doPlayerRemoveItem(cid, 2195, 1)
npcHandler:say("Here you are.", cid)
doPlayerAddItem(cid, 5891, 1)
talkState[talkUser] = 0
else
npcHandler:say("Sorry, you do not have a pair of Boots of Haste.", cid)
talkState[talkUser] = 0
end
elseif msgcontains(msg, "no") then
npcHandler:say("Then not.", cid)
talkState[talkUser] = 0
elseif msgcontains(msg, "fighting spirit") then
if getPlayerItemCount(cid, 2498) >= 2 then
npcHandler:say("Are you sure you would like to trade {two} royal helmets for a {fighting spirit}?", cid)
talkState[talkUser] = 1
else
npcHandler:say("Sorry, you do not have {two} Royal Helmets.", cid)
talkState[talkUser] = 0
end
elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
if getPlayerItemCount(cid, 2498) >= 2 then
doPlayerRemoveItem(cid, 2498, 2)
npcHandler:say("Here you are.", cid)
doPlayerAddItem(cid, 8182, 1)
talkState[talkUser] = 0
else
npcHandler:say("Sorry, you do not have {two} Royal Helmets.", cid)
talkState[talkUser] = 0
end
elseif msgcontains(msg, "no") then
npcHandler:say("Then not.", cid)
talkState[talkUser] = 0
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())