Racing scripts for racing fans

Hey man. im using your fantastic script for a private server to do some racing with friends. we are also using moded cars. is there a way I can add the moded cars so they are recognised by your script. currently any moded car that is used just shows up as NULL in the records and stuff and im assuming they also will not get used for the random races. do you know how i would add these in to be used properly?
any help would be appreciated. i have very little experience with coding and such. I did try a few different things to add them in but no luck and dont think i can figure this out myself.

That’s because you need to define the Car name in a script within the folder your cars are in.

I haven’t used add-on vehicles with the scripts. I don’t have any experience with add-on vehicles, but, I’ll try to figure out how you can use them with my scripts. You will eventually add the name of the add-on vehicle to the vehicles.txt file which is used as the source of any vehicles you can spawn.

I’ve been working on the scripts and have changed quite a bit of it. There shouldn’t be any significant functional changes to the commands. I’ve changed the vehicles.txt file into a .json file as an example of what I’ve changed. I’ve also renamed the raceData.json file to trackData.json. I’ve also found and fixed a bunch of bugs that I didn’t notice before. I’m also working on how-to videos for the scripts which helped me find most of the bugs. After I’m satisfied with my changes, I’ll upload them to github. I don’t know when that will happen, but it shouldn’t be too long.

I just figured out how to spawn add-on vehicles. The vehicle’s model name is in the vechicles.meta file between the <modelName> tags.

For example, the model name for my add-on vehicle in the vehicles.meta file is:

<modelName>gemera</modelName>

I can spawn the vehicle with '/races spawn gemera'. Unfortunately, its name shows up as NULL like you posted. I’ve found one way to fix that.

In your fxmanifest.lua or __resource.lua file for the add-on vehicle, add the following:

client_script {
	'vehicle_names.lua'
}

In the same directory as the fxmanifest.lua or __resource.lua file of your add-on vehicle, create a file named 'vehicle_names.lua'

Add the following to the 'vehicle_names.lua' file:

Citizen.CreateThread(function()
	AddTextEntry('gemera', 'Koenigsegg Gemera')
end)

'gemera' is the model name and 'Koenigsegg Gemera' is the name displayed when you spawn the vehicle. You will need to do this for each add-on vehicle.

There’s probably a more elegant solution to this. It’s one solution I found that seems to work.

Add the model name of your add-on vehicles to the 'vehicles.txt' file and you should be able to use them in the drop-down lists in the panels. You should be able to use them in random vehicle races as well.

that is amazing thank you and worked that out so fast as well. i will update my server later and test this myself make sure i dont get any issues but you have explained it very clearly.
would i also add the model name to the vehicle class texts such as the 00 to 21 depending on what class i would want to put them in?
i also do have some vehicle packs that have more than one car, for those would i just add in a line to the same Vehicle_names.lua such as:

Citizen.CreateThread(function()
AddTextEntry(‘gemera’, ‘Koenigsegg Gemera’),
AddTextEntry(‘S98’, ‘Karin S98K’)
end)

I believe the vehicle class is set in the vehicles.meta file between the <vehicleClass> tags. The vehicle class text files are not used for anything anymore. They were a convenience for a past version of the scripts that used text files as vehicle lists. I’m going to remove them since they aren’t used anymore.

You are correct about adding a line to the Citizen.CreateThread function for each car in the multi-car add-on pack. I’ve tested this on a multi-car add-on pack and it works.

I did some testing with it last night and have the ones i tested and working with your script which is great. I havent had a chance to test the random races but by the looks of it i would agree and looks like it would work. though it is a little harder to test haha.

Thank you for your help and how quickly you got back to me with this.

@GamyTaziT So what’s the fix?

Most recent changes to the scripts:

-Removed player permissions code. Was way more complicated than what it was worth. It is possible for the same player to join a server using different names. It is also possible for different players to join a server using the same name.
-Removed updateRaceData and updateTrack functions
-Renamed raceData.json to trackData.json
-Modified aiGroupData.json: changed field ‘vehicleHash’ to ‘model’ in saveGrp and overwriteGrp functions
-Converted vehicles.txt to json file and saved as vehicles.json
-Removed vehicles/ directory and contents.

races_client:
-Fixed bug not being able to load AI group
-Fixed bug not being able to spawn AI in race using custom class
-Fixed bug where gamer tags would sometimes dissappear when spawning ai group
-Fixed bug where best lap vehicle name for AI driver was not updated in random vehicle races
-Fixed bug where player registered race, joined race, left race, started race and was told that start event was ignored because player was idle
-Fixed bug where player registered race, joined race, left race, started editing, started race and was told that start event was ignored because player was editing
-Fixed bug where AI DNF timeout never starts when human/AI finishes race if race owner does not join
-Probably fixed bug where camera transitions would break after around 10 race starts by using DestroyAllCams
-Added call-back function argument to RegisterNUICallback function and called it to get rid of warnings
-Added setBlipCheckpointColor function to simplify editWaypoints function
-Added respawn indicator inspired by RustyTheDalek
-When AI or player respawns in a race, use primary, secondary, pearlescent and wheel colors of previous vehicle with newly spawned vehicle
-Added primary, secondary, pearlescent and wheel color arguments to putPedInVehicle and switchVehicle functions
-When adding waypoint through waypoint map, put waypoint 1.0 higher than ground level instead of at ground level
-Added ability to change vehicle of spawned AI driver using ai spawn command
-Added ability to change vehicle that player is driving by using spawn command
-Only allow saving or overwriting AI groups when race is registered, not after race has started
-Disabled spawn command when player is joining a race or player is in a race
-Allow registering a race if editing a track
-Renamed ‘Edit’ panel to ‘Track’ panel
-Changed ‘/races panel’ command to use ‘track’ instead of ‘edit’
-Added panel names to top of each panel
-Changed blip name in waypoint map of racers who join race to ‘Racer’ instead of default ‘Destination’
-Update cash HUD when funds transactions occur

races_server:
-Fixed bug where players not given back buyin if joined to a race where AI are not allowed and then race is unregistered
-Fixed bug where players not given back buyin when player who registered race drops from server
-Fixed bug where players not given back buyin if prize distribution is invalid
-Fixed bug where players not given winnings after finishing race where AI are not allowed
-Fixed bug where player finishes race and races:delRacer event would be triggered for AI as well as humans instead of just for humans
-Fixed bug where races:finish event not sent to race owner(who did not join race) for AI finishers
-Removed winningsRL variable from races:finish event handler because it was redundant
-Used file names with LoadResourceFile and SaveResourceFile instead of file paths with native lua IO functions
-Load vehicles.json to create all vehicle list at server startup instead of loading vehicles.txt every time player joins

index.html:
-Renamed a lot of elements

index.css:
-Renamed a lot of elements

index.js:
-Renamed a lot of elements

Latest version of scripts at:

MAKE SURE TO READ ABOUT RECENT CHANGES THAT AFFECT THE PREVIOUS VERSION IN THE README.MD

1 Like

May go back and test this out on my local server, but specifically for The AI racing…

Looks like you have been busy…

Excellent

1 Like

It was a bunch of bug fixes and some command changes. Nothing new about the AI driving ability. If you find anything that seems broken, let me know please.

Nope,
I didnt mention there was anything new I was just saying, you have been busy & I was just making a statement, and was interested only in the Ai part ( Purely to make video footage) (I mean I never really tested it out before, anyway).