19.07.2018, 06:04
Hey guys. I have a vehicle system and I've rebuilt it so that in the database it isn't just carid that is auto incremented and so when deleting and creating vehicles it doesn't make a mess.
However now I've come into an issue.
My issue, is in my database it won't the vehicle to load in order of the carid's in the database. For example I've made a check statement for loading the vehicles in the output and I get.
It seems to be grouping the vehicle model somewhat backwards However what it looks like in the DB is.
Here is my load code.
My Car save, also I haven't used the car save function I've inputted these in through the database SQL option.
Any help would be much appreciated
However now I've come into an issue.
My issue, is in my database it won't the vehicle to load in order of the carid's in the database. For example I've made a check statement for loading the vehicles in the output and I get.
Код:
Vehicle ID: 0 Vehicle Model: 523 Vehicle ID: 1 Vehicle Model: 523 Vehicle ID: 2 Vehicle Model: 596 Vehicle ID: 3 Vehicle Model: 596 Vehicle ID: 4 Vehicle Model: 596 Vehicle ID: 5 Vehicle Model: 426 Vehicle ID: 6 Vehicle Model: 426 Vehicle ID: 7 Vehicle Model: 560 Vehicle ID: 8 Vehicle Model: 560 Vehicle ID: 9 Vehicle Model: 541 Vehicle ID: 10 Vehicle Model: 544
Код:
Vehicle ID: 0 Vehicle Model: 544 Vehicle ID: 1 Vehicle Model: 541 Vehicle ID: 2 Vehicle Model: 560 Vehicle ID: 3 Vehicle Model: 560 Vehicle ID: 4 Vehicle Model: 426 Vehicle ID: 5 Vehicle Model: 426 Vehicle ID: 6 Vehicle Model: 523 Vehicle ID: 7 Vehicle Model: 523 Vehicle ID: 8 Vehicle Model: 596 Vehicle ID: 9 Vehicle Model: 596 Vehicle ID: 10 Vehicle Model: 596
Код:
public Car_Load() { static rows, fields, str[128]; cache_get_row_count(rows); cache_get_field_count(fields); for (new i = 0; i < rows; i ++) if (i < MAX_DYNAMIC_CARS) { CarData[i][carExists] = true; cache_get_value_name_int(i, "carID",CarData[i][carID]); cache_get_value_name_int(i, "carModel",CarData[i][carModel]); cache_get_value_name_int(i, "carOwner",CarData[i][carOwner]); cache_get_value_name_float(i, "carPosX",CarData[i][carPos][0]); cache_get_value_name_float(i, "carPosY",CarData[i][carPos][1]); cache_get_value_name_float(i, "carPosZ",CarData[i][carPos][2]); cache_get_value_name_float(i, "carPosR",CarData[i][carPos][3]); cache_get_value_name_int(i, "carColor1",CarData[i][carColor1]); cache_get_value_name_int(i, "carColor2",CarData[i][carColor2]); cache_get_value_name_int(i, "carPaintjob",CarData[i][carPaintjob]); cache_get_value_name_int(i, "carLocked",CarData[i][carLocked]); cache_get_value_name_int(i, "carImpounded",CarData[i][carImpounded]); cache_get_value_name_int(i, "carImpoundPrice",CarData[i][carImpoundPrice]); cache_get_value_name_int(i, "carFaction",CarData[i][carFaction]); cache_get_value_name_int(i, "carSiren",CarData[i][carSiren]); printf("Vehicle ID: %d Vehicle Model: %d", Iter_Count(Vehs), CarData[i][carModel]); for (new j = 0; j < 14; j ++) { if (j < 5) { format(str, sizeof(str), "carWeapon%d", j + 1); cache_get_value_name_int(i, str, CarData[i][carWeapons][j]); format(str, sizeof(str), "carAmmo%d", j + 1); cache_get_value_name_int(i, str,CarData[i][carAmmo][j]); } format(str, sizeof(str), "carMod%d", j + 1); cache_get_value_name_int(i, str,CarData[i][carMods][j]); } Iter_Add(Vehs, i); Car_Spawn(i); } for (new j = 0; j < MAX_DYNAMIC_CARS; j ++) if (CarData[j][carExists]) { format(str, sizeof(str), "SELECT * FROM `carstorage` WHERE `ID` = '%d'", CarData[j][carID]); mysql_tquery(g_iHandle, str, "OnLoadCarStorage", "d", j); } printf(" [Vehicle System] Loaded %d Vehicles.", Iter_Count(Vehs)); return 1; }
Код:
Car_Save(carid) { static query[900]; if(!Iter_Contains(Vehs, carid)) return 0; if (CarData[carid][carVehicle] != INVALID_VEHICLE_ID) { for (new i = 0; i < 14; i ++) { CarData[carid][carMods][i] = GetVehicleComponentInSlot(CarData[carid][carVehicle], i); } } format(query, sizeof(query), "UPDATE `Vehicles` SET `carModel` = '%d', `carOwner` = '%d', `carPosX` = '%.4f', `carPosY` = '%.4f', `carPosZ` = '%.4f', `carPosR` = '%.4f', `carColor1` = '%d', `carColor2` = '%d', `carPaintjob` = '%d', `carLocked` = '%d'", CarData[carid][carModel], CarData[carid][carOwner], CarData[carid][carPos][0], CarData[carid][carPos][1], CarData[carid][carPos][2], CarData[carid][carPos][3], CarData[carid][carColor1], CarData[carid][carColor2], CarData[carid][carPaintjob], CarData[carid][carLocked] ); format(query, sizeof(query), "%s, `carMod1` = '%d', `carMod2` = '%d', `carMod3` = '%d', `carMod4` = '%d', `carMod5` = '%d', `carMod6` = '%d', `carMod7` = '%d', `carMod8` = '%d', `carMod9` = '%d', `carMod10` = '%d', `carMod11` = '%d', `carMod12` = '%d', `carMod13` = '%d', `carMod14` = '%d'", query, CarData[carid][carMods][0], CarData[carid][carMods][1], CarData[carid][carMods][2], CarData[carid][carMods][3], CarData[carid][carMods][4], CarData[carid][carMods][5], CarData[carid][carMods][6], CarData[carid][carMods][7], CarData[carid][carMods][8], CarData[carid][carMods][9], CarData[carid][carMods][10], CarData[carid][carMods][11], CarData[carid][carMods][12], CarData[carid][carMods][13] ); format(query, sizeof(query), "%s, `carImpounded` = '%d', `carImpoundPrice` = '%d', `carFaction` = '%d' , `carSiren` = '%d', `carWeapon1` = '%d', `carWeapon2` = '%d', `carWeapon3` = '%d', `carWeapon4` = '%d', `carWeapon5` = '%d', `carAmmo1` = '%d', `carAmmo2` = '%d', `carAmmo3` = '%d', `carAmmo4` = '%d', `carAmmo5` = '%d' WHERE `carID` = '%d'", query, CarData[carid][carImpounded], CarData[carid][carImpoundPrice], CarData[carid][carFaction], CarData[carid][carSiren], CarData[carid][carWeapons][0], CarData[carid][carWeapons][1], CarData[carid][carWeapons][2], CarData[carid][carWeapons][3], CarData[carid][carWeapons][4], CarData[carid][carAmmo][0], CarData[carid][carAmmo][1], CarData[carid][carAmmo][2], CarData[carid][carAmmo][3], CarData[carid][carAmmo][4], CarData[carid][carID] ); return mysql_tquery(g_iHandle, query); }