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 greet(cid) talkState[cid] = 0 return true end
local sellableItemList = {
-- {"item name", itemid, value}
{"steel shield", 2509, 70},
{"battle shield", 2513, 80},
{"dark helmet", 2490, 100},
{"royal helmet", 2498, 20000},
{"warrior helmet", 2475, 4000},
{"crusader helmet", 2497, 9000},
{"crown helmet", 2491, 3000},
{"devil helmet", 2462, 1000},
{"mystic turban", 2663, 500},
{"chain helmet", 2458, 35},
{"iron helmet", 2459, 30},
{"steel boots", 2645, 25000},
{"boots of haste", 2195, 20000},
--{"boh", 2195, 20000},
{"golden boots", 2646, 100000},
{"magic plate armor", 2472, 150000},
--{"mpa", 2472, 150000},
{"dragon scale mail", 2492, 40000},
--{"dsm", 2492, 40000},
{"demon armor", 2494, 300000},
{"golden armor", 2466, 20000},
{"crown armor", 2487, 10000},
{"knight armor", 2476, 5000},
{"blue robe", 2656, 10000},
{"lady armor", 2500, 2500},
{"plate armor", 2463, 400},
{"brass armor", 2465, 200},
{"chain armor", 2464, 100},
{"golden legs", 2470, 80000},
{"crown legs", 2488, 12000},
{"knight legs", 2477, 6000},
{"plate legs", 2647, 500},
{"brass legs", 2478, 100},
{"mastermind shield", 2514, 80000},
--{"mms", 2514, 80000},
{"demon shield", 2520, 30000},
{"blessed shield", 2523, 500000},
{"great shield", 2522, 400000},
{"vampire shield", 2534, 15000},
{"medusa shield", 2536, 8000},
{"amazon shield", 2537, 4000},
{"crown shield", 2519, 5000},
{"tower shield", 2528, 4000},
{"guardian shield", 2515, 2000},
{"beholder shield", 2518, 1500},
{"dragon shield", 2516, 3000},
{"dwarven shield", 2525, 100},
{"magic longsword", 2390, 100000},
{"warlord sword", 2408, 900000},
{"magic sword", 2400, 80000},
{"giant sword", 2393, 15000},
{"bright sword", 2407, 6000},
{"ice rapier", 2396, 4000},
{"fire sword", 2392, 3000},
{"serpent sword", 2409, 1500},
{"two handed sword", 2377, 400},
{"broad sword", 2413, 100},
{"short sword", 2406, 30},
{"sword", 2376, 30},
{"dragon lance", 2414, 9000},
{"stonecutter axe", 2431, 6000},
{"guardian halberd", 2427, 7500},
{"fire axe", 2432, 10000},
{"knight axe", 2430, 4000},
{"double axe", 2387, 300},
{"halberd", 2381, 400},
{"battle axe", 2378, 150},
{"hatchet", 2388, 20},
{"war hammer", 2391, 1000},
{"thunder hammer", 2421, 300000},
{"skull staff", 2436, 4000},
{"dragon hammer", 2434, 2000},
{"clerical mace", 2423, 200},
{"battle hammer", 2417, 60},
{"mace", 2398, 30},
{"ring of the sky", 2123, 10000},
{"naginata", 2426, 5000},
{"gold ring", 2179, 1000},
{"platinum amulet", 2171, 2000},
{"stone skin amulet", 2197, 1000},
{"scarf", 2661, 500},
{"steel helmet", 2457, 200}
}
local function createSellableItemTextFromTable(cid, itemTable) -- {"item name", itemid, value}
local text = ""
local totalGold = 0
local playerItems = {}
for i = 1, 10 do
local slotItem = getPlayerSlotItem(cid, i)
if slotItem.itemid > 0 then
table.insert(playerItems, slotItem.itemid)
end
end
for i = 1, #itemTable do
local itemCount = (isInArray(playerItems, itemTable[i][2]) and -1 or 0)
itemCount = itemCount + getPlayerItemCount(cid, itemTable[i][2])
if itemCount > 0 then
if text ~= "" then
text = text .. ", "
end
text = text .. itemCount .. " " .. itemTable[i][1]
totalGold = totalGold + (itemCount * itemTable[i][3])
end
end
if totalGold > 0 then
text = text .. " for " .. totalGold .. " gold coins"
else
text = "Sorry, you have nothing of value to sell currently."
end
return text
end
local function sellAllItemsFromTable(cid, itemTable) -- {"item name", itemid, value}
local totalGold = 0
local playerItems = {}
for i = 1, 10 do
local slotItem = getPlayerSlotItem(cid, i)
if slotItem.itemid > 0 then
table.insert(playerItems, slotItem.itemid)
end
end
for i = 1, #itemTable do
local itemCount = (isInArray(playerItems, itemTable[i][2]) and -1 or 0)
itemCount = itemCount + getPlayerItemCount(cid, itemTable[i][2])
if itemCount > 0 then
doPlayerRemoveItem(cid, itemTable[i][2], (isInArray(playerItems, itemTable[i][2]) and itemCount + 1 or itemCount))
totalGold = totalGold + (itemCount * itemTable[i][3])
if isInArray(playerItems, itemTable[i][2]) then
doPlayerAddItem(cid, itemTable[i][2], 1)
end
end
end
doPlayerAddMoney(cid, totalGold)
return true
end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
-- sell all
if msgcontains(msg, "sell all") and talkState[cid] == 0 then
local text = createSellableItemTextFromTable(cid, sellableItemList)
if text ~= "Sorry, you have nothing of value to sell currently." then
selfSay("Do you want to sell " .. text .. "?", cid)
talkState[cid] = 1
else
selfSay(text, cid)
talkState[cid] = 0
end
-- sell all confirmation
elseif talkState[cid] == 1 then
if msgcontains(msg, "yes") then
local text = createSellableItemTextFromTable(cid, sellableItemList)
if text ~= "Sorry, you have nothing of value to sell currently." then
sellAllItemsFromTable(cid, sellableItemList)
selfSay("You have sold " .. text .. ".", cid)
else
selfSay(text, cid)
end
else
selfSay("Another time, then.", cid)
end
talkState[cid] = 0
-- sell information
elseif msgcontains(msg, "helmets") then
selfSay("I buy royal (20k), warrior (4k), crusader (9k), crown (3k), devil (1k), chain (35gp) and iron helmets (30gp), steel helmets (200gp) also mystic turbans (500gp).", cid)
elseif msgcontains(msg, "boots") then
selfSay("I buy golden boots (100k), steel boots (25k) and boots of haste (20k).", cid)
elseif msgcontains(msg, "armors") then
selfSay("I buy golden (20k), crown (10k), knight (5k), lady (2,5k), plate (400gp), brass (200gp) and chain armors (100gp), also mpa (150k), dsm (40k) and blue robes (15k).", cid)
elseif msgcontains(msg, "legs") then
selfSay("I buy golden (80k), crown (12k), knight (6k), plate (500gp) and brass legs (100gp).", cid)
elseif msgcontains(msg, "shields") then
selfSay("I buy blessed (500k), great (400k), demon (30k), vampire (15k), medusa (8k), amazon (4k), crown (5k), tower (4k), dragon (3k), guardian (2k), beholder (1k), and dwarven shields (100gp), also mms (80k).", cid)
elseif msgcontains(msg, "swords") then
selfSay("I buy giant (15k), bright (6k), fire (3k) serpent (1.5k), spike (800gp) and two handed swords (400gp), also ice rapiers (4k), magic longswords (150k), magic swords (90k), warlord swords (100k) broad swords (70gp), short swords (30gp), sabres (25gp) and swords (25gp).", cid)
elseif msgcontains(msg, "axes") then
selfSay("I buy fire (10k), guardian halberds (7,5k), naginata (5k) knight (2k), double (200gp) and battle axes (100gp), also dragon lances (10k), stonecutters axes (90k), halberds (200gp) and hatchets (20gp).", cid)
elseif msgcontains(msg, "clubs") then
selfSay("I buy thunder hammers (300k), war (4k), dragon (2k) and battle hammers (60gp), also skull staffs (10k) and clerical maces (200gp).", cid)
elseif msgcontains(msg, "rings") then
selfSay("I buy ring of the sky (10k), gold ring (1k).", cid)
elseif msgcontains(msg, "amulets") then
selfSay("I buy platinum amulet (1k), Stone Skin amulet (1k), scarf (500gp).", cid)
end
return true
end
npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())