| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- #include <YSI_Coding\y_hooks>
- forward OnVehicleCreated(sqlid);
- forward OnVehicleDeleted(sqlid);
- forward OnServerVehicleSpawned(vehicleid);
- forward OnServerVehicleDespawned(vehicleid);
- #define MAX_VEHICLE_PLATE 33
- static VehicleSQLID[MAX_VEHICLES];
- static VehicleOwnerSQLID[MAX_VEHICLES];
- static VehiclePrice[MAX_VEHICLES];
- static VehicleModel[MAX_VEHICLES];
- static VehiclePlate[MAX_VEHICLES][MAX_VEHICLE_PLATE];
- static VehicleColOne[MAX_VEHICLES];
- static VehicleColTwo[MAX_VEHICLES];
- static Float:VehiclePosX[MAX_VEHICLES];
- static Float:VehiclePosY[MAX_VEHICLES];
- static Float:VehiclePosZ[MAX_VEHICLES];
- static Float:VehiclePosA[MAX_VEHICLES];
- static VehicleWorld[MAX_VEHICLES];
- static VehicleInterior[MAX_VEHICLES];
- hook OnMySQLPreClose()
- {
- foreach(new i : Vehicle)
- {
- if(VehicleSQLID[i] != 0)
- {
- new world = GetVehicleVirtualWorld(i);
- new Float:x, Float:y, Float:z, Float:a;
- GetVehiclePos(i, x, y, z);
- GetVehicleZAngle(i, a);
- new query[184];
- mysql_format(MySQL_GetHandle(), query, sizeof(query), "UPDATE vehicles SET pos_x = %f, pos_y = %f, pos_z = %f, pos_a = %f, world = %d WHERE id = %d", x, y, z, a, world, VehicleSQLID[i]);
- mysql_tquery(MySQL_GetHandle(), query);
- }
- }
- }
- CMD:createvehicle(playerid, params[])
- {
- new modelid, colOne, colTwo;
- if(sscanf(params, "iii", modelid, colOne, colTwo)) return SendSyntaxMessage(playerid, "/createvehicle (modelid) (color one) (color two)");
- new Float:x, Float:y, Float:z, Float:a;
- GetPlayerPos(playerid, x, y, z);
- GetPlayerFacingAngle(playerid, a);
- new world = GetPlayerVirtualWorld(playerid);
- new interior = GetPlayerInterior(playerid);
- inline const OnVehicleInserted()
- {
- new sqlid = cache_insert_id();
- printf("Vehicle ID %d has been created.", sqlid);
- SendAdminWarningF(playerid, "You have created a vehicle. (SQL ID %d)", sqlid);
- CallRemoteFunction("OnVehicleCreated", "i", sqlid);
- }
- MySQL_TQueryInline(MySQL_GetHandle(), using inline OnVehicleInserted, "INSERT INTO vehicles (owner_id, price, model, plate, col_one, col_two, pos_x, pos_y, pos_z, pos_a, world, interior) VALUES (0, 0, %d, 'null', %d, %d, %f, %f, %f, %f, %d, %d)", modelid, colOne, colTwo, x, y, z, a, world, interior);
- return 1;
- }
- CMD:deletevehicle(playerid, params[])
- {
- new sqlid;
- if(sscanf(params, "i", sqlid)) return SendSyntaxMessage(playerid, "/deletevehicle (database ID)");
- inline OnVehicleRemoved()
- {
- if(cache_affected_rows())
- {
- CallRemoteFunction("OnVehicleDeleted", "i", sqlid);
- foreach(new i : Vehicle)
- {
- if(VehicleSQLID[i] == sqlid)
- {
- CallRemoteFunction("OnServerVehicleDespawned", "i", i);
- VehicleSQLID[i] = 0;
- VehicleOwnerSQLID[i] = 0;
- DestroyVehicle(i);
- break;
- }
- }
- printf("Vehicle ID %d has been deleted.", sqlid);
- SendAdminWarningF(playerid, "You have deleted a vehicle. (SQL ID %d)", sqlid);
- }
- else SendAdminWarningF(playerid, "That vehicle (SQL ID %d) could not be found in the database.", sqlid);
- }
- MySQL_TQueryInline(MySQL_GetHandle(), using inline OnVehicleRemoved, "DELETE FROM vehicles WHERE id = %d", sqlid);
- return 1;
- }
- CMD:spawnvehicle(playerid, params[])
- {
- new sqlid;
- if(sscanf(params, "i", sqlid)) return SendSyntaxMessage(playerid, "/spawnvehicle (database ID)");
- foreach(new i : Vehicle)
- {
- if(VehicleSQLID[i] == sqlid) return SendErrorMessage(playerid, "That vehicle is already spawned.");
- }
- inline const OnVehicleFound()
- {
- if(cache_num_rows())
- {
- new id;
- new ownerid;
- new model;
- new price;
- new plate[MAX_VEHICLE_PLATE];
- new colOne, colTwo;
- new world, interior;
- new Float:x, Float:y, Float:z, Float:a;
- cache_get_value_name_int(0, "id", id);
- cache_get_value_name_int(0, "owner_id", ownerid);
- cache_get_value_name_int(0, "model", model);
- cache_get_value_name_int(0, "price", price);
- cache_get_value_name(0, "plate", plate);
- cache_get_value_name_int(0, "col_one", colOne);
- cache_get_value_name_int(0, "col_two", colTwo);
- cache_get_value_name_float(0, "pos_x", x);
- cache_get_value_name_float(0, "pos_y", y);
- cache_get_value_name_float(0, "pos_z", z);
- cache_get_value_name_float(0, "pos_a", a);
- cache_get_value_name_int(0, "world", world);
- cache_get_value_name_int(0, "interior", interior);
- new sessionid = CreateVehicle(model, x, y, z, a, colOne, colTwo, -1);
- SetVehicleVirtualWorld(sessionid, world);
- LinkVehicleToInterior(sessionid, interior);
- SetVehicleNumberPlate(sessionid, plate);
- format(VehiclePlate[sessionid], MAX_VEHICLE_PLATE, plate);
- VehicleSQLID[sessionid] = sqlid;
- VehicleOwnerSQLID[sessionid] = ownerid;
- VehicleModel[sessionid] = model;
- VehiclePrice[sessionid] = price;
- VehicleColOne[sessionid] = colOne;
- VehicleColTwo[sessionid] = colTwo;
- VehiclePosX[sessionid] = x;
- VehiclePosY[sessionid] = y;
- VehiclePosZ[sessionid] = z;
- VehiclePosA[sessionid] = a;
- VehicleWorld[sessionid] = world;
- VehicleInterior[sessionid] = interior;
- CallRemoteFunction("OnServerVehicleSpawned", "i", sessionid);
- SendAdminWarningF(playerid, "You spawned vehicle ID %d, SQL ID %d.", sessionid, sqlid);
- }
- else SendAdminWarningF(playerid, "That vehicle (SQL ID %d) could not be found in the database.", sqlid);
- }
- MySQL_TQueryInline(MySQL_GetHandle(), using inline OnVehicleFound, "SELECT * FROM vehicles WHERE id = %d", sqlid);
- return 1;
- }
- CMD:despawnvehicle(playerid, params[])
- {
- new sessionid;
- if(sscanf(params, "i", sessionid)) return SendSyntaxMessage(playerid, "/despawnveh (vehicleid)");
- if(!IsValidVehicle(sessionid)) return SendErrorMessage(playerid, "That vehicle is not spawned.");
- new world = GetVehicleVirtualWorld(sessionid);
- new Float:x, Float:y, Float:z, Float:a;
- GetVehiclePos(sessionid, x, y, z);
- GetVehicleZAngle(sessionid, a);
- new query[184];
- mysql_format(MySQL_GetHandle(), query, sizeof(query), "UPDATE vehicles SET pos_x = %f, pos_y = %f, pos_z = %f, pos_a = %f, world = %d WHERE id = %d", x, y, z, a, world, VehicleSQLID[sessionid]);
- mysql_tquery(MySQL_GetHandle(), query);
- VehicleSQLID[sessionid] = 0;
- VehicleOwnerSQLID[sessionid] = 0;
- DestroyVehicle(sessionid);
- SendAdminWarningF(playerid, "You despawned vehicle ID %d, SQL ID %d.", sessionid, VehicleSQLID[sessionid]);
- return 1;
- }
- stock bool:IsValidServerVehicle(vehicleid)
- {
- if(IsValidVehicle(vehicleid) && VehicleSQLID[vehicleid] != 0)
- {
- return true;
- }
- return false;
- }
- stock Vehicle_GetSQLID(vehicleid)
- {
- return VehicleSQLID[vehicleid];
- }
- stock Vehicle_SetOwnerSQLID(vehicleid, ownerid)
- {
- VehicleOwnerSQLID[vehicleid] = ownerid;
- new query[84];
- mysql_format(MySQL_GetHandle(), query, sizeof(query), "UPDATE vehicles SET owner_id = %d WHERE id = %d", ownerid, VehicleSQLID[vehicleid]);
- mysql_tquery(MySQL_GetHandle(), query);
- }
- stock Vehicle_GetOwnerSQLID(vehicleid)
- {
- return VehicleOwnerSQLID[vehicleid];
- }
- stock Vehicle_SetPrice(vehicleid, price)
- {
- VehiclePrice[vehicleid] = price;
- new query[84];
- mysql_format(MySQL_GetHandle(), query, sizeof(query), "UPDATE vehicles SET price = %d WHERE id = %d", price, VehicleSQLID[vehicleid]);
- mysql_tquery(MySQL_GetHandle(), query);
- }
- stock Vehicle_GetPrice(vehicleid)
- {
- return VehiclePrice[vehicleid];
- }
- stock Vehicle_SetColors(vehicleid, colOne, colTwo)
- {
- VehicleColOne[vehicleid] = colOne;
- VehicleColTwo[vehicleid] = colTwo;
- new query[84];
- mysql_format(MySQL_GetHandle(), query, sizeof(query), "UPDATE vehicles SET col_one = %d, col_two = %d WHERE id = %d", colOne, colTwo, VehicleSQLID[vehicleid]);
- mysql_tquery(MySQL_GetHandle(), query);
- }
- stock Vehicle_GetColors(vehicleid, &colOne, &colTwo)
- {
- colOne = VehicleColOne[vehicleid];
- colTwo = VehicleColTwo[vehicleid];
- }
- stock Vehicle_GetPosition(vehicleid, &Float:x, &Float:y, &Float:z, &Float:a)
- {
- x = VehiclePosX[vehicleid];
- y = VehiclePosY[vehicleid];
- z = VehiclePosZ[vehicleid];
- a = VehiclePosA[vehicleid];
- }
- stock Vehicle_GetWorld(vehicleid)
- {
- return VehicleWorld[vehicleid];
- }
- stock Vehicle_GetInterior(vehicleid)
- {
- return VehicleInterior[vehicleid];
- }
|