15.01.2013, 13:00
Well, im making a vehicle system, and im using djson. It saves the vehicle with an id for it, like this;
Where %d is the id, the id that im using to save it is the carid, but inside the data saved there, there is an unique ID, the problem that if i delete a car and it is before some car, the ids would be moved, so the next time i save or load a vehicle, it will be bugged, what can i do?, my mind is closed, here i leave the code for saving and load vehicles.
So, there the car is saved by the id given by samp, and here the load code:
Ok, here i load the cars, but what if a have deleted a car and it was before another one, and i want to save it, it will be bugged, because if it is saved like Coche_52, now it will be saved like Coche_51, and there will be a Coche_51 and Coche_52 with the same data, so waht can i do?
Код:
Vehicle_%d
Код:
funcion GuardarCoche(idcoche) { new string[150]; djAutocommit(false); format(string,sizeof(string),"Coche_%d/ID",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cID]); format(string,sizeof(string),"Coche_%d/Aeros",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cAeros]); format(string,sizeof(string),"Coche_%d/Alarma",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cAlarma]); format(string,sizeof(string),"Coche_%d/Arma1",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cArma1]); format(string,sizeof(string),"Coche_%d/Arma2",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cArma2]); format(string,sizeof(string),"Coche_%d/Arma3",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cArma3]); format(string,sizeof(string),"Coche_%d/Arma4",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cArma4]); format(string,sizeof(string),"Coche_%d/Bateria",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cBateria]); format(string,sizeof(string),"Coche_%d/BateriaT",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cBateriaT]); format(string,sizeof(string),"Coche_%d/Bloqueado",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cBloqueado]); format(string,sizeof(string),"Coche_%d/BumperD",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cBumperD]); format(string,sizeof(string),"Coche_%d/BumperT",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cBumperT]); format(string,sizeof(string),"Coche_%d/Capo",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cCapo]); format(string,sizeof(string),"Coche_%d/Chaleco",idcoche); djSetFloat(GCoches,string,InfoCoche[idcoche][cChaleco]); format(string,sizeof(string),"Coche_%d/Color1",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cColor1]); format(string,sizeof(string),"Coche_%d/Color2",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cColor2]); format(string,sizeof(string),"Coche_%d/Comprable",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cComprable]); format(string,sizeof(string),"Coche_%d/Drogas",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cDrogas]); format(string,sizeof(string),"Coche_%d/Dueno",idcoche); djSet(GCoches,string,InfoCoche[idcoche][cDueno]); format(string,sizeof(string),"Coche_%d/Encendido",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cEncendido]); format(string,sizeof(string),"Coche_%d/Exausto",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cExausto]); format(string,sizeof(string),"Coche_%d/Faccion",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cFaccion]); format(string,sizeof(string),"Coche_%d/Faldones",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cFaldones]); format(string,sizeof(string),"Coche_%d/Gas",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cGas]); format(string,sizeof(string),"Coche_%d/GasT",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cGasT]); format(string,sizeof(string),"Coche_%d/GPS",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cGPS]); format(string,sizeof(string),"Coche_%d/Hidraulicos",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cHidraulicos]); format(string,sizeof(string),"Coche_%d/Llantas",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cLlantas]); format(string,sizeof(string),"Coche_%d/Luces",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cLuces]); format(string,sizeof(string),"Coche_%d/Modelo",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cModelo]); format(string,sizeof(string),"Coche_%d/Motor",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cMotor]); format(string,sizeof(string),"Coche_%d/Multa",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cMulta]); format(string,sizeof(string),"Coche_%d/MultaRazon",idcoche); djSet(GCoches,string,InfoCoche[idcoche][cMultaRazon]); format(string,sizeof(string),"Coche_%d/MultaPor",idcoche); djSet(GCoches,string,InfoCoche[idcoche][cMultaPor]); format(string,sizeof(string),"Coche_%d/Mun1",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cMun1]); format(string,sizeof(string),"Coche_%d/Mun2",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cMun2]); format(string,sizeof(string),"Coche_%d/Mun3",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cMun3]); format(string,sizeof(string),"Coche_%d/Mun4",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cMun4]); format(string,sizeof(string),"Coche_%d/Nitro",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cNitro]); format(string,sizeof(string),"Coche_%d/Nombre",idcoche); djSet(GCoches,string,InfoCoche[idcoche][cNombre]); format(string,sizeof(string),"Coche_%d/Paintjob",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cPaintjob]); format(string,sizeof(string),"Coche_%d/Placa",idcoche); djSet(GCoches,string,InfoCoche[idcoche][cPlaca]); format(string,sizeof(string),"Coche_%d/Spoiler",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cSpoiler]); format(string,sizeof(string),"Coche_%d/Techo",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cTecho]); format(string,sizeof(string),"Coche_%d/Trabajo",idcoche); djSetInt(GCoches,string,InfoCoche[idcoche][cTrabajo]); format(string,sizeof(string),"Coche_%d/X",idcoche); djSetFloat(GCoches,string,InfoCoche[idcoche][cX]); format(string,sizeof(string),"Coche_%d/Y",idcoche); djSetFloat(GCoches,string,InfoCoche[idcoche][cY]); format(string,sizeof(string),"Coche_%d/Z",idcoche); djSetFloat(GCoches,string,InfoCoche[idcoche][cZ]); format(string,sizeof(string),"Coche_%d/A",idcoche); djSetFloat(GCoches,string,InfoCoche[idcoche][cA]); djCommit(GCoches); djAutocommit(true); return 1; }
Код:
funcion CargarCoches(idcoche) //Trenico { new string[40], string2[40]; format(string, sizeof(string),"Coche_%d",idcoche); if(djIsSet(GCoches,string)) { format(string2, sizeof(string2),"Coche_%d/ID",idcoche); InfoCoche[idcoche][cID] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Aeros",idcoche); InfoCoche[idcoche][cAeros] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Alarma",idcoche); InfoCoche[idcoche][cAlarma] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Arma1",idcoche); InfoCoche[idcoche][cArma1] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Arma2",idcoche); InfoCoche[idcoche][cArma2] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Arma3",idcoche); InfoCoche[idcoche][cArma3] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Arma4",idcoche); InfoCoche[idcoche][cArma4] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Bateria",idcoche); InfoCoche[idcoche][cBateria] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/BateriaT",idcoche); InfoCoche[idcoche][cBateriaT] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Bloqueado",idcoche); InfoCoche[idcoche][cBloqueado] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/BumperD",idcoche); InfoCoche[idcoche][cBumperD] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/BumperT",idcoche); InfoCoche[idcoche][cBumperT] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Capo",idcoche); InfoCoche[idcoche][cCapo] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Chaleco",idcoche); InfoCoche[idcoche][cChaleco] = djFloat(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Color1",idcoche); InfoCoche[idcoche][cColor1] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Color2",idcoche); InfoCoche[idcoche][cColor2] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Comprable",idcoche); InfoCoche[idcoche][cComprable] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Drogas",idcoche); InfoCoche[idcoche][cDrogas] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Dueno",idcoche); strmid(InfoCoche[idcoche][cDueno],dj(GCoches, string2),0,24,24); format(string2, sizeof(string2),"Coche_%d/Encendido",idcoche); InfoCoche[idcoche][cEncendido] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Exausto",idcoche); InfoCoche[idcoche][cExausto] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Faccion",idcoche); InfoCoche[idcoche][cFaccion] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Faldones",idcoche); InfoCoche[idcoche][cFaldones] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Gas",idcoche); InfoCoche[idcoche][cGas] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/GasT",idcoche); InfoCoche[idcoche][cGasT] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/GPS",idcoche); InfoCoche[idcoche][cGPS] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Hidraulicos",idcoche); InfoCoche[idcoche][cHidraulicos] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Llantas",idcoche); InfoCoche[idcoche][cLlantas] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Luces",idcoche); InfoCoche[idcoche][cLuces] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Modelo",idcoche); InfoCoche[idcoche][cModelo] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Motor",idcoche); InfoCoche[idcoche][cMotor] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Multa",idcoche); InfoCoche[idcoche][cMulta] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/MultaRazon",idcoche); strmid(InfoCoche[idcoche][cMultaRazon],dj(GCoches, string2),0,25,25); format(string2, sizeof(string2),"Coche_%d/MultaPor",idcoche); strmid(InfoCoche[idcoche][cMultaPor],dj(GCoches, string2),0,24,24); format(string2, sizeof(string2),"Coche_%d/Mun1",idcoche); InfoCoche[idcoche][cMun1] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Mun2",idcoche); InfoCoche[idcoche][cMun2] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Mun3",idcoche); InfoCoche[idcoche][cMun3] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Mun4",idcoche); InfoCoche[idcoche][cMun4] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Nitro",idcoche); InfoCoche[idcoche][cNitro] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Nombre",idcoche); strmid(InfoCoche[idcoche][cNombre],dj(GCoches, string2),0,30,30); format(string2, sizeof(string2),"Coche_%d/Paintjob",idcoche); InfoCoche[idcoche][cPaintjob] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Placa",idcoche); strmid(InfoCoche[idcoche][cPlaca],dj(GCoches, string2),0,8,8); format(string2, sizeof(string2),"Coche_%d/Spoiler",idcoche); InfoCoche[idcoche][cSpoiler] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Techo",idcoche); InfoCoche[idcoche][cTecho] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Trabajo",idcoche); InfoCoche[idcoche][cTrabajo] = djInt(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/X",idcoche); InfoCoche[idcoche][cX] = djFloat(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Y",idcoche); InfoCoche[idcoche][cY] = djFloat(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/Z",idcoche); InfoCoche[idcoche][cZ] = djFloat(GCoches, string2); format(string2, sizeof(string2),"Coche_%d/A",idcoche); InfoCoche[idcoche][cA] = djFloat(GCoches, string2); new idcoche2 = AddStaticVehicleEx(InfoCoche[idcoche][cModelo],InfoCoche[idcoche][cX],InfoCoche[idcoche][cY],InfoCoche[idcoche][cZ],InfoCoche[idcoche][cA],InfoCoche[idcoche][cColor1],InfoCoche[idcoche][cColor2],12000); SetVehicleNumberPlate(idcoche,InfoCoche[idcoche2][cPlaca]); ResetearVariablesCoches(idcoche2); //SetVehicleToRespawn(idcoche2); IDCoches[idcoche2] = InfoCoche[idcoche][cID]; SetVehicleParamsEx(idcoche2,InfoCoche[idcoche][cEncendido],InfoCoche[idcoche][cLuces],0,0,0,0,0); AplicarTuning(idcoche); if(InfoCoche[idcoche][cID] > UltimaIDVeh) { UltimaIDVeh = InfoCoche[idcoche][cID]; } return InfoCoche[idcoche][cID]; } return print("*Un coche no pudo ser cargado!"); }