21.12.2015, 20:34
I use code like this:
On the top
My enum
OnPlayerConnect
And this forward
And this stock for CarOwnSpawn
Any error like that ..
I assume there are three players who will be logged, Playe A, B, and C. Player A have 3 cars/vehicle, B 2 cars/vehicle, C 3 cars/vehicle.
If Player A logged, he/she success to get all the vehicles. And if player B logged he/she success to get all the vehicles too, but Player A lost 1 his/him vehicle, but the vehicle does not destroy, just belongs to the server. And if Player C logged he/she success to get all the vehicles too, but Player B lost one vehicle like player A. Player A not lost vehicle again just player last logged. And if player A relog, he/she get back all the vehicles, and cause lost one vehicle for player last logged ..
Any someone help me? Please ..
Sorry my english is very bad.
On the top
Код:
#define THREAD_LOAD_CARSOWNED #define MAX_DYNAMIC_CARS 1500
Код:
enum carData { carID, carExists, carModel, carOwner, Float:carPos[4], carColor1, carColor2, carPaintjob, carLocked, carMods[14], carImpounded, carImpoundPrice, carWeapons[5], carAmmo[5], carVehicle }; new CarData[MAX_DYNAMIC_CARS][carData];
Код:
format(query, sizeof(query), "SELECT * FROM `carsowned` WHERE `carOwner` = '%d'", PlayerData[extraid][pID]); mysql_tquery(g_iHandle, query, "OnQueryFinished", "dd", extraid, THREAD_LOAD_CARSOWNED);
Код:
forward OnQueryFinished(extraid, threadid); public OnQueryFinished(extraid, threadid) { if (!IsPlayerConnected(extraid)) return 0; static rows, fields ; switch (threadid) { case THREAD_LOAD_CARSOWNED: { static str[128]; cache_get_data(rows, fields, g_iHandle); for (new i = 0; i < rows; i ++) if (i < MAX_DYNAMIC_CARS) { CarData[i][carExists] = true; CarData[i][carID] = cache_get_field_int(i, "carID"); CarData[i][carModel] = cache_get_field_int(i, "carModel"); CarData[i][carOwner] = cache_get_field_int(i, "carOwner"); CarData[i][carPos][0] = cache_get_field_float(i, "carPosX"); CarData[i][carPos][1] = cache_get_field_float(i, "carPosY"); CarData[i][carPos][2] = cache_get_field_float(i, "carPosZ"); CarData[i][carPos][3] = cache_get_field_float(i, "carPosR"); CarData[i][carColor1] = cache_get_field_int(i, "carColor1"); CarData[i][carColor2] = cache_get_field_int(i, "carColor2"); CarData[i][carPaintjob] = cache_get_field_int(i, "carPaintjob"); CarData[i][carLocked] = cache_get_field_int(i, "carLocked"); CarData[i][carImpounded] = cache_get_field_int(i, "carImpounded"); CarData[i][carImpoundPrice] = cache_get_field_int(i, "carImpoundPrice"); for (new j = 0; j < 14; j ++) { if (j < 5) { format(str, sizeof(str), "carWeapon%d", j + 1); CarData[i][carWeapons][j] = cache_get_field_int(i, str); format(str, sizeof(str), "carAmmo%d", j + 1); CarData[i][carAmmo][j] = cache_get_field_int(i, str); } format(str, sizeof(str), "carMod%d", j + 1); CarData[i][carMods][j] = cache_get_field_int(i, str); } CarOwnSpawn(i); } for (new i = 0; i < MAX_DYNAMIC_CARS; i ++) if (CarData[i][carExists]) { format(str, sizeof(str), "SELECT * FROM `carstorage` WHERE `ID` = '%d'", CarData[i][carID]); mysql_tquery(g_iHandle, str, "OnLoadCarStorage", "d", i); } } } }
Код:
stock CarOwnSpawn(carid) { if (carid != -1 && CarData[carid][carExists]) { CarData[carid][carVehicle] = CreateVehicle(CarData[carid][carModel], CarData[carid][carPos][0], CarData[carid][carPos][1], CarData[carid][carPos][2], CarData[carid][carPos][3], CarData[carid][carColor1], CarData[carid][carColor2], -1); if (CarData[carid][carVehicle] != INVALID_VEHICLE_ID) { if (CarData[carid][carPaintjob] != -1) { ChangeVehiclePaintjob(CarData[carid][carVehicle], CarData[carid][carPaintjob]); } if (CarData[carid][carLocked]) { new engine, lights, alarm, doors, bonnet, boot, objective; GetVehicleParamsEx(CarData[carid][carVehicle], engine, lights, alarm, doors, bonnet, boot, objective); SetVehicleParamsEx(CarData[carid][carVehicle], engine, lights, alarm, 1, bonnet, boot, objective); } for (new i = 0; i < 14; i ++) { if (CarData[carid][carMods][i]) AddVehicleComponent(CarData[carid][carVehicle], CarData[carid][carMods][i]); } ResetVehicle(CarData[carid][carVehicle]); return 1; } } return 0; }
I assume there are three players who will be logged, Playe A, B, and C. Player A have 3 cars/vehicle, B 2 cars/vehicle, C 3 cars/vehicle.
If Player A logged, he/she success to get all the vehicles. And if player B logged he/she success to get all the vehicles too, but Player A lost 1 his/him vehicle, but the vehicle does not destroy, just belongs to the server. And if Player C logged he/she success to get all the vehicles too, but Player B lost one vehicle like player A. Player A not lost vehicle again just player last logged. And if player A relog, he/she get back all the vehicles, and cause lost one vehicle for player last logged ..
Any someone help me? Please ..
Sorry my english is very bad.