• 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 prices by reputation

Faeyren

Active Member
Joined
Apr 2, 2009
Messages
11
Reaction score
28
I am trying to make the "sell" value in this code change based on the rank. Currently the code works to sell items at higher prices based on the rank, but the trade window doesn't update to reflect the new value.

I thought maybe this would do the trick
Code:
local rank = .75

local function getTable(player)
    local itemsList = {
        {name="axe ring", id=2208, buy=100, sell=(500*rank)},
This gives me "attempt to perform arithmetic on field 'sell' a nil value"





Mostly working code below-
Code:
local rank_neutral = .75
    local function getTable(player)
        local itemsList = {
            {name="ring", id=2208, buy=100, sell=500},
            {name="necklace", id=2209, buy=100, sell=500},
            {name="trinket", id=2188, buy=1000, sell=600}
    
    }
    
        return itemsList
    end
    
    local function setNewTradeTable(table)
        local items, item = {}
    
        for i = 1, #table do
            item = table[i]
            sellPrice = (item.sell * rank_neutral)
           items[item.id] = {itemId = item.id, buyPrice = item.buy, sellPrice, subType = item.subType, realName = item.name}
        print (sellPrice)
        end
    
        return items
    
    end
 
"Mostly working code below"
I will assume this is the full script you showed. And I can tell you this, you are never calling the function "getTable(player)".

Where you said there was an error is correct syntax, check this lua fiddle Baby shark doo doo doo doo (Lua) - myCompiler (https://www.mycompiler.io/view/Cu7u8Vk)

But since you are never calling and getting this table from the function, there is no column named "sell" and therefore it is nil.
 
IIRC NPCs are loaded on startup with their shops, prices etc. and stored source-side. To make sure you won't edit these prices for EVERYONE when one player trades with NPC, you should edit protocolgame.cpp code and change prices there, this will take care of players not seeing actual price in trade window. Then when player buys an item, just do math in Lua script.

 
Back
Top