potinho
Advanced OT User
Good evening guys, how are you? I have this NPC that I copied from Ralke to sell some items with charge, but he takes the item and its quantity (2160 for crystal coin and 2148 for platinum) and its real value is not included. As I added a new currency in the game, I would like to adjust this NPC to use the correct function of removing money. Could you help me to fix it?
Lua:
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
item = 'You do not have the required items.'
done = 'Here you are.'
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
if msgcontains(msg, 'offer') then
selfSay('Here you can buy the following training items: {training sword}, {training axe}, {training club}, {training bow}, {training rod}, and {training wand}.', cid)
elseif msgcontains(msg, 'training sword') or msgcontains(msg, 'sword') then
if getPlayerItemCount(cid,2160) >= 400 or getPlayerItemCount(cid,2152) >= 40000 then
selfSay('Are you willing to pay 4,000,000 gold coins for {training sword}?', cid)
talk_state = 1
else
selfSay('I need 4,000,000 gold coins to give you the {training sword}. Come back when you have them.', cid)
talk_state = 0
end
elseif msgcontains(msg, 'yes') and talk_state == 1 then
talk_state = 0
if getPlayerItemCount(cid,2160) >= 400 or getPlayerItemCount(cid,2152) >= 40000 then
if doPlayerRemoveItem(cid,2160, 400) or doPlayerRemoveItem(cid,2152, 40000) == TRUE then
selfSay(done, cid)
local xx = doPlayerAddItem(cid, 5758, 1)
doItemSetAttribute(xx, "charges", 100)
end
else
selfSay(item, cid)
end
-- axe ---
elseif msgcontains(msg, 'training axe') or msgcontains(msg, 'axe') then
if getPlayerItemCount(cid,2160) >= 400 or getPlayerItemCount(cid,2152) >= 40000 then
selfSay('Are you willing to pay 4,000,000 gold coins for {training axe}?', cid)
talk_state = 2
else
selfSay('I need 4,000,000 gold coins to give you the {training axe}. Come back when you have them.', cid)
talk_state = 0
end
elseif msgcontains(msg, 'yes') and talk_state == 2 then
talk_state = 0
if getPlayerItemCount(cid,2160) >= 400 or getPlayerItemCount(cid,2152) >= 40000 then
if doPlayerRemoveItem(cid,2160, 400) or doPlayerRemoveItem(cid,2152, 40000) == TRUE then
selfSay(done, cid)
local xa = doPlayerAddItem(cid, 5759, 1)
doItemSetAttribute(xa, "charges", 100)
end
else
selfSay(item, cid)
end
-- club---
elseif msgcontains(msg, 'training club') or msgcontains(msg, 'club') then
if getPlayerItemCount(cid,2160) >= 400 or getPlayerItemCount(cid,2152) >= 40000 then
selfSay('Are you willing to pay 4,000,000 gold coins for {training club}?', cid)
talk_state = 3
else
selfSay('I need 4,000,000 gold coins to give you the {training club}. Come back when you have them.', cid)
talk_state = 0
end
elseif msgcontains(msg, 'yes') and talk_state == 3 then
talk_state = 0
if getPlayerItemCount(cid,2160) >= 400 or getPlayerItemCount(cid,2152) >= 40000 then
if doPlayerRemoveItem(cid,2160, 400) or doPlayerRemoveItem(cid,2152, 40000) == TRUE then
selfSay(done, cid)
local xb = doPlayerAddItem(cid, 5760, 1)
doItemSetAttribute(xb, "charges", 100)
end
else
selfSay(item, cid)
end
-- pally--
elseif msgcontains(msg, 'training bow') or msgcontains(msg, 'bow') then
if getPlayerItemCount(cid,2160) >= 400 or getPlayerItemCount(cid,2152) >= 40000 then
selfSay('Are you willing to pay 4,000,000 gold coins for {training bow}?', cid)
talk_state = 4
else
selfSay('I need 4,000,000 gold coins to give you the {training bow}. Come back when you have them.', cid)
talk_state = 0
end
elseif msgcontains(msg, 'yes') and talk_state == 4 then
talk_state = 0
if getPlayerItemCount(cid,2160) >= 400 or getPlayerItemCount(cid,2152) >= 40000 then
if doPlayerRemoveItem(cid,2160, 400) or doPlayerRemoveItem(cid,2152, 40000) == TRUE then
selfSay(done, cid)
local xc = doPlayerAddItem(cid, 5761, 1)
doItemSetAttribute(xc, "charges", 100)
end
else
selfSay(item, cid)
end
--druid--
elseif msgcontains(msg, 'training rod') or msgcontains(msg, 'rod') then
if getPlayerItemCount(cid,2160) >= 400 or getPlayerItemCount(cid,2152) >= 40000 then
selfSay('Are you willing to pay 4,000,000 gold coins for {training rod}?', cid)
talk_state = 5
else
selfSay('I need 4,000,000 gold coins to give you the {training rod}. Come back when you have them.', cid)
talk_state = 0
end
elseif msgcontains(msg, 'yes') and talk_state == 5 then
talk_state = 0
if getPlayerItemCount(cid,2160) >= 400 or getPlayerItemCount(cid,2152) >= 40000 then
if doPlayerRemoveItem(cid,2160, 400) or doPlayerRemoveItem(cid,2152, 40000) == TRUE then
selfSay(done, cid)
local xd = doPlayerAddItem(cid, 5756, 1)
doItemSetAttribute(xd, "charges", 100)
end
else
selfSay(item, cid)
end
--- sorcerer--
elseif msgcontains(msg, 'training wand') or msgcontains(msg, 'wand') then
if getPlayerItemCount(cid,2160) >= 400 or getPlayerItemCount(cid,2152) >= 40000 then
selfSay('Are you willing to pay 4,000,000 gold coins for {training wand}?', cid)
talk_state = 6
else
selfSay('I need 4,000,000 gold coins to give you the {training wand}. Come back when you have them.', cid)
talk_state = 0
end
elseif msgcontains(msg, 'yes') and talk_state == 6 then
talk_state = 0
if getPlayerItemCount(cid,2160) >= 400 or getPlayerItemCount(cid,2152) >= 40000 then
if doPlayerRemoveItem(cid,2160, 400) or doPlayerRemoveItem(cid,2152, 40000) == TRUE then
selfSay(done, cid)
local xf = doPlayerAddItem(cid, 5757, 1)
doItemSetAttribute(xf, "charges", 100)
end
else
selfSay(item, cid)
end
return true
end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())