• 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!

NPC trade sells for custom item (REQUEST)

tlundin

Almighty push all the noobs.
Joined
Jul 28, 2009
Messages
95
Reaction score
1
Hello! Is it possible to make a NPC sell items for other items instead of gold? Change gold value i guess you can call it...

For example:
I want to sell golden boots for 15 christmas tokens and get the trade window as in a normal NPC seller.

rep++ for help
 
Not 100% sure, if it works, but I think it should ;)

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 creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
local shopWindow = {}
local t = {
          [2195] = {price = 15, price2 = 10}, -- [ITEMID TO SELL] = {Buy cost (0 = not buyable), sell cost (0 = not sellable)}
          [2493] = {price = 25, price2 = 0},
          [2361] = {price = 30, price2 = 0},
          [8851] = {price = 20, price2 = 0},
          [8925] = {price = 30, price2 = 0},
          [2640] = {price = 50, price2 = 0},
          [2494] = {price = 100, price2 = 0},
          [9932] = {price = 50, price2 = 0},
          [2472] = {price = 70, price2 = 0},
          [8931] = {price = 100, price2 = 0}
          }
local TradeItem = 6527
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
	if getPlayerItemCount(cid, TradeItem) < t[item].price*amount then
		selfSay("You don't have enough christmas token.", cid)
	else
		doPlayerAddItem(cid, item, amount)
		doPlayerRemoveItem(cid, TradeItem, t[item].price*amount)
		doPlayerSendTextMessage(cid, 20, "You have bought " .. amount .. "x " .. getItemName(item) .. " for " .. t[item].price*amount .. " christmas token.")
	end
	return true
end
local onSell = function(cid, item, subType, amount)
	doPlayerRemoveItem(cid, item, amount)
	doPlayerAddItem(cid, TradeItem, t[item].price2*amount)
	doPlayerSendTextMessage(cid, 20, "You have sold " .. amount .. "x " .. getItemName(item) .. " for " .. t[item].price*amount .. " christmas token.")
	--selfSay("Here your are!", cid)
	return true
end
if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then
	for var, ret in pairs(t) do
		table.insert(shopWindow, {id = var, subType = 0, buy = ret.price, sell = ret.price2, name = getItemName(var)})
	end
	openShopWindow(cid, shopWindow, onBuy, onSell) end
	return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Update

I tested it, changed some things, and it should work now ;)
 
Last edited:
Not 100% sure, if it works, but I think it should ;)

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 creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
local shopWindow = {}
local t = {
          [2195] = {price = 15, price2 = 10}, -- [ITEMID TO SELL] = {Buy cost (0 = not buyable), sell cost (0 = not sellable)}
          [2493] = {price = 25, price2 = 0},
          [2361] = {price = 30, price2 = 0},
          [8851] = {price = 20, price2 = 0},
          [8925] = {price = 30, price2 = 0},
          [2640] = {price = 50, price2 = 0},
          [2494] = {price = 100, price2 = 0},
          [9932] = {price = 50, price2 = 0},
          [2472] = {price = 70, price2 = 0},
          [8931] = {price = 100, price2 = 0}
          }
local TradeItem = 6527
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
	if getPlayerItemCount(cid, TradeItem) < t[item].price*amount then
		selfSay("You don't have enough christmas token.", cid)
	else
		doPlayerAddItem(cid, item, amount)
		doPlayerRemoveItem(cid, TradeItem, t[item].price*amount)
		doPlayerSendTextMessage(cid, 20, "You have bought " .. amount .. "x " .. getItemName(item) .. " for " .. t[item].price*amount .. " christmas token.")
	end
	return true
end
local onSell = function(cid, item, subType, amount)
	doPlayerRemoveItem(cid, item, amount)
	doPlayerAddItem(cid, TradeItem, t[item].price2*amount)
	doPlayerSendTextMessage(cid, 20, "You have sold " .. amount .. "x " .. getItemName(item) .. " for " .. t[item].price*amount .. " christmas token.")
	--selfSay("Here your are!", cid)
	return true
end
if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then
	for var, ret in pairs(t) do
		table.insert(shopWindow, {id = var, subType = 0, buy = ret.price, sell = ret.price2, name = getItemName(var)})
	end
	openShopWindow(cid, shopWindow, onBuy, onSell) end
	return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Update

I tested it, changed some things, and it should work now ;)

if it works i will love you


sorry if i missed something obvious, but:

error.jpg
 
Last edited:

Similar threads

Back
Top