Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // yiin
- #include <a_samp>
- /* pawno.exe
- native ORM:GetVehicleORM(vehicleid);
- native GetVehicleUID(vehicleid);
- native AddVehicle(model, Float:x, Float:y, Float:z, Float:a, color1 = -1, color2 = -1);
- native LoadVehicle(sqlid = -1, row = 0, applydata = true);
- native SaveVehicle(vehicleid, update_pos = true, remove = false);
- native DeleteVehicle(vehicleid);
- */
- // functions
- forward ORM:CreateVehicleORM(vehicleid);
- forward ORM:GetVehicleORM(vehicleid);
- // callbacks
- forward OnVehicleInsert(vehicleid);
- forward OnCreateVehicleORM(ORM:ormid, vehicleid);
- #define format_query( format(query, sizeof(query),
- static query[500];
- static
- database,
- ORM:vehicle_ORM[MAX_VEHICLES],
- vehicle_ID[MAX_VEHICLES],
- vehicle_Model[MAX_VEHICLES],
- vehicle_Color1[MAX_VEHICLES],
- vehicle_Color2[MAX_VEHICLES],
- Float:vehicle_Health[MAX_VEHICLES],
- Float:vehicle_PosX[MAX_VEHICLES],
- Float:vehicle_PosY[MAX_VEHICLES],
- Float:vehicle_PosZ[MAX_VEHICLES],
- Float:vehicle_PosA[MAX_VEHICLES]
- ;
- stock vehicle_ChangeVehicleColor(vehicleid, color1, color2) {
- vehicle_Color1[vehicleid] = color1;
- vehicle_Color2[vehicleid] = color2;
- return ChangeVehicleColor(vehicleid, color1, color2);
- }
- #if defined _ALS_ChangeVehicleColor
- #undef ChangeVehicleColor
- #else
- #define _ALS_ChangeVehicleColor
- #endif
- #define ChangeVehicleColor vehicle_ChangeVehicleColor
- stock ORM:GetVehicleORM(vehicleid) {
- return vehicle_ORM[vehicleid];
- }
- stock GetVehicleUID(vehicleid) {
- return vehicle_ID[vehicleid];
- }
- stock static ORM:CreateVehicleORM(vehicleid) {
- new ORM:ormid = vehicle_ORM[vehicleid] = orm_create("vehicles");
- orm_addvar_int(ormid, vehicle_ID[vehicleid], "uid");
- orm_setkey(ormid, "uid");
- orm_addvar_int(ormid, vehicle_Model[vehicleid], "model");
- orm_addvar_int(ormid, vehicle_Color1[vehicleid], "color1");
- orm_addvar_int(ormid, vehicle_Color2[vehicleid], "color2");
- orm_addvar_float(ormid, vehicle_PosX[vehicleid], "x");
- orm_addvar_float(ormid, vehicle_PosY[vehicleid], "y");
- orm_addvar_float(ormid, vehicle_PosZ[vehicleid], "z");
- orm_addvar_float(ormid, vehicle_PosA[vehicleid], "a");
- orm_addvar_float(ormid, vehicle_Health[vehicleid], "health");
- CallLocalFunction("OnCreateVehicleORM", "ii", _:ormid, vehicleid);
- return ormid;
- }
- stock static ApplyVehicleData(vehicleid, setpos = true) {
- if(setpos) {
- SetVehiclePos(vehicleid,
- vehicle_PosX[vehicleid],
- vehicle_PosY[vehicleid],
- vehicle_PosZ[vehicleid]);
- SetVehicleZAngle(vehicleid,
- vehicle_PosA[vehicleid]);
- }
- SetVehicleHealth(vehicleid, vehicle_Health[vehicleid]);
- ChangeVehicleColor(vehicleid, vehicle_Color1[vehicleid], vehicle_Color2[vehicleid]);
- }
- stock AddVehicle(model, Float:x, Float:y, Float:z, Float:a, color1 = -1, color2 = -1) {
- new vehicleid = CreateVehicle(model, x, y, z, a, color1, color2, -1);
- if(vehicleid == INVALID_VEHICLE_ID) {
- return INVALID_VEHICLE_ID;
- }
- new ORM:ormid = CreateVehicleORM(vehicleid);
- vehicle_Model[vehicleid] = model;
- vehicle_Color1[vehicleid] = color1;
- vehicle_Color2[vehicleid] = color2;
- vehicle_PosX[vehicleid] = x;
- vehicle_PosY[vehicleid] = y;
- vehicle_PosZ[vehicleid] = z;
- vehicle_PosA[vehicleid] = a;
- ApplyVehicleData(vehicleid, .setpos = false);
- orm_insert(ormid, "OnVehicleInsert", "i", vehicleid);
- return vehicleid;
- }
- stock LoadVehicle(sqlid = -1, row = 0, applydata = true) {
- new Cache:cache;
- if(sqlid != -1) {
- format_query("SELECT * FROM vehicles WHERE uid = %i", sqlid);
- cache = mysql_query(database, query);
- }
- new model = cache_get_field_content_int(row, "model");
- new vehicleid = CreateVehicle(model, 0, 0, 0, 0, 0, 0, 0);
- new ORM:ormid = CreateVehicleORM(vehicleid);
- orm_apply_cache(ormid, row);
- if(applydata) {
- ApplyVehicleData(vehicleid);
- }
- if(sqlid != -1) {
- cache_delete(cache);
- }
- return vehicleid;
- }
- stock SaveVehicle(vehicleid, update_pos = true, remove = false) {
- if(vehicle_ID[vehicleid] != 0) {
- if(update_pos) {
- GetVehiclePos(vehicleid,
- vehicle_PosX[vehicleid],
- vehicle_PosY[vehicleid],
- vehicle_PosZ[vehicleid]);
- GetVehicleZAngle(vehicleid,
- vehicle_PosA[vehicleid]);
- }
- orm_update(vehicle_ORM[vehicleid]);
- if(remove) {
- orm_destroy(vehicle_ORM[vehicleid]);
- DestroyVehicle(vehicleid);
- }
- }
- }
- stock DeleteVehicle(vehicleid) {
- if(vehicle_ID[vehicleid] != 0) {
- orm_delete(vehicle_ORM[vehicleid]);
- orm_destroy(vehicle_ORM[vehicleid]);
- DestroyVehicle(vehicleid);
- }
- }
- public OnVehicleRespray(playerid, vehicleid, color1, color2)
- {
- vehicle_Color1[vehicleid] = color1;
- vehicle_Color2[vehicleid] = color2;
- #if defined vehicles_OnVehicleRespray
- vehicles_OnVehicleRespray(playerid, vehicleid, color1, color2);
- #endif
- return 1;
- }
- #if defined _ALS_OnVehicleRespray
- #undef OnVehicleRespray
- #else
- #define _ALS_OnVehicleRespray
- #endif
- #define OnVehicleRespray vehicles_OnVehicleRespray
- #if defined vehicles_OnVehicleRespray
- forward vehicles_OnVehicleRespray(playerid, vehicleid, color1, color2);
- #endif
- vehicles_mysql_connect(host[], user[], database[], password[]) {
- return (database = mysql_connect(host, user, database, password));
- }
- #if defined _ALS_mysql_connect
- #undef mysql_connect
- #else
- #define _ALS_mysql_connect
- #endif
- #define mysql_connect vehicles_mysql_connect
Advertisement
Add Comment
Please, Sign In to add comment