Racing scripts for racing fans

Added ability to make racers start in a specified vehicle in random vehicle races. Respawns put players in new condition vehicles and delete the old vehicle. Respawns can be executed by pressing ‘F’ on keyboard, ‘Y’ on Xbox controller or ‘Triangle’ on DualShock controller for one second.

Race results are now saved to resources/races/[owner]_results.txt where [owner] is the owner of the race. Latest version at link in original post.

Hey, how can i change the position of the arrow? it’s too high up and can sometime be block by a bridge or trees in certain area.

Do you have the latest version? I lowered the checkpoint heights for everything. If not, then checkpoint heights are set in calls to makeCheckpoint. Here’s the definition:

local function makeCheckpoint(checkpointType, coord, nextCoord, color, alpha, num)

The height is set in the coord argument. Before the call to makeCheckpoint, I set the coord.z value to a number. Higher numbers are higher in height, lower numbers are lower in height. For example:

    local pedCoord = GetEntityCoords(PlayerPedId())
    local coord = {x = pedCoord.x, y = pedCoord.y, z = pedCoord.z, r = 5.0}
    local checkpoint = makeCheckpoint(arrow3Checkpoint, coord, nextCoord, yellow, 127, 5)

You will want to pass a modified copy of coord instead of modifying coord directly and then pass it to makeCheckpoint. For example:

local coordCopy = {x = coord.x, y = coord.y, z = coord.z - 5, r = coord.r}
local raceCheckpoint = makeCheckpoint(arrow3Checkpoint, coordCopy , nextCoord , yellow, 127, 0)

In the above, I made a copy of coord' with a modified height and passed it to makeCheckpoint. In the copy, I decreased the coord.z height by 5.


The variable raceCheckpoint is the yellow race checkpoint you see when racing. These are the ones you want to change the height of. There are only two places where raceCheckpoint is set. You should make a copy of the coord argument passed to makeCheckpoint and change the height. For example, change the following:

raceCheckpoint = makeCheckpoint(checkpointType, waypointCoord, nextCoord, yellow, 127, 0)

to

local coordCopy = {x = waypointCoord.x, y = waypointCoord.y, z = waypointCoord.z - 5, r = waypointCoord.r}
raceCheckpoint = makeCheckpoint(checkpointType, coordCopy, nextCoord, yellow, 127, 0)

I decreased the waypointCoord.z height by 5 in the copy.

Changed respawn key/button to ‘X’ key, ‘A’ button on Xbox controller, ‘cross’ button on DualShock controller.

Hi! First of all, thanks for your awesome work. I’m wondering if there’s any way to copy existing races from other racing script to this one.
Basically, it’s the same coord system but in Lua. Looks like this:image

Is this ESX only?

This should work for most frameworks.

You would have to manually copy the x, y, z coordinates and add an r value(radius). Take a look at the sample races in .json format. If you can copy those into a .json file and then import(read the README.md file on how to import races) you should be able to use the track.

1 Like

Alright! Is it possible to convert races from this form


to something like table or so? It’d be much easier to edit coords this way. There’re many races those have 30+ waypoints :grimacing:

Sorry, no. There is no easy way to do it. You would have to manually copy the coordinates to the format you want it.

Hey, it’s me again. I wanted to ask how results are calculated.
Let’s say we have 3 players racing together, sometimes a guy who has 100% the fastest time in the race somehow is displayed in the results like he came to the finish line 2nd, but actually he was 1st - no doubts. Also he gets credits for the 2nd place not for the 1st one.
Maybe I misunderstood how it works but I’d really appreciate any help :slight_smile:

Results are based on the time to finish the entire race. The shorter the time, the higher the place. I was assuming that the time to finish the race would mean that a racer who has a shorter time than another racer would physically finish before the other racer. If that’s not the case then that might mean racers are not starting at the same exact time which I assumed was the case. If you have video evidence of this, could I take a look at it? I might have to rework the timing.

1 Like

I tried to catch this bug today but the thing is it doesn’t appear anymore :flushed: I’ll let you know if it pops up again.
Also sometimes position counter is flickering (changing your position every sec).
I was the 3rd all the time.


image

For part of calculating the position, I use a native function that calculates the travel distance from your current position to the next waypoint. It’s sort of like a GPS distance calculator. Sometimes the function calculates distance using a weird path instead of one that is more direct. If this happens a lot, then I will need to change how to calculate postion. If you have video of this, I’d like to see when it is happening.

1 Like

Unfortunately, I can’t send you a video rn but yeah, it happens kinda often. The problem here is that I personally use custom maps with vanila map off for my server. They don’t have paths for GPS like GTA vanila map does => it almost always calculates it wrong, depends on checkpoints location actually.
It’s not a big deal honestly, so if there’s no way to fix or change it, I’m not gonna complain :slightly_smiling_face:
P.S. I’ll try to record and send you a video later.

I can change the position calculation using straight line distance from the current position to the next waypoint. It should work for most cases, but not all cases. That may work better for you.

Changed position calculation to use straight line distance from current location to next waypoint instead of using ‘CalculateTravelDistanceBetweenPoints’. Latest version at link in original post.

1 Like

Haven’t tested the new version but here’s a video with position calculation bug and a new bug I recently found: 2 - YouTube
0:07 - I’m the last one in that race but my position is 2 of 7
2:20-2:30 - 2 players left the server => left the race
4:45 - finish line
Now it’s time to explain what’s the problem. If there’re more than 4-5 people in race it tends to be broken, especially if someone leaves. After this race we wanted to start another one but we just couldn’t, the script decided that race isn’t finished yet => we can’t create a new race. The fun thing is that when we were trying to type /races leave, it said that there’s no race in progress rn. Schrodinger’s race ig :grin:
We can demonstrate it to you, if you want.

The new way I calculate position is based on the straight line distance from the racer’s current location to the next waypoint. The new way I’ve used to calculate position works best if there are checkpoints at every corner. It doesn’t know the race path other than the checkpoints. Having checkpoints at every corner helps to approximate the path and makes the position calculation more accurate. If you have tight S curves, like a switchback, between checkpoints, the position calculation will not be accurate. It will flip flop between players who have the shortest straight line distance to the next checkpoint.

In your video, I’m not sure why the race does not end when everyone finishes. It should take into account player dropouts. I’ll need to take a closer look at the code.

Thanks for testing.

1 Like