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

Npc price fluctuations [rep given to all who help]

GhostX

Mapping Board Moderator
Staff member
Board Moderator
Joined
Nov 2, 2011
Messages
6,051
Reaction score
1,817
Location
UK
Twitch
ghostxpr0
The idea is simple: The npc buys certain loot from players, however the prices vary daily. E.g. Monday spike sword is 800gp, tuesday 850gp wednesday 1100gp and so on.

Basically i want a % of the price to fluctuate throughout the day to add some realism to my project as in "low stock from no new shipment therefore price increases etc" and monday and thursday would be the cheapest since the shipment arrives on monday and thursday..

Now i am thinking about the difficulties within the script?

Well maybe set it out with each day seperate e.g.
LUA:
EXAMPLE idk how scripts work tbh :P
------------------------------------
dosetprice (or w,e) condition Mon(0%)
Tues (2%)
wed (5%)
Thurs (0%)
Fri(7%)
Sat(5%)
sun(10%)

Since i want ALL items this npc will buy to fluctuate by the same percentage it wouldn't need to be item specific. therefore i guess it would be along the config of the script or something...

I don't know much about lua nevermind the rest of it (all though i am trying in my spare time)

I would be extremely greatful for any help/aid and/or guidance in the creation of this script.

regards
 
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
function PercentNumber(n)
percent = {
["Monday"] = 1,
["Tuesday"] = 2,
["Wednesday"] = 5,
["Thursday"] = 1,
["Friday"] = 7,
["Saturday"] = 5,
["Sunday"] = 10
}
return n + math.ceil(((percent[os.date("%A")]*n)/100))
end

local trade = { 
{id=2386, buy= PercentNumber(20) , sell= PercentNumber(8),name="axe"}, 
{id=2382, buy= PercentNumber(15), sell=  PercentNumber(4), name="club"},
{id=2413, buy= PercentNumber(2240), sell= PercentNumber(550), name="broadsword"}, 
}
 
local items = {}  
    for _, item in ipairs(trade) do
    items[item.id] = {item_id = item.id, buyPrice = item.buy, sellPrice = item.sell, subType = 0, realName = item.name}
end 
	local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)  
	    if items[item].buyPrice ~= 0 then  
	        doPlayerRemoveMoney(cid, amount * items[item].buyPrice)  
	        for i = 1, amount do 
	            doPlayerAddItem(cid, items[item].item_id, amount)  
	        end 
	    end 
	end 
	local onSell = function(cid, item, subType, amount, ignoreCap, inBackpacks)  
		if items[item].sellPrice ~= 0 then  
			doPlayerAddMoney(cid, items[item].sellPrice * amount)  
			doPlayerRemoveItem(cid, items[item].item_id, amount)  
		end 
	end 
    if msgcontains(msg, 'trade') then  
     openShopWindow(cid, trade, onBuy, onSell) 
    end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


info:

id=2386 -- item id

buy= PercentNumber(20) -- 20 this price original to buy

sell= PercentNumber(8) -- 8 this price original to sell

name= "axe" -- item name


exemple: sunday is 10%...

20 price + 10% sunday = 22 price final of the item
 
Last edited:
Will test this and i'll rep you regardless for the effort
and time you spent to help
me! Thanks alot mate
 
Back
Top