[Include] Dynamic Vehicle System [MySQL | User Friendly | 0.3d Compatible]
#1

Dynamic Vehicle System - by Tee


- Introduction

Hey, it's me again, with my first include. Well today I'm releasing a Dynamic Vehicle System which would sort of eliminate the use of the AddStaticVehicle and AddStaticVehicleEx functions used to add vehicles to a gamemode. With this users can add vehicles to their MySQL database with one command, and have total control over the vehicle (mods, plate and color). I decided to make this filterscript while updating my server because I wanted to change the vehicles and I didn't want to have to go in each one and use the /save command then add it to my gamemode.

- Question?

Q: What will happen to vehicles I already have?
A: There is a function located at the bottom of the script (d_AddVehiclesToDatabase())
Copy it to your gamemode, uncomment it, and add d_AddVehiclesToDatabase(); under OnGameModeInit then load your script
NOTE: RUN IT ONLY 1 time! *

- Features

- Add vehicle to database.
- Remove vehicle from database.
- Change vehicle color.
- Change vehicle plate.
- Add modifications to vehicle.
- Features listed above are all done in-game.

- Installation & Equipment

For this to your you must have a server that is MySQL and 0.3d compatible.
All other includes are provided in the file.

To install:

1. Copy the file from "pawno/include" located in this file, to your "pawno/include" folder (on your computer)
2. Copy the files from "include" located in this file, to your "include" folder (this folder is located in the same directory as the server.cfg)
3. Go to your database and import the sql table located in this file ("dvehicles.sql")
4. Go to your server, log into RCON and type /dvcmds.

- Commands
  • /setdveh - Spawns and saves the vehicle in the database (you'll need to be in a vehicle to use this)
  • /setdcol - Changes the vehicle's color.
  • /setdplate - Changes the vehicle's numberplate.
  • /deletedveh - Deletes the vehicle.
  • /dmodstart - Start the modification process (optional). Whenever you type this, you can go to a tune shop and add the modifications to the vehicle
  • /dmodcomplete - Stops the modification process.
  • /removedmods
- Picture

I couldn't bother to make a video so here's a picture:



- Downloads

SA-MP Color Picker - GTAGarage
Version 1.0 (0.3d) - solidfiles
Version 1.5 (0.3d) - solidfiles (Mod reset bug fixed in this version, thanks to Kar for discovering it)

- Credits

Credits:
SA-MP Team
ZCMD - Zeex
MySQL plugin - Blue-G
GetVehicleColor - Credits to whoever made this.
sscanf 2.0 - ******
zone - Credits to whoever made this (I compiled it into an include).
dveh - Tee
SA-MP Color picker - UZI-I (I used it to pick the colors, you can download it here)

*If you run the "d_AddVehiclesToDatabase" function more than one time, then you'll have vehicle duplicates, so when you've ran it the first time, just remove it from your script.
Reply
#2

Nice, I might use it.
Reply
#3

Nice work
Reply
#4

Amhaaaizing. And when I say something with the " h " I say it from the heart, mate.
Reply
#5

Pretty nice. Buy why people uses the same color that i used on my FS? I don't understand. I already saw that on few releases.

Edit: " GetVehicleColor " i think was made by Ryder.
Reply
#6

Thanks guys!

Quote:
Originally Posted by TheArcher
View Post
Pretty nice. Buy why people uses the same color that i used on my FS? I don't understand. I already saw that on few releases.
What colors? If it's the colors in include, well I used the color picker to pick green and yellow, then lighten them.
Reply
#7

Nice job Tee. +1 Rep.

Quote:
Originally Posted by TheArcher
View Post
Pretty nice. Buy why people uses the same color that i used on my FS? I don't understand. I already saw that on few releases.
Ummm you do realize that people dont use it just because you do. They use the color they think suites their server and stuff more. It's not like they're "stealing your colors"
Reply
#8

Here are a few things you might want to redesign:
pawn Code:
for(new i=1; i<MAX_D_VEH; i++)
{
    format(dquery,sizeof(dquery),"SELECT * FROM dvehicles WHERE `ID` = %d LIMIT 1",i);
        mysql_query(dquery);
    //.........
}
If you take a look at that, there are a couple of issues with it. The first one being that you are selecting the whole row of information (*) when you could be singularly selecting the ID. Secondly, if you have a few hundred cars, it's going to go through hundreds of queries and store thousands of fields of information before finding a free slot. This won't even be needed if you format your load vehicles correctly and setting ID to auto increment. All you would need to do is save the auto increment ID for later if you are going to delete vehicles.

pawn Code:
for(new i=1; i<MAX_D_VEH; i++)
{
    format(dquery,55,"SELECT * FROM dvehicles WHERE `ID` = %d LIMIT 1",i);
    mysql_query(dquery);
        //.......
}
That's the same sort of thing that I was talking about above. You only need a single query to get all of the information and process it. Here is an example:

pawn Code:
mysql_query("SELECT * FROM dvehicles");
mysql_store_result();
while(mysql_retrieve_row())
{
    mysql_fetch_row_format(drow, "|")
    //.......
}
mysql_free_result();
You also seem to have mysql_debug set to enable on your SaveMods function, then you turn it off after. This isn't really needed for the final script if it's working fine, it may be best just turning it off.

Hope that this helps .
Reply
#9

Very nice!! tested it on my GM I'm making from scratch, well done man.
Reply
#10

Quote:
Originally Posted by [HiC]TheKiller
View Post
Here are a few things you might want to redesign:
pawn Code:
for(new i=1; i<MAX_D_VEH; i++)
{
    format(dquery,sizeof(dquery),"SELECT * FROM dvehicles WHERE `ID` = %d LIMIT 1",i);
        mysql_query(dquery);
    //.........
}
If you take a look at that, there are a couple of issues with it. The first one being that you are selecting the whole row of information (*) when you could be singularly selecting the ID. Secondly, if you have a few hundred cars, it's going to go through hundreds of queries and store thousands of fields of information before finding a free slot. This won't even be needed if you format your load vehicles correctly and setting ID to auto increment. All you would need to do is save the auto increment ID for later if you are going to delete vehicles.

pawn Code:
for(new i=1; i<MAX_D_VEH; i++)
{
    format(dquery,55,"SELECT * FROM dvehicles WHERE `ID` = %d LIMIT 1",i);
    mysql_query(dquery);
        //.......
}
That's the same sort of thing that I was talking about above. You only need a single query to get all of the information and process it. Here is an example:

pawn Code:
mysql_query("SELECT * FROM dvehicles");
mysql_store_result();
while(mysql_retrieve_row())
{
    mysql_fetch_row_format(drow, "|")
    //.......
}
mysql_free_result();
You also seem to have mysql_debug set to enable on your SaveMods function, then you turn it off after. This isn't really needed for the final script if it's working fine, it may be best just turning it off.

Hope that this helps .
Thanks for that, I totally forgot the mysql_debug.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)