• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

10% discount on NPC [HARD]

Dankoo

Active Member
Joined
Sep 4, 2010
Messages
1,007
Reaction score
27
if isVIP then set price = 0.9

Is there ah way? It's very useful, but must be hard to do

Thanks :peace:.
 
yeah but I wanted an real discount system you know, maybe a function ifgetplayervipdays > 1 then, or isVip then u know
 
hippo_bump.jpg
 
Yep.
PHP:
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 config = {
				storage = 1234,
				conversion = 0.9
				}

local trades = {
				{id=2457, buy=800, sell=100, name='steel helmet'},
				{id=2471, buy=800, sell=100, name='golden helmet'}
				}
				
local items = {}
for i = #trades, 1, -1 do
	v = trades[i]
	if getPlayerStorageValue(cid, config.storage) == -1 then
		price = v.buy
	else
		price = math.floor(v.buy * config.conversion)
		v.buy = math.floor(v.buy * config.conversion)
	end
	items[v.id] = {item_id = v.id, buyPrice = price, sellPrice = v.sell, subType = 0, realName = v.name}
end
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
	if doPlayerRemoveMoney(cid, amount * items[item].buyPrice) then
		selfSay('You have bought '..amount..' '..items[item].realName..' for '..items[item].buyPrice * amount..' gold coins.', cid)
		doPlayerAddItem(cid, item, amount)
	else
		selfSay('You have not enough money.', cid)
	end
end
local onSell = function(cid, item, subType, amount, ignoreCap, inBackpacks)
	if doPlayerRemoveItem(cid, item, amount) then
		selfSay('You sold '..amount..' '..items[item].realName..' for '..items[item].sellPrice * amount..' gold coins.', cid)
		doPlayerAddMoney(cid, amount * items[item].sellPrice)
	end
end
if msgcontains(msg, 'trade') then
	selfSay('It\'s my offert.', cid)
	return openShopWindow(cid, trades, onBuy, onSell)
end 
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) 
npcHandler:addModule(FocusModule:new())
 
Function lib:
PHP:
function changePriceTradeItems(cid, trades, conversion, storage, value, message)
if value == nil then value = 1 end
if message == nil then message = 'It\'s my offert.' end
local items = {}
for i = #trades, 1, -1 do
	v = trades[i]
	if getPlayerStorageValue(cid, storage) == value then
		price = math.floor(v.buy * conversion)
		v.buy = math.floor(v.buy * conversion)
	else
		price = v.buy
	end
	items[v.id] = {item_id = v.id, buyPrice = price, sellPrice = v.sell, subType = 0, realName = v.name}
end
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
	if doPlayerRemoveMoney(cid, amount * items[item].buyPrice) then
		selfSay('You have bought '..amount..' '..items[item].realName..' for '..items[item].buyPrice * amount..' gold coins.', cid)
		doPlayerAddItem(cid, item, amount)
	else
		selfSay('You have not enough money.', cid)
	end
end
local onSell = function(cid, item, subType, amount, ignoreCap, inBackpacks)
	if doPlayerRemoveItem(cid, item, amount) then
		selfSay('You sold '..amount..' '..items[item].realName..' for '..items[item].sellPrice * amount..' gold coins.', cid)
		doPlayerAddMoney(cid, amount * items[item].sellPrice)
	end
end
selfSay(message, cid)
return openShopWindow(cid, trades, onBuy, onSell)
end
And for example:
PHP:
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
storage = 1234
conversion = 0.9
local trades = {
				{id=2457, buy=800, sell=100, name='steel helmet'},
				{id=2471, buy=800, sell=100, name='golden helmet'}
				}
if msgcontains(msg, 'trade') then				
	return changePriceTradeItems(cid, trades, conversion, storage)
end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) 
npcHandler:addModule(FocusModule:new())


changePriceTradeItems(cid, trades, conversion, storage, value, word, message)
cid is Player, trades is table with items, conversion is... conversion, storage what you need, value storagevalue what you need to lower prices, message, for example 'it's my offert'.
 
DUUUDE

Thanks to your idea I've managed to make a change in the modules.lua that worked perfectly:

LUA:
		if(doPlayerRemoveItem(cid, itemid, amount, subType)) then
			local msg = self.npcHandler:getMessage(MESSAGE_SOLD)
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, self.npcHandler:parseMessage(msg, parseInfo))
		if getPlayerStorageValue(cid, 20500) == -1 then
			doPlayerAddMoney(cid, amount * shopItem.sell)
			elseif getPlayerStorageValue(cid, 20500) == 1 then
			doPlayerAddMoney(cid, amount * shopItem.sell * 1.2)
			end
			if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
				self.npcHandler.talkStart[cid] = os.time()
			else
				self.npcHandler.talkStart = os.time()
			end

			return true
		end

Now all NPCs that use shop_sellable module buys items 20% more expensive from players

Thanks for the storage idea, couldn't do it without your help!
 
Back
Top