View Full Version : Random Race Generator and API

28-05-2018, 01:55
In the spirit of Spongleton's Randomizer page (https://project-cars-2-random.000webhostapp.com/), I've created my own that spits out a bit more detail. This takes the list of cars, tracks, weather, classes, and times to try to give you a pretty crazy race. I turned the script into an API just to play with Azure functions.

Here's the most basic output both tall (https://pc2randostorage.blob.core.windows.net/assets/PC2RandOut.html) and wide (https://pc2randostorage.blob.core.windows.net/assets/PC2RandOutW.html).

The API will spit out HTML or XML to be used how you like. Here's the API documentation https://pc2randostorage.blob.core.windows.net/assets/PC2RandAPI.html. See how to use it in your chat here (http://forum.projectcarsgame.com/showthread.php?63400-Random-Race-Generator-and-API&p=1527640&viewfull=1#post1527640).

I'm hosting all of the images myself and am missing a good amount so I did the best I could with what I had. Let me know if you find this useful or have any questions. If it gets too expensive to host, I'll make sure to give plenty of warning before it moves or is taken down.


pcars rookie
29-05-2018, 15:06
Thank you JasonSandwich, this is a great idea, well done.:yes:

01-06-2018, 16:00
I sloppily put together a mobile-friendly page that lets you choose the options in the API. Give it a swing.


It looks terrible on desktop. I'm not a CSS wizard or a web developer.

05-06-2018, 20:47
A few more minor updates make the cell page and the desktop page more friendly.



28-06-2018, 22:21
I just made another minor update and a few tweaks on the back end. The primary landing page will now redirect to the narrow width (mobile) site if it detects a narrow display.

I know some people out there are using this. I hope you enjoy! http://pc2rando.jasonsandwich.com

16-07-2018, 22:54
Want to use this in your stream chat? I made a quick custom command for a random car or track and simplified it to be used with common chat bots. If you'd like to add these to your chat, create a custom command to call the API.

In each sample below, "car" can be replaced with "track". You can specify dlc and karts for the car. There are lots of fancy ways to use this. Example uses the Nightbot command below.


Nightbot (Twitch): $(urlfetch https://pc2randomizer.azurewebsites.net/api/PC2Randomizer?format=car&karts=false&dlc=false)
Deepbot (Twitch): @customapi@[https://pc2randomizer.azurewebsites.net/api/PC2Randomizer?format=car]
Streamlabs Chatbot (Twitch/Mixer): $readapi(https://pc2randomizer.azurewebsites.net/api/PC2Randomizer?format=track)
Botisimo (Twitch/Mixer/Discord/YouTube): $(fetch https://pc2randomizer.azurewebsites.net/api/PC2Randomizer?format=$(query)) use is !command car or !command track

Let me know if you find more. Details and updates will be here (https://pc2randostorage.blob.core.windows.net/assets/PC2RandAPI.html). Thanks.

17-07-2018, 09:11
Can you just mix multiclass races?

17-07-2018, 13:22
Can you just mix multiclass races?

I'm not sure what you mean. If you want a second or third class to set up a multiclass race, just run it again. The car class is the final thing in parenthesis when the car is returned.

The big randomizer (in my signature) returns as many as four classes along with a car for you to drive from one of those classes.

20-07-2018, 15:18
Fantastic work Jason, I am going to really find this useful :)

20-07-2018, 16:41
I wanted to share some notes about this little project:

This is a free time labor of love. I'm not looking for money and it costs almost nothing to host.
There's no tracking at all on my end, no social media widget, nothing for you to block in any ad blocker. Go ahead and try it. I'm a security/privacy nut and I don't want to force anything like that on someone.
It's fully hosted through SSL on Azure. The reason I redirect to the Azure page instead of masking it is so you know exactly what you're getting. Nothing to hide.
I pulled the images from the Project CARS website and am hosting them myself. No hotlinking or sucking bandwidth from someone else's server.
I do use Javascript which can be a turnoff but you're welcome to view the page source to see that I'm not doing anything funky.
You are welcome to integrate this via API or share this anywhere with anyone. I'd like to make racing as fun as possible. I think a random race with buddies is some of the most fun you can have with PC2.
The meat of the script is written in PowerShell and can be run on the desktop with little modification.

You'll come across some impossible combos, some tracks that are weird, etc. Just roll the dice again and get something fun.

You guys are great. This is getting used (I see bandwidth out) and that's what I really want. :cheerful:

16-09-2018, 18:09
I have added the Ferrari DLC cars and tracks. https://pc2randostorage.blob.core.windows.net/assets/PC2RandAPI.html

19-09-2018, 04:50
Been away from PC2 for a fair while. I come back and see I inspired this. That makes me happy.:)

Yours is way better! Look forward to trying it!