About this mod
This mod fix a bug where your player character thats above 31+ level make traders/vendor to zero(0) gold.
- Requirements
- Permissions and credits
How does it work; well it wont work at first till you reach level 31+ and then it use a new calculation;
Your level * 200 gold; yep thats it. Also I cap it to 20,000 gold so it don't go out of hand when you long rest or level up.
-- Table to track if gold has been added for each trader
local traderGoldGiven = {}
local traderGoldAddedOnce = {}
-- Function to calculate the gold to be added based on the player's level
local function CalculateGold(player)
local level = Osi.GetLevel(player)
-- Check if the player level is below 31
if level and level >= 31 then
return level * 200 -- Calculate gold, no cap for now but capped later in AddGoldToTrader
else
return 0 -- Do nothing :D if the player level is below 31
end
end
-- Function to check and cap the gold that can be added to a trader
local function AddGoldToTrader(trader, goldAmount)
local currentGold = Osi.GetGold(trader) -- Get trader's current gold
if currentGold >= 20000 then return end -- No gold should be added if current gold exceeds 20,000
local goldToAdd = math.min(goldAmount, 20000 - currentGold) -- Cap the amount to not exceed 20,000
if goldToAdd > 0 then
Osi.AddGold(trader, goldToAdd) -- Add the calculated gold
traderGoldGiven[trader] = (traderGoldGiven[trader] or 0) + goldToAdd -- Track the added gold
traderGoldAddedOnce[trader] = true -- Mark that gold was added to this trader
end
end
-- Main event listener to add gold when a trade starts
Ext.Osiris.RegisterListener("PROC_StartTrade", 4, "before", function(player, trader, TRADEMODE, _)
-- Ignore the excluded trader
if trader == "S_GLO_JergalAvatar_0133f2ad-e121-4590-b5f0-a79413919805" then return end
-- Check if the player's level is below 31
local level = Osi.GetLevel(player)
if not level or level < 31 then return end -- Do nothing if player's level is below 31
-- Check if gold has already been added to this trader once
if traderGoldAddedOnce[trader] then return end
-- Calculate gold based on player level
local goldAmount = CalculateGold(player)
-- Add the calculated gold to the trader with a cap of 20,000 total
AddGoldToTrader(trader, goldAmount)
end)
-- Listener to reset gold-given state on level-up
Ext.Osiris.RegisterListener("LeveledUp", 1, "before", function(player)
-- Clear the "gold added" state for all traders when the player levels up
traderGoldAddedOnce = {}
end)
-- Listener to reset gold-given state on long rest
Ext.Osiris.RegisterListener("PROC_LongRest", 0, "before", function()
-- Clear the "gold added" state for all traders after a long rest
traderGoldAddedOnce = {}
end)