public OnFilterScriptInit() { // Here loads ALL the vehicles LoadVehicles(); } public OnFilterScriptExit() { SaveVehicles(); return 1; } public OnPlayerSpawn(playerid) { // Here ONLY USER vehicles LoadUserVehicles(playerid); } CMD:mycars(playerid, params[]) { new string[240]; new stats[30]; new count; for(new i=0;i<DYNAMIC_MAX;i++) { if(strmatch(VehicleUser[i][Owner],PlayerName(playerid))) { if (VehicleUser[i][Stats] == 0) { stats = "{B2F289}Spawnead"; } else if (VehicleUser[i][Stats] == 1) { stats = "{CAE1FF}Saved"; } format(string,sizeof(string), "%s%s (%d) - [%s] - %s\n", string, GetVehicleName(VehicleUser[i][Model]), VehicleUser[i][ID], VehiclePlate(VehicleUser[i][ID]), stats); ListSelection[playerid][count] = i; count++; } } if (count >= 1) { ShowPlayerDialog(playerid, DIALOG_MYCARS, DIALOG_STYLE_LIST, "My Cars", string, "Change", "Exit"); } else { SendClientMessage(playerid, -1, "{40D3FF}[SERVIDOR]: {FFFFFF}You don't own any car."); } return 1; } public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) { if (dialogid == DIALOG_MYCARS) { if(response) { new sel[300]; new stats[30]; if (VehicleUser[ListSelection[playerid][listitem]][Stats] == 0) { new Float:XX1, Float:YY1, Float:ZZ1; GetVehiclePos(VehicleUser[ListSelection[playerid][listitem]][ID], XX1, YY1, ZZ1); if(IsPlayerInRangeOfPoint(playerid, 3.0, XX1, YY1, ZZ1)) { stats = "{CAE1FF}saved"; format(sel,sizeof(sel),"{FFFFFF}You have %s the vehicleid %d.", stats, VehicleUser[ListSelection[playerid][listitem]][ID]); ShowPlayerDialog(playerid, DIALOG_ALERT, DIALOG_STYLE_MSGBOX, "Attention!", sel, "Okay!", ""); DeleteVehicleFromServer(playerid, GetVehicleID(VehicleUser[ListaSeleccion[playerid][listitem]][ID])); SaveStats(ListSelection[playerid][listitem], 1); // Just update DB. Works fine. FreeVehicleID(); LoadUserVehicles(playerid); } else { SendClientMessage(playerid,-1,"{40D3FF}[SERVER]: {FFFFFF}3m to your vehicle!"); } } else { stats = "{B2F289}spawned"; format(sel,sizeof(sel),"{FFFFFF}You have %s the vehicle.",stats); ShowPlayerDialog(playerid, DIALOG_ALERT, DIALOG_STYLE_MSGBOX, "Attention!", sel, "Okay!", ""); SaveStats(ListSelection[playerid][listitem], 0); CreateUserVehicleByID(ListSelection[playerid][listitem]); SetVehicleHealth(VehicleUser[ListSelection[playerid][listitem]][ID], VehicleUser[GetVehicleID(VehicleUser[ListSelection[playerid][listitem]][ID])][Health]); LoadUserVehicles(playerid); } } } return 1; }
// Loading ALL vehicles public OnVehiclesLoad() { for(new i = 0; i < cache_num_rows(); i++) { Vehicle[i][ID] = cache_get_field_content_int(i, "ID"); cache_get_field_content(i, "plate", str); strpack(Vehicle[i][Plate], str, 30); Vehicle[i][Model] = cache_get_field_content_int(i, "model"); Vehicle[i][Color1] = cache_get_field_content_int(i, "color1"); Vehicle[i][Color2] = cache_get_field_content_int(i, "color2"); Vehicle[i][PosX] = cache_get_field_content_float(i, "posx"); Vehicle[i][PosY] = cache_get_field_content_float(i, "posy"); Vehicle[i][PosZ] = cache_get_field_content_float(i, "posz"); Vehicle[i][PosA] = cache_get_field_content_float(i, "posa"); cache_get_field_content(i, "llaves1", str); strpack(Vehicle[i][Llaves1], str, 30); cache_get_field_content(i, "llaves2", str); strpack(Vehicle[i][Llaves2], str, 30); cache_get_field_content(i, "llaves3", str); strpack(Vehicle[i][Llaves3], str, 30); cache_get_field_content(i, "llaves4", str); strpack(Vehicle[i][Llaves4], str, 30); cache_get_field_content(i, "dueno", str); strpack(Vehicle[i][Dueno], str, 30); Vehicle[i][Bloqueo] = cache_get_field_content_int(i, "bloqueo"); Vehicle[i][Precio] = cache_get_field_content_int(i, "precio"); Vehicle[i][Venta] = cache_get_field_content_int(i, "venta"); Vehicle[i][Stats] = cache_get_field_content_int(i, "stats"); Vehicle[i][ExpoX] = cache_get_field_content_float(i, "expox"); Vehicle[i][ExpoY] = cache_get_field_content_float(i, "expoy"); Vehicle[i][ExpoZ] = cache_get_field_content_float(i, "expoz"); Vehicle[i][ExpoA] = cache_get_field_content_float(i, "expoa"); Vehicle[i][TotalLlaves] = cache_get_field_content_int(i, "totalllaves"); Vehicle[i][A1] = cache_get_field_content_int(i, "a1"); Vehicle[i][A2] = cache_get_field_content_int(i, "a2"); Vehicle[i][A3] = cache_get_field_content_int(i, "a3"); Vehicle[i][A4] = cache_get_field_content_int(i, "a4"); Vehicle[i][A5] = cache_get_field_content_int(i, "a5"); Vehicle[i][M1] = cache_get_field_content_int(i, "m1"); Vehicle[i][M2] = cache_get_field_content_int(i, "m2"); Vehicle[i][M3] = cache_get_field_content_int(i, "m3"); Vehicle[i][M4] = cache_get_field_content_int(i, "m4"); Vehicle[i][M5] = cache_get_field_content_int(i, "m5"); Vehicle[i][Vida] = cache_get_field_content_float(i, "vida"); Vehicle[i][Created] = false; CreateVehicleByIDX(i); } printf(">> Loaded %d vehicles from DB.", cache_num_rows()); } // Creating the vehicles by IDX (idx is the row ID). CreateVehicleByIDX(idx) { if(Vehicle[idx][Created]) { DestroyVehicle(Vehicle[idx][VehicleID]); Delete3DTextLabel(Vehicle[idx][NameLabel]); } // We create the car ONLY if STATS = 0 (SPAWNED) if(Vehicle[idx][Stats] == 0) { Vehicle[idx][VehicleID] = CreateVehicle(Vehicle[idx][Model], Vehicle[idx][PosX], Vehicle[idx][PosY], Vehicle[idx][PosZ], Vehicle[idx][PosA], Vehicle[idx][Color1], Vehicle[idx][Color1], -1); SetVehicleNumberPlate(Vehicle[idx][VehicleID], VehiclePlate(idx)); SetVehicleHealth(Vehicle[idx][VehicleID], Vehicle[idx][Vida]); Vehicle[idx][Created] = true; } } // Loading the user vehicles (onplayerspawn, this is the tquery function response). public OnVehiclesUserLoad() { for(new i = 0; i < cache_num_rows(); i++) { VehicleUser[i][ID] = cache_get_field_content_int(i, "ID"); cache_get_field_content(i, "plate", str); strpack(VehicleUser[i][Plate], str, 30); VehicleUser[i][Model] = cache_get_field_content_int(i, "model"); VehicleUser[i][Color1] = cache_get_field_content_int(i, "color1"); VehicleUser[i][Color2] = cache_get_field_content_int(i, "color2"); VehicleUser[i][PosX] = cache_get_field_content_float(i, "posx"); VehicleUser[i][PosY] = cache_get_field_content_float(i, "posy"); VehicleUser[i][PosZ] = cache_get_field_content_float(i, "posz"); VehicleUser[i][PosA] = cache_get_field_content_float(i, "posa"); cache_get_field_content(i, "llaves1", str); strpack(VehicleUser[i][Llaves1], str, 30); cache_get_field_content(i, "llaves2", str); strpack(VehicleUser[i][Llaves2], str, 30); cache_get_field_content(i, "llaves3", str); strpack(VehicleUser[i][Llaves3], str, 30); cache_get_field_content(i, "llaves4", str); strpack(VehicleUser[i][Llaves4], str, 30); cache_get_field_content(i, "dueno", str); strpack(VehicleUser[i][Dueno], str, 30); VehicleUser[i][Bloqueo] = cache_get_field_content_int(i, "bloqueo"); VehicleUser[i][Precio] = cache_get_field_content_int(i, "precio"); VehicleUser[i][Venta] = cache_get_field_content_int(i, "venta"); VehicleUser[i][Stats] = cache_get_field_content_int(i, "stats"); VehicleUser[i][TotalLlaves] = cache_get_field_content_int(i, "totalllaves"); VehicleUser[i][A1] = cache_get_field_content_int(i, "a1"); VehicleUser[i][A2] = cache_get_field_content_int(i, "a2"); VehicleUser[i][A3] = cache_get_field_content_int(i, "a3"); VehicleUser[i][A4] = cache_get_field_content_int(i, "a4"); VehicleUser[i][A5] = cache_get_field_content_int(i, "a5"); VehicleUser[i][M1] = cache_get_field_content_int(i, "m1"); VehicleUser[i][M2] = cache_get_field_content_int(i, "m2"); VehicleUser[i][M3] = cache_get_field_content_int(i, "m3"); VehicleUser[i][M4] = cache_get_field_content_int(i, "m4"); VehicleUser[i][M5] = cache_get_field_content_int(i, "m5"); VehicleUser[i][Vida] = cache_get_field_content_float(i, "vida"); if(VehicleUser[i][Stats] == 0) { VehicleUser[i][Created] = true; } else { VehicleUser[i][Created] = false; } } }
Works, but I have a bug. When I "save" a car, the other cars gets another ID's.
|