Racing scripts for racing fans

Could you try to use the original port.lua file instead of the one ported to ESX and see if you get the GetFunds error when you restart the server?

fxmanifest.lua

fx_version "cerulean"
game "gta5"

lua54 "yes"

dependency "chat"

client_script "races_client.lua"

client_script {
    'vehicle_names.lua'
}

shared_script '@es_extended/imports.lua'

server_scripts {
    "races_server.lua",
    "port.lua"
}

ui_page "html/index.html"
files {
    "html/index.css",
    "html/index.html",
    "html/index.js",
    "html/reset.css"
}```

port.lua

ESX = exports["es_extended"]:getSharedObject()

function GetFunds(source)
    local xPlayer = ESX.GetPlayerFromId(source)

    if xPlayer ~= nil then
        return xPlayer.getMoney()
    else
        return -1
    end
end

function SetFunds(source, amount)
    local xPlayer = ESX.GetPlayerFromId(source)

    if xPlayer ~= nil then
        if amount < 0 then
            xPlayer.setMoney(0)
        else
            xPlayer.setMoney(amount)
        end
    end
end

function Withdraw(source, amount)
    local xPlayer = ESX.GetPlayerFromId(source)

    if xPlayer ~= nil then
        if xPlayer.getMoney() < amount then
            xPlayer.setMoney(0)
        else
            xPlayer.removeMoney(amount)
        end
    end
end

function Deposit(source, amount)
    local xPlayer = ESX.GetPlayerFromId(source)

    if xPlayer ~= nil then
        xPlayer.addMoney(amount)
    end
end

function Remove(source)
    -- do nothing
end

After changing port.lua to an unmodified version, there is no GetFunds error, but it does not collect information from ox-inventory about the amount of playerā€™s money

Can you post what your server console displays during server startup? Do you see any errors during startup before the GetFunds error? Do you see any errors on the F8 client console?

FYI, the original port.lua keeps track of its own version of money. It does not do anything with ESX, so you wouldnā€™t see any changes in money in ESX.

This is log form my server when starting up with ESX port
fxserver_1709797246.log (48.1 KB)

I found this in your log:

[        script:races] SCRIPT ERROR: @es_extended/imports.lua:1: No such export getSharedObject in resource es_extended
[        script:races] SCRIPT ERROR: @races/port.lua:33: No such export getSharedObject in resource es_extended

Thanks for the log by the way. It looks like there may be an issue with your ESX installation. There should be a getSharedObject export.

The error is because

ESX = exports["es_extended"]:getSharedObject()

in your port.lua file fails to execute because your ESX does not have a getSharedObject export.
I donā€™t know how to help you with that, sorry.

I installed the latest version of es_extended and the error still appears

Iā€™m guessing here. Your ESX server should have a \resources\[core]\es_extended\server\common.lua file. In this file should be the following code:

exports("getSharedObject", function()
    return ESX
end)

I believe this is where getSharedObject is exported. Maybe your ESX server does not have this?

There is this entry in the [core]\es_extended\server\common.lua file

Something weird is going on. Try making a vanilla ESX server with just my resource and see if you have the same problem. If not, there is something weird going on that I have no idea how to fix.

Iā€™ll ask my developer friend if thereā€™s anything he can do about it. When I find out what causes this error, I will let you know. Thanks so much for all your help.

No problem. I definitely would like to know whatā€™s going on if your friend can figure out what the problem is.

Uploaded latest version to GitHub - emtneutrino/races

Video explaining new ā€˜recurā€™ and ā€˜orderā€™ parameters of random vehicle races:

2 Likes

Very useful video, thanks.

This script is great for No Props racing and AI, I love the flexability of the random races features, i may even start using it ago.

A few questions

1.Will your races ever support xml style tracks made with props?
2. Can i take the race results and best times etc and add it to a mysgl database, like I hvae here > https://randomraces.com/results/racing_list.php
3. Any plans to simplify the UI

I remember when You first started with this, it was very good then. It just gets better. Well done for your hard work and continued features etc.

1 Like

Itā€™s crazy how this is still being improved upon :+1:

1 Like

Thanks for liking the scripts.

  1. I donā€™t know exactly what you mean. Do you mean making the track data into xml and using props like a stack of tires or a cone instead of checkpoints?
  2. I could probably create a CSV or JSON file with the results. Maybe have a field saying the racer is human or AI or a separate file for only human racers.
  3. What kind of simplifications are you thinking about?
  1. I mean Like community races, basically loading a map created already, then using your script for checkpoints within that track. I say xml as i use another script that using xml data and lua to race. > [H@mer][GameRoom] Racing (GTA:O Style) + Map Creator

Currently your script is pure racing around the map anywhere, with the function of adding checkpoints and creating a track. (Which is fine)

I can load tracks with a script, then add your checkpoints to that track, but then I would have to keep offloading the track.

basically what im saying is your script with any premade track.

  1. That would be good if you could

  2. I have always thought the UI was very complicated, could you not use Native UI Or Rage style Menu for UI. I also find it irritating because its always centered and obstructing most of screen, just my constructive thoughts.

  1. Supporting xml tracks with props looks like a huge amount of work(I might be wrong). Iā€™m probably not going to support it any time soon. Also, what do you mean by ā€œI would have to keep offloading the trackā€?
  2. Iā€™ll create a JSON file of the results in addition to the results_[name].txt file unless you donā€™t need the results_[name].txt file. I believe I created the results_[name].txt file at your request. If you only need the JSON file, Iā€™ll get rid of results_[name].txt.
  3. Switching to Rage UI also looks like a big amount of work. One of my goals was not to depend on other resources(except chat). The aim of the UI is to support all possible chat commands, which does make it more complicated.