Vehicle spawning with MySQL
#1

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.
Reply
#2

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

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

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

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

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.
Reply
#7

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.
Reply
#8

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
Reply
#9

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?
Reply
#10

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!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)