Racing scripts for racing fans

oh ok.

Added ability to reverse race waypoints.

How difficult would it be to integrate this with esx? Similar to how the StreetRacing resource awards players money and allows them to bet money also? I’m still learning but I’m curious to have a go at it.

I’m working on adding race buy-ins and payouts. It will need to be ported to ESX or whatever system is desired by someone else.

Race buy-ins and payouts added. Latest version is at link in original post.

1 Like

Awesome! This is honestly a super in depth and very well explained resource. Really appreciate you adding in the money part as well as explaining how to add it to esx compat. :slight_smile:

No problem! My pleasure :slight_smile: It would be great if these scripts could be tested with multiple people and let me know if any bugs pop up.

1 Like

Currently I am running into an issue that I believe to be more with esx than your plugin… Unfortunately I cannot get any of your commands to work however because it keeps telling me that it is not a valid command. I haven’t the slightest clue on how to add your commands to the esx plugin, but what’s odder is that I don’t have this issue with any other ones. I’ve done some reading and it mentions something about using a RegisterCommand function instead of a chat message but again, I don’t understand enough about it all yet to decipher what that means.

Sorry about that, I thought I was having an issue registering your command to esx but it appears that I keep mucking up something when it comes to porting things over. Would you mind looking at what I did and tell me if I did it correctly? I’m still trying to learn how to do lua stuff and don’t understand some of the technical stuff yet… :c

local function xPlayer.getMoney()

return funds

end

local function xPlayer.removeMoney(money)

funds = funds - amount

end

local function xPlayer.addMoney(money)

funds = funds + amount

end

Those were the three lines I edited to use the esx money functions instead which seemed pretty straight forward. But apparently it’s saying there’s an error and I’m racking my brain trying to figure out what I did wrong. I bet it’s something stupid simple. I would greatly appreciate the guidance if you can give any.

Error parsing script. @ races_client.lua:125: ‘(’ expected near ‘.’

Update: I think I figured out that I did that thing completely backwards… I’ve tried it this way now but when I try to do /races funds it throws an error as well saying attempt to index a nil value global ‘xPlayer’

local function getFunds()

xPlayer.getMoney()

end

local function withdraw(amount)

xPlayer.removeMoney(money)

end

local function deposit(amount)

xPlayer.addMoney(money)

end

I’m not sure checking funds would actually even work correctly anyway, but I’ve yet to try a race.

Also. Even after resetting the client file to default and trying to list races it’s telling me error loading data. Not sure why.

I also cant save any races either… It keeps saying error loading data. Again, I’m using the default unedited client lua

Edit Edit: NVM… Looked above, got that part understood.

I’m not very familiar with ESX. You probably need to get an instance of xPlayer before using it and its functions. Maybe try asking how to do that on the ESX forums. I believe you need to replace ‘money’ in your call to the xPlayer functions with ‘amount’ like I did below.

local function getFunds()
xPlayer.getMoney()
end

local function withdraw(amount)
xPlayer.removeMoney(amount)
end

local function deposit(amount)
xPlayer.addMoney(amount)
end

You also need to make sure to place all the files in the ‘resources/races/’ directory. I believe you may have downloaded the files as ‘races-main.zip’ and extracted the contents to ‘resources/races-main/’. The scripts are looking for the file ‘resources/races/raceData.json’ and not finding it. Rename ‘races-main/’ to 'races/'.

2 Likes

I really appreciate any help you give. It means a lot to someone just starting to try stuff out on their own. I’ve been doing server stuff for years since fivereborn but this is the first year I have attempted to even try and configure/code or do any type of .lua or esx editing.

I might try to port the funds related functions to ESX myself. I don’t have ESX installed so I would need someone who has it to test the port.

1 Like

My attempt to port the funds functions using ESX functions is at the link in the original post. The instructions for using the port are right above the screenshots portion of the README.md. You will need to copy ‘races_client.lua’ and ‘races_server.lua’ in the ‘esx’ folder to your ‘resources/races/’ folder. Let me know if it works or not.

1 Like

Moved funds functions to ‘port.lua’. This makes porting to a framework like ESX easier, I hope. ‘fxmanifest.lua’ was modified to include ‘port.lua’ in the server scripts. Also note in the ESX port of ‘port.lua’ I made that if you do NOT want to initialize your funds to 5000, you should comment out line 123 in ‘races_client.lua’ by adding ‘--’ to the left of ‘TriggerServerEvent("races:initFunds", 5000)’. The latest version is at the link in the original post.

1 Like

You are AWESOME. I just came back after taking a break for a day, I will go and test this out asap. :slight_smile:

1 Like

So you totally just saved me a hell of a lot of work and I cannot thank you enough. ESX COMPATIBLE! It works flawlessly. Thank you so much. You are an awesome dev. If you have any tips or tricks or places to look for learning resources I would be eternally grateful because I definitely want to keep learning and understanding this stuff.

1 Like

Excellent! Thanks for testing it! When I first started learning about lua and a bunch of stuff in FiveM I looked at some existing code and looked up the functions at Home to see what they did. They have some introductory information there for people starting out. For learning lua I went to Programming in Lua (first edition) and Lua 5.4 Reference Manual - contents.

1 Like

Forgot to refund racers if the race they joined is unregistered. Fixed in latest version at link in original post.

1 Like

Super awesome! Thank you so much! :slight_smile:

1 Like

Hi, thank you for this awesome script.

Is it possible to have checkpoints that indicate the direction of the next checkpoint ? Like those listed here

EDIT : While using the ESX port.lua I have the following error in the server console

[        script:races] SCRIPT ERROR: @races/port.lua:42: attempt to index a nil value (local 'xPlayer')

I tried to search how to resolve it but without success. It’s not a major error the script works despite this. But I thought I should report it.

EDIT 2 : Nevermind I forgot to comment the line 123 again after updating.