15.06.2015, 14:31
(
Last edited by theYiin; 15/06/2015 at 06:09 PM.
)
Hey there,
this include helps to save and load information of vehicles without much effort.
Available functions:
Callbacks:
Example:
Questions or suggesions?
this include helps to save and load information of vehicles without much effort.
Available functions:
Code:
// Get unique vehicle id (sql id) stock GetVehicleUID(vehicleid); // Create a vehicle. This function will create an entry in database for vehicle too. stock AddVehicle(model, Float:x, Float:y, Float:z, Float:a, color1 = -1, color2 = -1); // Load vehicle from database by vehicles UID (sqlid) or from active cache (use row parameter for that). Set applydata to false, if you dont want to apply loaded vehicle information (position, color, health) stock LoadVehicle(sqlid = -1, row = 0, applydata = true); // Save vehicle. Set update_pos to false if you don't want to save current vehicle position, and set remove to true, if you want to destroy vehicle from world. stock SaveVehicle(vehicleid, update_pos = true, remove = false); // Deletes vehicle entirely, both from game and from database. Cannot be undone. stock DeleteVehicle(vehicleid);
Code:
// Gets called when new vehicle is inserted into database forward OnVehicleInsert(vehicleid); // In this callback you can specify which information you want to be automatically loaded and saved forward OnCreateVehicleORM(ORM:ormid, vehicleid);
PHP Code:
#include <a_samp>
#include <a_mysql>
#include <vehicles>
// you vehicle information enum
enum vehicle_e_DATA {
owner[MAX_PLAYER_NAME], // name, because I wanted to make example using string variable
Float:fuel,
Float:run,
price
};
new vehicleDB[MAX_VEHICLES][vehicle_e_DATA];
/* ... other code ... */
public OnVehicleInsert(vehicleid) {
print("Vehicle (id: %i, sql id: %i) was successfully inserted into database!",
vehicleid, GetVehicleUID(vehicleid));
}
public OnCreateVehicleORM(ORM:ormid, vehicleid) {
// information you want to be automatically saved and loaded
// don't forget to create additional fields in `vehicles` table
orm_addvar_string(ormid, vehicleDB[vehicleid][owner], "owner");
orm_addvar_float(ormid, vehicleDB[vehicleid][fuel], "fuel");
orm_addvar_float(ormid, vehicleDB[vehicleid][run], "run");
orm_addvar_int(ormid, vehicleDB[vehicleid][price], "price");
}
- For this include to work, you will need this MySQL plugin: https://sampforum.blast.hk/showthread.php?tid=56564
- SQL file to create basic `vehicles` table structure: http://pastebin.com/3gtLVTMD
- vehicles.inc: http://pastebin.com/hnw1GFL7
- Model
- Position (including angle)
- Color
- Health
Questions or suggesions?
grammar is bit fked up, feel free to correct me if needed!