3 items

File information

Last updated

Original upload

Created by

BiasNil

Uploaded by

BiasNil

Virus scan

Safe to use

Tags for this mod

About this mod

This mod fix a bug where your player character thats above 31+ level make traders/vendor to zero(0) gold.

Share
Requirements
Permissions and credits
"If you're using the Level 30 mod along with the 210+ level addon and you notice that when you talk to a vendor to trade, they don't have any gold—this issue shouldn't happen anymore. However, since this is a new mod and I'm still learning about modding, please use this feedback to help me understand what might have gone wrong.

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)