Automatic price change LUA

Hey i want the price in esx_drugs to change every 2 hours between these values… how do i get this to work?
image

Hello, this is a friendly reminder because this is your first time creating a topic (or it has been a while since your last topic) in this category.

Please note that most of the support is provided by the Cfx.re community on a voluntary basis. We ask you to be patient; there is no guarantee we have a solution to your problem(s). To avoid unnecessary/duplicate topics, please browse the forums before creating a topic.

To improve your chances of your issue(s) being solved, please provide as much information as possible about the issue(s) you are having. Also —whenever possible— please use the template given to you when creating a topic.

Thanks for keeping these forums tidy!
:mascot:

use this in server.lua

Config.DrugDealerItems = {
    heroin = math.random(384,918),
    marijuana = math.random(319,967),
    meth = math.random(1274,1587),
    coke = math.random(1027,1354),
    bagofdope = math.random(457,1487),
    lsd = math.random(1178,2579)
}

function changeDrugsPrice()
    Config.DrugDealerItems = {
        heroin = math.random(384,918),
        marijuana = math.random(319,967),
        meth = math.random(1274,1587),
        coke = math.random(1027,1354),
        bagofdope = math.random(457,1487),
        lsd = math.random(1178,2579)
    }
end

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(1000*60*120)
        changeDrugsPrice()
    end
end)

or

Config.DrugDealerItems = {}

function changeDrugsPrice()
    Config.DrugDealerItems = {
        heroin = math.random(384,918),
        marijuana = math.random(319,967),
        meth = math.random(1274,1587),
        coke = math.random(1027,1354),
        bagofdope = math.random(457,1487),
        lsd = math.random(1178,2579)
    }
end

Citizen.CreateThread(function()
    while true do
        changeDrugsPrice()
        Citizen.Wait(1000*60*120)
    end
end)

If you leave the array empty at the beginning, it will only update after 2 hours

Edit: Sorry I didn’t see that the wait is after the function (Should work fine)

thank you… It works ^^

how to i set in other script ?

The same way as it is done here ?
I can’t really say anything as you did not gave me any information on the other script

my script doesn’t have Config.DrugDealerItems

Config = {}
Config.Locale = 'en'

Config.DealerLocation = {
    ["Fish"] = {
        coords = {
            vector3(-3031.1628417969, 92.543334960938, 12.346242904663),
        },
        ["npc"] = {
            enable = true,
            hash = 0x5B44892C,
            heading = 328.6963,
        },
        ["blip"] = {
            enable = true,
            blipName = "Fish Sell",
            sprite = 365,
            color = 46,
            scale = 0.9,
        },
        ["drawText"] = {
            enable = true,
            farText = "Aquaman",
            text = "Press ~g~E~w~ to talk Aquaman.",
            distance = 1.5
        },
        ['animation'] = {
            enable = false,
            animDict = "mp_car_bomb",
            animName = "car_bomb_mechanic",
            animFlag = 49,
        },
        ['progressBar'] = {
            enable = true,
            text = 'Selling...',
            durationPerAmount = true, -- if is true progress time = duration*itemAmount 
            duration = 5000
        },
        ["items"] = {
           ["fish"] = 20,
        }
    },

You can change the price in server.lua (ESX.removemoney(price))

i dont have

(ESX.removemoney(price))

in my server.lua only have

RegisterServerEvent("cylex_npcdealer:server:sellItem")
AddEventHandler("cylex_npcdealer:server:sellItem", function(item, amount, cash)
    local player = ESX.GetPlayerFromId(source)
    if not player or amount == nil or amount < 1 then return end
    local count = player.getInventoryItem(item).count
    if count >= amount then 
        player.removeInventoryItem(item, amount) 
        player.addMoney(cash * amount)
        TriggerClientEvent('mythic_notify:client:SendAlert', player.source, { type = 'inform', text = _U('on_sell', amount, ESX.GetItemLabel(item), amount*cash)})
    else
        TriggerClientEvent('mythic_notify:client:SendAlert', player.source, { type = 'error', text = _U('not_enough_item')})
    end
end)

Ok i think in your config.lua this line is price

        ["items"] = {
           ["fish"] = 20,
        }

i already put

[“fish”] math.random (1000,1500),

But the price will be 1401 all the way . haha .

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.