Racing scripts for racing fans

I think i have an idea that would be perfect for RP and similar servers.

You could try to recreate the SA’s Race Missions.

Instead of people having to write so many commands, it could have an option to allow players to go to markers and select the races they want to based on the marker’s location.

What do you think of that?

This looks like a single human playing against a bunch of AI’s. I made these scripts with multiple humans racing against each other in mind. With multiple humans, you need someone who creates the race. Then the people that want to participate need to join the race. Then someone needs to start the race. You can do that with my scripts. This requires coordination between all these people. It isn’t as easy as going to a location and then starting a race with everyone ready to race immediately.

2 Likes

Uh, i was talking about adding MARKERS with MENUS so people don’t have to go through a batch of COMMANDS.

COMMANDS are pretty much complicated to most of other players.

MARKERS have NOTHING to do with AI.

This can be easily enabled or even disabled through a config file.

OK. From the video, I thought you wanted to have it so people would go to a location and then start a race with everyone ready to race. I have not messed around with menus. The only tool I’ve used is a simple text editor. I think menus require a compiler and some other tools that I don’t have access to. I’ve tried to keep these scripts as simple as possible. There was another person named " tishio" who has posted in this thread who was able to create menus using the commands I wrote. You might want to talk to them and ask how they did it.

The closest thing the scripts have to a menu is the 3 panels you can bring up. Type ‘/races panel’ to bring up the main panel. Type ‘/races panel edit’ to bring up the edit tracks panel. Type ‘/races panel register’ to bring up the register races panel. These panels let you perform the same commands you would type in chat.

I noticed today after making a point to point track, that the best lap time only records if the track is freshly loaded, registered, and run. If you reverse the track, and register and run it again, any number of times, a best lap time is not recorded. If I clear the waypoints, and reload fresh and register and run, a blt is recorded again. Interesting, but not breaking anything.

If you make any modifications to a track that’s been loaded, it will not save best lap times because the best lap times are only valid for the original track. If you want to save best lap times for a modified track, you will need to save it as a new track first. If you try to overwrite the track, the best lapt times will be deleted.

I didn’t want best lap times of an unmodified version of the track to be mixed with best lap times of a modified version of the track. A modified version of the track may be shorter than the original and the best lap time would probably be shorter than a best lap time of the original. It doesn’t make sense to record best lap times of a modified track to the original track because they are different. I decided that any modification(even reversing and unreversing) should prevent you from recording a best lap time.

So reversing the waypoints is a modification.
Got it.

Hidden deep in the README.md:

If you are editing waypoints and have not saved them as a track or you have loaded a saved track and modified any of its waypoints, the best lap times will not be saved if you register and start a race using the unsaved or modified track. A modification to a saved track means adding, deleting, moving, increasing/decreasing radii, combining start/finish, separating start/finish or reversing waypoints. Changes can only be undone by reloading the saved track. If you have not saved your waypoints as a track or you loaded a saved track and modified any waypoints, you must save or overwrite the track to allow best lap times to be saved. NOTE THAT OVERWRITING A TRACK WILL DELETE ITS EXISTING BEST LAP TIMES.

2 Likes

Added race mode where AI drivers can be added to a race. Latest version at link in original post. Details in README.md.

2 Likes

cool! gonna test it out and see

i can’t edit nor register through the panel. how do i get full access of the menu.

Several panels.

/races panel
/races panel register
/races panel edit

yup, which i need access to.

You can set the following flags to false in races_server.lua and restart the server so everyone has permission

local requirePermissionToEdit <const> = false -- flag indicating if permission is required to edit tracks
local requirePermissionToRegister <const> = false -- flag indicating if permission is required to register races

or if you have those set to true, login to the client as the user you want to have those permissions and type:
‘/races request edit’ on the client

and on the server, type:
‘races listReqs’ to see the request

and then on the server type:
‘races approve [playerID]’ where [playerID] is the playerID listed in the listReqs command

Do the same to request permission to register
‘/races request register’ on the client

and on the server, type:
‘races listReqs’ to see the request

and then on the server type:
‘races approve [playerID]’

2 Likes

and there’s something i realise with the npc’s, is that they can’t drive addon cars very well. and aslo when i replace this line: waypointCoord.r with this: if #(pedCoord - vector3(waypointCoord.x, waypointCoord.y, waypointCoord.z)) < waypointCoord.r + 10.0 then, the ai’s won’t move.

The AI drivers aren’t great drivers to begin with. I suspect if you are using a custom map that doesn’t have pathing information like the original GTA map, then the AI drivers won’t know how to drive from their current location to their destination and will sit there doing nothing. Also, the AI drivers may not know how to get to their destination and will just sit there doing nothing even on the original map especially if the destination is not on a road/path. There may be nothing you can do about that. Placement of the waypoints may be critical to whether or not the AI drivers can reach those waypoints. The comments and code that tells the AI drivers to drive to their destination is below:

--TaskVehicleDriveToCoordLongrange(ped, vehicle, x, y, z, speed, driveMode, stopRange)
--driveMode: https://vespura.com/fivem/drivingstyle/
--actual speed is around speed * 2 mph
TaskVehicleDriveToCoordLongrange(driver.ped, driver.vehicle, driver.destWP.x, driver.destWP.y, driver.destWP.z, 60.0, 787004, driver.destWP.r * 0.5)

The AI driver’s destination is 'driver.destWP' x, y and z. They stop driving to 'driver.destWP' once they are within 'driver.destWP.r * 0.5' of 'driver.destWP'. In other words, they stop driving once they are within half the distance of the radius of the center of the waypoint. Once they are within half the radius, they drive to their next waypoint.

The line of code you are talking about, I think, only checks the human player’s proximity to their next waypoint. It does not check AI driver’s proximity to their next waypoint. The following line is the one that checks that:

if #(GetEntityCoords(driver.ped) - vector3(driver.destWP.x, driver.destWP.y, driver.destWP.z)) < driver.destWP.r then

3 Likes

So what do i need to replace to get the radius for the player? and yes i’m using the original GTA 5 Map. and evn though i modify the handling for AI in the handling file to SPORTS_CAR, they still drive like crap lol. but i appreciate all the effort you put into this mod for free.
.

Line 2305 in races_client.lua:

if #(playerCoord - vector3(waypointCoord.x, waypointCoord.y, waypointCoord.z)) < waypointCoord.r then

Just add 10.0 to waypointCoord.r:

if #(playerCoord - vector3(waypointCoord.x, waypointCoord.y, waypointCoord.z)) < waypointCoord.r + 10.0 then

2 Likes

So far i improve they’re speed, but they still drive like ass. i might try adjusting the checkpoints a little.

2 Likes

The following lines in races_client.lua affect the AI’s ability to drive. You may want to experiment with some different values.

Line 1007-1008: value range is 0.0 to 1.0

SetDriverAbility(aiState.drivers[aiName].ped, 1.0)
SetDriverAggressiveness(aiState.drivers[aiName].ped, 1.0)

Line 2543-2456: try different drive modes documented at Driving Style Calculator - GTA V

--TaskVehicleDriveToCoordLongrange(ped, vehicle, x, y, z, speed, driveMode, stopRange)
--driveMode: https://vespura.com/fivem/drivingstyle/
--actual speed is around speed * 2 mph
TaskVehicleDriveToCoordLongrange(driver.ped, driver.vehicle, driver.destWP.x, driver.destWP.y, driver.destWP.z, 60.0, 787004, driver.destWP.r * 0.5)

4 Likes