• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 0.X [7.72] NPC Buy all loots

potinho

Advanced OT User
Joined
Oct 11, 2009
Messages
1,403
Solutions
17
Reaction score
151
Location
Brazil
Hello guys,

I have a question and I was wondering if it is possible: I have NPCs who buy items and work perfectly. They buy in the quantity I determine, as in the print below, but he doesn't understand when I say "sell all". Is there a way for the NPC to understand? If yes, how? It would make it easier to sell the loots.

1609676115748.png
 
Last edited:
Solution
Not worked, but thanks for attention. Tried both ways. I say "sell all demon shield" (have 4 in bp) and he replies: "want to sell 1 demon shield...". Like i said, I don't know if it's duplicated, but npc.xml also has a sales parameter, is that correct? Because my original script dont sell anything, i change price and itens on npc.xml, and not LUA
Alright, fixed everything, I think.

Also added in the 'workaround', so that the items on your character don't get removed. (removes all items, then adds 1 item back)

Let me know how it goes.
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid)...
Got your npc code available?

I can show you how
Sure, thanks for reply btw.

npc.xml
XML:
<?xml version="1.0"?>
<npc name="Mad" script="data/npc/scripts/loot.lua" walkinterval="2000" floorchange="0">
     <look type="129" head="76" body="114" legs="124" feet="86"/>

    <parameters>
    <parameter key="module_shop" value="1" />
    <parameter key="message_greet" value="Hello |PLAYERNAME|. I buy swords, clubs, axes, helmets, boots, legs, shields and armors." />
    <parameter key="shop_sellable" 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;" />
    </parameters>
</npc>

scripts/loot.lua

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

-- Don't forget npcHandler = npcHandler in the parameters. It is required for all StdModule functions!
keywordHandler:addKeyword({'helmets'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = '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).'})
keywordHandler:addKeyword({'boots'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I buy golden boots (100k), steel boots (25k) and boots of haste (20k).'})
keywordHandler:addKeyword({'armors'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = '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).'})
keywordHandler:addKeyword({'legs'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I buy golden (80k), crown (12k), knight (6k), plate (500gp) and brass legs (100gp).'})
keywordHandler:addKeyword({'shields'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = '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).'})
keywordHandler:addKeyword({'swords'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = '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).'})
keywordHandler:addKeyword({'axes'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = '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).'})
keywordHandler:addKeyword({'clubs'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I buy thunder hammers (300k), war (4k), dragon (2k) and battle hammers (60gp), also skull staffs (10k) and clerical maces (200gp).'})
keywordHandler:addKeyword({'rings'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I buy ring of the sky (10k), gold ring (1k).'})
keywordHandler:addKeyword({'amulets'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I buy platinum amulet (1k), Stone Skin amulet (1k), scarf (500gp).'})

npcHandler:addModule(FocusModule:new())
 
Sure, thanks for reply btw.

npc.xml
XML:
<?xml version="1.0"?>
<npc name="Mad" script="data/npc/scripts/loot.lua" walkinterval="2000" floorchange="0">
     <look type="129" head="76" body="114" legs="124" feet="86"/>

    <parameters>
    <parameter key="module_shop" value="1" />
    <parameter key="message_greet" value="Hello |PLAYERNAME|. I buy swords, clubs, axes, helmets, boots, legs, shields and armors." />
    <parameter key="shop_sellable" 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;" />
    </parameters>
</npc>

scripts/loot.lua

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

-- Don't forget npcHandler = npcHandler in the parameters. It is required for all StdModule functions!
keywordHandler:addKeyword({'helmets'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = '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).'})
keywordHandler:addKeyword({'boots'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I buy golden boots (100k), steel boots (25k) and boots of haste (20k).'})
keywordHandler:addKeyword({'armors'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = '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).'})
keywordHandler:addKeyword({'legs'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I buy golden (80k), crown (12k), knight (6k), plate (500gp) and brass legs (100gp).'})
keywordHandler:addKeyword({'shields'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = '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).'})
keywordHandler:addKeyword({'swords'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = '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).'})
keywordHandler:addKeyword({'axes'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = '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).'})
keywordHandler:addKeyword({'clubs'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I buy thunder hammers (300k), war (4k), dragon (2k) and battle hammers (60gp), also skull staffs (10k) and clerical maces (200gp).'})
keywordHandler:addKeyword({'rings'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I buy ring of the sky (10k), gold ring (1k).'})
keywordHandler:addKeyword({'amulets'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I buy platinum amulet (1k), Stone Skin amulet (1k), scarf (500gp).'})

npcHandler:addModule(FocusModule:new())
Well this took a bit longer then I expected. lol
Most of my time was creating the sellable item list. xD

Let me know if you get any errors.
Script is currently untested.

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 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
	for i = 1, #itemTable do
		local 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
	for i = 1, #itemTable do
		local itemCount = getPlayerItemCount(cid, itemTable[i][2])
		if itemCount > 0 then
			doPlayerRemoveItem(cid, itemTable[i][2], itemCount)
			totalGold = totalGold + (itemCount * itemTable[i][3])
		end
	end
	doPlayerAddMoney(cid, totalGold)
	return true
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
	
	-- sell all
	if msgcontains(msg, "sell all") and talkState[talkUser] == 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[talkUser] = 1
		else
			selfSay(text, cid)
			talkState[talkUser] = 0
		end
		
	-- sell all confirmation
	elseif talkState[talkUser] == 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[talkUser] = 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())
 
Well this took a bit longer then I expected. lol
Most of my time was creating the sellable item list. xD

Let me know if you get any errors.
Script is currently untested.

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 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
    for i = 1, #itemTable do
        local 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
    for i = 1, #itemTable do
        local itemCount = getPlayerItemCount(cid, itemTable[i][2])
        if itemCount > 0 then
            doPlayerRemoveItem(cid, itemTable[i][2], itemCount)
            totalGold = totalGold + (itemCount * itemTable[i][3])
        end
    end
    doPlayerAddMoney(cid, totalGold)
    return true
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
 
    -- sell all
    if msgcontains(msg, "sell all") and talkState[talkUser] == 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[talkUser] = 1
        else
            selfSay(text, cid)
            talkState[talkUser] = 0
        end
     
    -- sell all confirmation
    elseif talkState[talkUser] == 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[talkUser] = 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())

You are a reference in this forum Xikini haha.

It hasn't worked yet, it's still the same, I say "sell all" and he understands it as a unit.

I don't know if it's duplicated, but npc.xml also has a sales parameter, is that correct?

1609895028169.png
 
Last edited:
You are a reference in this forum Xikini haha.

It hasn't worked yet, it's still the same, I say "sell all" and he understands it as a unit.

View attachment 53402
ahh. the main npc stuff is interfering with my script.

Can you change this line?
Lua:
if msgcontains(msg, "sell all") and talkState[talkUser] == 0 then
to something else?

like.. this?
Lua:
if msgcontains(msg, "sell everything") and talkState[talkUser] == 0 then

and if that doesn't work.. get rid of 'sell' entirely. :/
Lua:
if msgcontains(msg, "test") and talkState[talkUser] == 0 then
 
ahh. the main npc stuff is interfering with my script.

Can you change this line?
Lua:
if msgcontains(msg, "sell all") and talkState[talkUser] == 0 then
to something else?

like.. this?
Lua:
if msgcontains(msg, "sell everything") and talkState[talkUser] == 0 then

and if that doesn't work.. get rid of 'sell' entirely. :/
Lua:
if msgcontains(msg, "test") and talkState[talkUser] == 0 then
Not worked, but thanks for attention. Tried both ways. I say "sell all demon shield" (have 4 in bp) and he replies: "want to sell 1 demon shield...". Like i said, I don't know if it's duplicated, but npc.xml also has a sales parameter, is that correct? Because my original script dont sell anything, i change price and itens on npc.xml, and not LUA
 
Not worked, but thanks for attention. Tried both ways. I say "sell all demon shield" (have 4 in bp) and he replies: "want to sell 1 demon shield...". Like i said, I don't know if it's duplicated, but npc.xml also has a sales parameter, is that correct? Because my original script dont sell anything, i change price and itens on npc.xml, and not LUA
Alright, fixed everything, I think.

Also added in the 'workaround', so that the items on your character don't get removed. (removes all items, then adds 1 item back)

Let me know how it goes.
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 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())
 
Solution
Alright, fixed everything, I think.

Also added in the 'workaround', so that the items on your character don't get removed. (removes all items, then adds 1 item back)

Let me know how it goes.
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 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())
First sorry for last night, was late in Br and my girlfriend calls me.
Second, you're kind a god man, works haha, I dont know how to thank u. <3
 
Back
Top