SA-MP Forums Archive
Vehicle spawning with MySQL - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Other (https://sampforum.blast.hk/forumdisplay.php?fid=7)
+--- Forum: Everything and Nothing (https://sampforum.blast.hk/forumdisplay.php?fid=23)
+--- Thread: Vehicle spawning with MySQL (/showthread.php?tid=608391)



Vehicle spawning with MySQL - dicknyson - 31.05.2016

I've created a vehicle spawning command. You type /v with no parameters, and a dialog opens that shows the top 10 vehicles that are spawned the most:
Or, you can type /v with a vehicle model ID or (part of) a vehicle name and it will spawn it. Fairly simple like most vehicle spawning systems, apart from that it just uses MySQL.

I have a table called "vehicles" with 4 fields: model_id, name, prefix, and spawns. It looks like this:

and so on for each vehicle.

The prefix field obviously makes correct grammar a lot easier in the client messages. I usually see "You have spawned a Infernus" and it drives me crazy.

Also, the amounts of spawns are automatically incremented when a vehicle is spawned so it shows accurate data about which vehicles players are driving the most and makes it easier for players to find their favourite vehicles.

It looks neater not having that huge array of vehicle names in my gamemode too.

What do you guys think about the idea of systems relying almost entirely on a database? I'm not sure (haven't tested) if it makes it slower or not, but I don't think it's noticeable if it does.


Re: Vehicle spawning with MySQL - Luis- - 31.05.2016

I really like that. Obviously the Infernus would be the the most popular! I do like to see this type of information.


Re: Vehicle spawning with MySQL - iKevin - 31.05.2016

I like the idea and everything, how did you make the click counts if I can ask?


Re: Vehicle spawning with MySQL - Luis- - 31.05.2016

I'm presuming some sort of variable that increments each time a vehicle is spawned. Or something similar.


Re: Vehicle spawning with MySQL - Ritzy2K - 31.05.2016

This is a good idea! I believe Hydra will soon gain top rank


Re: Vehicle spawning with MySQL - dicknyson - 31.05.2016

Quote:
Originally Posted by KevinExec
Посмотреть сообщение
I like the idea and everything, how did you make the click counts if I can ask?
Very simply. I have a custom function (CreatePlayerVehicle(playerid, modelid);) to spawn vehicles for players. Included under this function is just a simple MySQL query:
Код:
"UPDATE `vehicles` SET spawns=spawns+1 WHERE model_id = [model ID of the vehicle the player spawned]"
Then, when the top vehicles dialog is loaded, it just sorts the vehicles by "spawns" descending and limits the results to 10, then it's just a case of formatting it for the dialog.


Re: Vehicle spawning with MySQL - Lordzy - 31.05.2016

I don't find how having vehicle names as an array could affect the neatness, it depends on the coder though. Instead of having prefix column, I'd use bitflags which could save memory and provide better performance. 0 for a and 1 for an.


Re: Vehicle spawning with MySQL - dicknyson - 31.05.2016

Quote:
Originally Posted by Lordzy
Посмотреть сообщение
I don't find how having vehicle names as an array could affect the neatness, it depends on the coder though. Instead of having prefix column, I'd use bitflags which could save memory and provide better performance. 0 for a and 1 for an.
Good thinking. Cheers for the idea


Re: Vehicle spawning with MySQL - Boar - 04.06.2016

Quote:
Originally Posted by dicknyson
Посмотреть сообщение
Very simply. I have a custom function (CreatePlayerVehicle(playerid, modelid);) to spawn vehicles for players. Included under this function is just a simple MySQL query:
Код:
"UPDATE `vehicles` SET spawns=spawns+1 WHERE model_id = [model ID of the vehicle the player spawned]"
Then, when the top vehicles dialog is loaded, it just sorts the vehicles by "spawns" descending and limits the results to 10, then it's just a case of formatting it for the dialog.
Why would you run a query every time a vehicle is spawned/created instead of running one query when the server starts and another one when it stops, using internal variables?


Re: Vehicle spawning with MySQL - SickAttack - 04.06.2016

Quote:
Originally Posted by Boar
Посмотреть сообщение
Why would you run a query every time a vehicle is spawned/created instead of running one query when the server starts and another one when it stops, using internal variables?
That's a bad idea (it won't save if the server crashes), a timer with checks for any changes is more suitable (it won't save if the server crashes either; however, you don't lose all the data like in your idea).

OT: It's a really nice idea, I like it! Good job!