11.09.2016, 17:12
Hello!
I'm making a MySQL vehicles system and I need some help. First of all, I create vehicles IG, then I sell this vehicles generating one copy of the vehicle created. That's not the problem, the car creates good. I want to make something but I don't know how I can do it.
I want the user can "despawn" the car. So, he has a dialog with his buyed cars and if he click on one car, the car dissapears. Then If he click another time the car (on list dialog) the car will be respawned.
Actually I store vehicles in arrays (Vehicles for ALL vehicles and VehicleUser for user vehicles). The system on my head works but then, on my script not. Some code:
Works, but I have a bug. When I "save" a car, the other cars gets another ID's. So I do all via MySQL ID's (row ID's, an autoincrement). But I only can Save and Spawn a car only one time, the second time I try to save or spawn a car, doen't do nothing (I think it's problem of the IDs). If anyone is interested on a big help, I can provide the entire script and a SQL file...
Lot, lot lot of thanks!
I'm making a MySQL vehicles system and I need some help. First of all, I create vehicles IG, then I sell this vehicles generating one copy of the vehicle created. That's not the problem, the car creates good. I want to make something but I don't know how I can do it.
I want the user can "despawn" the car. So, he has a dialog with his buyed cars and if he click on one car, the car dissapears. Then If he click another time the car (on list dialog) the car will be respawned.
Actually I store vehicles in arrays (Vehicles for ALL vehicles and VehicleUser for user vehicles). The system on my head works but then, on my script not. Some code:
Код:
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; }
Lot, lot lot of thanks!