Sign in to follow this  

VehicleData.json generator

Recommended Posts

Hi Guys,

Had someone in a discord ask about generating an updated version of vehicleData.json so i took it on as a challenge for myself to create some code that will automatically grab the vehicles listed on the wiki and create some information about them into a JSON File. Feel free to extend this or do whatever.


    public class GetVehicleInfo : Script
        public GetVehicleInfo()
        public static Task<string> MakeAsyncRequest(string url, string contentType)
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.ContentType = contentType;
            request.Method = WebRequestMethods.Http.Get;
            request.Timeout = 20000;
            request.Proxy = null;
            Task<WebResponse> task = Task.Factory.FromAsync(
                asyncResult => request.EndGetResponse(asyncResult),
            return task.ContinueWith(t => ReadStreamFromResponse(t.Result));
        private static string ReadStreamFromResponse(WebResponse response)
            using (Stream responseStream = response.GetResponseStream())
            using (StreamReader sr = new StreamReader(responseStream))
                //Need to return this response
                string strContent = sr.ReadToEnd();
                return strContent;
        public async Task<List<string>> ReturnVehicleNamesAsync(Client player)
            List<string> tempVehicleStore = new List<string>();
            player.SendChatMessage("Fetching vehicle data... this may take a couple seconds.");
            string html = await MakeAsyncRequest("", "text/html");
            string pattern = @"<code[^>]*?>(.*?)</code>";
            MatchCollection matches = Regex.Matches(html, pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);
            if (matches.Count != 0)
                foreach(Match match in matches)
                    GroupCollection groups = match.Groups;
                return tempVehicleStore;
            } else
                player.SendChatMessage("Error matching regex to vehicles..");
            return null;
        public void WriteToFile(string path, string content)
                File.WriteAllText(path, content);
            catch (IOException e)
                NAPI.Util.ConsoleOutput("Error: ", e.Message);
                NAPI.Util.ConsoleOutput("Stack: ", e.StackTrace);
    public class VehicleData
        public string VehicleName { get; set; }
        public float MaxSpeed { get; set; }
        public float MaxBraking { get; set; }
        public float MaxTraction { get; set; }
        public float MaxAcceleration { get; set; }
        public int MaxNumberOfPassengers { get; set; }
        public int MaxOccupants { get; set; }
        public int VehicleClass { get; set; }


Command i created with this class:

        public async void FetchVehicleDataAsync(Client player)
            List<VehicleData> vehData = new List<VehicleData>();
            GetVehicleInfo vehicle = new GetVehicleInfo();

            List<string> vehiclenames = await vehicle.ReturnVehicleNamesAsync(player);

            player.SendChatMessage("Fetch complete, getting related vehicle info..");
            foreach(string v in vehiclenames)
                uint id = NAPI.Util.GetHashKey(v);

                vehData.Add(new VehicleData()
                    VehicleName = NAPI.Vehicle.GetVehicleDisplayName((VehicleHash)id),
                    MaxSpeed = NAPI.Vehicle.GetVehicleMaxSpeed((VehicleHash)id),
                    MaxBraking = NAPI.Vehicle.GetVehicleMaxBraking((VehicleHash)id),
                    MaxTraction = NAPI.Vehicle.GetVehicleMaxTraction((VehicleHash)id),
                    MaxAcceleration = NAPI.Vehicle.GetVehicleMaxAcceleration((VehicleHash)id),
                    MaxNumberOfPassengers = NAPI.Vehicle.GetVehicleMaxPassengers((VehicleHash)id),
                    MaxOccupants = NAPI.Vehicle.GetVehicleMaxOccupants((VehicleHash)id),
                    VehicleClass = NAPI.Vehicle.GetVehicleClass((VehicleHash)id)
            vehicle.WriteToFile(@"output/vehicleData.json", NAPI.Util.ToJson(vehData));
            player.SendChatMessage("vehicleData.json exported, check output folder in your server directory");


Note: I did use the GTANetwork's deprecated code as a reference when creating this so partial credits to them :)


Kind Regards,


  • Like 1

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.