Allowing a resource for a certain job

Hi guys,

New here and new to the coding community.

I want to lock the station jobs (where you fill it up) just to a job.

I am configuring the server file, but it never works.

I tried looking at the esx_ambulancejob and esx_policejob scripts to figure out how they make sure only EMS can open EMS menus / likewise for police, but all I found were something along the following lines which don’t work for the script I’m trying to customize a bit.

The parts I added are the lines with ++ at the beginning

ESX = nil

TriggerEvent(

Config.ESX.ESXSHAREDOBJECT,

function(a)

    ESX = a

end

)

local b = {}

local c = nil

function SendWebhookMessage(d, e)

if d ~= nil and d ~= "" then

    PerformHttpRequest(

        d,

        function(f, g, h)

        end,

        "POST",

        json.encode({content = e}),

        {["Content-Type"] = "application/json"}

    )

end

end

Citizen.CreateThread(

function()

    Wait(5000)

    MySQL.Sync.execute(

        [[CREATE TABLE IF NOT EXISTS `gas_station_business`( `gas_station_id` VARCHAR(50) NOT NULL DEFAULT '' COLLATE 'utf8mb4_general_ci', `user_id` VARCHAR(50) NOT NULL, `stock` INT(10) UNSIGNED NOT NULL DEFAULT '0', `price` INT(10) UNSIGNED NOT NULL DEFAULT '0', `stock_upgrade` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0', `truck_upgrade` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0', `relationship_upgrade` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0', `money` INT(10) UNSIGNED NOT NULL DEFAULT '0', `total_money_earned` INT(10) UNSIGNED NOT NULL DEFAULT '0', `total_money_spent` INT(10) UNSIGNED NOT NULL DEFAULT '0', `gas_bought` INT(10) UNSIGNED NOT NULL DEFAULT '0', `gas_sold` INT(10) UNSIGNED NOT NULL DEFAULT '0', `distance_traveled` DOUBLE UNSIGNED NOT NULL DEFAULT '0', `total_visits` INT(10) UNSIGNED NOT NULL DEFAULT '0', `customers` INT(10) UNSIGNED NOT NULL DEFAULT '0', `timer` INT(10) UNSIGNED NOT NULL DEFAULT '0', PRIMARY KEY (`gas_station_id`) USING BTREE) COLLATE='utf8mb4_general_ci' ENGINE=InnoDB ; CREATE TABLE IF NOT EXISTS `gas_station_balance` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `gas_station_id` VARCHAR(50) NOT NULL COLLATE 'utf8mb4_general_ci', `income` BIT(1) NOT NULL, `title` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_general_ci', `amount` INT(10) UNSIGNED NOT NULL, `date` INT(10) UNSIGNED NOT NULL, PRIMARY KEY (`id`) USING BTREE ) COLLATE='utf8mb4_general_ci' ENGINE=InnoDB ; CREATE TABLE IF NOT EXISTS `gas_station_jobs` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `gas_station_id` VARCHAR(50) NOT NULL DEFAULT '' COLLATE 'utf8mb4_general_ci', `name` VARCHAR(50) NOT NULL COLLATE 'utf8mb4_general_ci', `reward` INT(10) UNSIGNED NOT NULL DEFAULT '0', `amount` INT(11) NOT NULL DEFAULT '0', `progress` BIT(1) NOT NULL DEFAULT b'0', PRIMARY KEY (`id`) USING BTREE ) COLLATE='utf8mb4_general_ci' ENGINE=InnoDB ;]]

    )

    MySQL.Sync.execute("UPDATE `gas_station_jobs` SET progress = 0", {})

end

)

local i = 1

c = true

Citizen.CreateThread(

function()

    Wait(6000)

    for m, n in pairs(Config.gas_station_locations) do

        if not Config.gas_station_types[n.type] then

            if Config.lang == "br" then

                print(

                    "^8[" ..

                        GetCurrentResourceName() ..

                            "] Erro detectado no seu arquivo de configuracao, o tipo '" ..

                                n.type .. "' nao esta cadastrado em Config.gas_station_types^7"

                )

            else

                print(

                    "^8[" ..

                        GetCurrentResourceName() ..

                            "] Error detected in your configuration file, the type '" ..

                                n.type .. "' is not registered in Config.gas_station_types^7"

                )

            end

        end

    end

end

)

Citizen.CreateThread(

function()

    Citizen.Wait(10000)

    while Config.clear_gas_stations.active do

        local o = "SELECT gas_station_id, user_id, stock, timer FROM gas_station_business"

        local p = MySQL.Sync.fetchAll(o, {})

        for m, n in pairs(p) do

            local q = json.decode(n.stock)

            if

                n.stock <

                    Config.gas_station_types[Config.gas_station_locations[n.gas_station_id].type].stock_capacity *

                        Config.clear_gas_stations.min_stock_amount /

                        100

             then

                if n.timer + Config.clear_gas_stations.cooldown * 60 * 60 < os.time() then

                    local o = "DELETE FROM `gas_station_balance` WHERE gas_station_id = @gas_station_id;"

                    MySQL.Sync.execute(o, {["@gas_station_id"] = n.gas_station_id})

                    local o = "DELETE FROM `gas_station_jobs` WHERE gas_station_id = @gas_station_id;"

                    MySQL.Sync.execute(o, {["@gas_station_id"] = n.gas_station_id})

                    local o = "DELETE FROM `gas_station_business` WHERE gas_station_id = @gas_station_id;"

                    MySQL.Sync.execute(o, {["@gas_station_id"] = n.gas_station_id})

                    SendWebhookMessage(

                        Config.webhook,

                        Lang[Config.lang]["logs_lost_low_stock"]:format(

                            n.gas_station_id,

                            n.stock,

                            os.date("%d/%m/%Y %H:%M:%S", n.timer),

                            n.user_id ..

                                os.date(

                                    "\n[" ..

                                        Lang[Config.lang]["logs_date"] ..

                                            "]: %d/%m/%Y [" .. Lang[Config.lang]["logs_hour"] .. "]: %H:%M:%S"

                                )

                        )

                    )

                end

            else

                local o = "UPDATE `gas_station_business` SET timer = @timer WHERE gas_station_id = @gas_station_id"

                MySQL.Sync.execute(o, {["timer"] = os.time(), ["@gas_station_id"] = n.gas_station_id})

            end

            Citizen.Wait(100)

        end

        Citizen.Wait(1000 * 60 * 60)

    end

end

)

RegisterServerEvent(“gas_station:getData”)

AddEventHandler(

"gas_station:getData",

function(r)

    if c then

        local source = source

        local s = ESX.GetPlayerFromId(source)

        local t = s.identifier

        if t then

            local o = "SELECT user_id FROM `gas_station_business` WHERE gas_station_id = @gas_station_id"

            local query = MySQL.Sync.fetchAll(o, {["@gas_station_id"] = r})

            if query and query[1] then

                if query[1].user_id == t then

                    openUI(source, r, false)

                else

                    TriggerClientEvent(

                        "gas_station:Notify",

                        source,

                        "negado",

                        Lang[Config.lang]["already_has_owner"]

                    )

                end

            else

                local o = "SELECT gas_station_id FROM `gas_station_business` WHERE user_id = @user_id"

                local query = MySQL.Sync.fetchAll(o, {["@user_id"] = t})

                if query and query[1] and #query >= Config.max_stations_per_player then

                    TriggerClientEvent(

                        "gas_station:Notify",

                        source,

                        "negado",

                        Lang[Config.lang]["already_has_business"]

                    )

                else

                    TriggerClientEvent("gas_station:openRequest", source, Config.gas_station_locations[r].buy_price)

                end

            end

        end

    end

end

)

RegisterServerEvent(“gas_station:buyMarket”)

AddEventHandler(

"gas_station:buyMarket",

function(r)

    if c then

        local source = source

        local s = ESX.GetPlayerFromId(source)

        local t = s.identifier

        local u = Config.gas_station_locations[r].buy_price

        if Config.ESX.account_stores == "money" or Config.ESX.account_stores == "cash" then

            money = s.getMoney()

        else

            money = s.getAccount(Config.ESX.account_stores).money

        end

        if money >= u then

            if Config.ESX.account_stores == "money" or Config.ESX.account_stores == "cash" then

                s.removeMoney(u)

            else

                s.removeAccountMoney(Config.ESX.account_stores, u)

            end

            local o =

                "INSERT INTO `gas_station_business` (user_id,gas_station_id,stock,timer) VALUES (@user_id,@gas_station_id,@stock,@timer);"

            MySQL.Sync.execute(

                o,

                {["@gas_station_id"] = r, ["@user_id"] = t, ["@stock"] = 0, ["@timer"] = os.time()}

            )

            TriggerClientEvent("gas_station:Notify", source, "sucesso", Lang[Config.lang]["businnes_bougth"])

            SendWebhookMessage(

                Config.webhook,

                Lang[Config.lang]["logs_bought"]:format(

                    r,

                    t ..

                        os.date(

                            "\n[" ..

                                Lang[Config.lang]["logs_date"] ..

                                    "]: %d/%m/%Y [" .. Lang[Config.lang]["logs_hour"] .. "]: %H:%M:%S"

                        )

                )

            )

        else

            TriggerClientEvent(

                "gas_station:Notify",

                source,

                "negado",

                Lang[Config.lang]["insufficient_funds_store"]:format(u)

            )

        end

    end

end

)

RegisterServerEvent(“gas_station:getJob”)

AddEventHandler(

"gas_station:getJob",

function(r)

    local source = source

    local s = ESX.GetPlayerFromId(source)

    local t = s.identifier~

++ local xPlayer = ESX.GetPlayerFromId(source)

++ if xPlayer.job.name == ‘transporte’ then

    if t then

        local o =

            "SELECT id,name,reward FROM gas_station_jobs WHERE gas_station_id = @gas_station_id AND progress = 0 ORDER BY id ASC"

        local query = MySQL.Sync.fetchAll(o, {["@gas_station_id"] = r})[1]

        if query == nil then

            TriggerClientEvent("gas_station:Notify", source, "negado", Lang[Config.lang]["no_available_jobs"])

        end

        local o = "SELECT user_id FROM gas_station_business WHERE gas_station_id = @gas_station_id"

        local v = MySQL.Sync.fetchAll(o, {["@gas_station_id"] = r})[1]

        if v ~= nil and v.user_id == t then

            TriggerClientEvent("gas_station:Notify", source, "negado", Lang[Config.lang]["cannot_do_own_job"])

            query = nil

        end

        TriggerClientEvent("gas_station:getJob", source, r, query)

    end

end

)

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