Quote:
Originally Posted by chusothe41
Creo que si lo entiendo ahora.
Que al iniciar el gm carga cada vehiculo con una id predefinida y al aсadir mas coches pueden robarse las ids.
Bien lo que te recomendaria es que no guardaras los coches y los cargaras por id, lo mejor es crear un coche y guardar su valor en una varible por ejemplo
pawn Код:
#define vehfile "/Vehiculos/%s.ini" //#define MAX_VEHICLES 1000 new coches;
//coches = AddStaticVehicle(modelid, x, y, z, angle, color1, color2);
enum pVehicle { pModelid, Float: px, Float: py, Float: pz, Float: pAngle, pcolor1, pcolor2 }
new VehicleInfo[MAX_PLAYERS][pVehicle];
stock VehiclePath(playerid)//si quieres guardar los vehiculos con otro nombre cambia esto { new string[128],playername[MAX_PLAYER_NAME]; GetPlayerName(playerid,playername,sizeof(playername)); format(string,sizeof(string),vehfile,playername); return string; }
forward LoadVehicle_data(playerid,name[],value[]); public LoadVehicle_data(playerid,name[],value[]) { INI_Int("Modelid",VehicleInfo[playerid][pModelid]); INI_Float("x",VehicleInfo[playerid][px]); INI_Float("y",VehicleInfo[playerid][py]); INI_Float("z",VehicleInfo[playerid][pz]); INI_Float("Angle",VehicleInfo[playerid][pAngle]); INI_Int("color1",VehicleInfo[playerid][pcolor1]); INI_Int("color2",VehicleInfo[playerid][pcolor2]); return 1; }
YCMD:Vehiculo1(playerid, params[], help) { #pragma unused params #pragma unused help new INI:File = INI_Open(VehiclePath(playerid)); INI_WriteFloat(File,"x",0); //pon donde quiers que se cree el vehiculo INI_WriteFloat(File,"y",0); INI_WriteFloat(File,"z",0); INI_WriteFloat(File,"Angle",0); INI_WriteInt(File,"Modelid",0); INI_WriteInt(File,"color1",0); INI_WriteInt(File,"color2",0); coches = AddStaticVehicle(0, 0, 0, 0, 0, 0, 0); return coches; }
YCMD:Vehiculo2(playerid, params[], help) { #pragma unused params #pragma unused help coches = AddStaticVehicle(VehicleInfo[playerid][pModelid],VehicleInfo[playerid][px],VehicleInfo[playerid][py],VehicleInfo[playerid][pz],VehicleInfo[playerid][pAngle],VehicleInfo[playerid][pcolor1],VehicleInfo[playerid][pcolor2]); return coches; }
public OnPlayerConnect(playerid) { INI_ParseFile(VehiclePath(playerid), "LoadVehicle_%s", .bExtra = true, .extra = playerid); return 1; }
Creo que mas o menos se entiende la idea sino preguntame
|
No creo que funcione, no uso path para los vehiculos, la funciуn para cargarlos y guardarlos es esta:
pawn Код:
stock SaveVehicle(vehicle, filename[36])
{
new INI:File = INI_Open(filename);
INI_SetTag(File,"Data");
INI_WriteInt(File, "Modelo", cInformacion[vehicle][cModelo]);
new Float:pos[3], Float:Angulo;
GetVehiclePos(vehicle, pos[0], pos[1], pos[2]);
GetVehicleZAngle(vehicle, Angulo);
INI_WriteFloat(File, "X", pos[0]);
INI_WriteFloat(File, "Y", pos[1]);
INI_WriteFloat(File, "Z", pos[2]);
INI_WriteFloat(File, "Angle", Angulo);
INI_WriteInt(File, "Color1", cInformacion[vehicle][cCol1]);
INI_WriteInt(File, "Color2", cInformacion[vehicle][cCol2]);
INI_WriteInt(File, "Respawn", cInformacion[vehicle][cRespawn]);
INI_WriteString(File, "Dueсo", cInformacion[vehicle][cOwner]);
INI_WriteInt(File, "Seguro", cInformacion[vehicle][cLocked]);
INI_Close(File);
}
stock SaveAllVehicles()
{
new saveindex = 0;
new fname[36];
for(new i = 0; i < MAX_VEHICLES; i ++)
{
if(validcar[i])
{
format(fname, sizeof(fname), "/Vehiculos/%d.ini", saveindex);
SaveVehicle(i, fname);
saveindex ++;
}
}
}
y para guardarlos:
pawn Код:
stock VehicleLoad(vehicleID, file[])
{
INI_ParseFile(file, "LoadVehicle_Data", .bExtra = true, .extra = vehicleID);
CrearVehiculo(cInformacion[vehicleID][cModelo], cInformacion[vehicleID][cx], cInformacion[vehicleID][cy], cInformacion[vehicleID][cz], cInformacion[vehicleID][cAngle], cInformacion[vehicleID][cCol1], cInformacion[vehicleID][cCol2], cInformacion[vehicleID][cRespawn], cInformacion[vehicleID][cOwner], cInformacion[vehicleID][cLocked]);
}
stock CrearVehiculo(Modelo, Float:x, Float:y, Float:z, Float:Angulo, Col1, Col2, Respawn, Owner[], seguro)
{
new vehicleID = GetFreeVehicleSlot(), engine, lights, alarm, doors, bonnet, boot, objective;
cInformacion[vehicleID][cModelo] = Modelo;
cInformacion[vehicleID][cCol1] = Col1;
cInformacion[vehicleID][cCol2] = Col2;
cInformacion[vehicleID][cRespawn] = Respawn;
format(cInformacion[vehicleID][cOwner], MAX_PLAYER_NAME, Owner);
cInformacion[vehicleID][cLocked] = seguro;
CreateVehicle(Modelo, x, y, z, Angulo, Col1, Col2, Respawn);
GetVehicleParamsEx(vehicleID, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleID, 0, 0, alarm, seguro, bonnet, boot, objective);
validcar[vehicleID] = true;
}
forward LoadVehicle_Data(vehicleID, name[], value[]);
public LoadVehicle_Data(vehicleID, name[], value[])
{
INI_Int("Modelo", cInformacion[vehicleID][cModelo]);
INI_Float("X", cInformacion[vehicleID][cx]);
INI_Float("Y", cInformacion[vehicleID][cy]);
INI_Float("Z", cInformacion[vehicleID][cz]);
INI_Float("Angle", cInformacion[vehicleID][cAngle]);
INI_Int("Color1", cInformacion[vehicleID][cCol1]);
INI_Int("Color2", cInformacion[vehicleID][cCol2]);
INI_Int("Respawn", cInformacion[vehicleID][cRespawn]);
INI_String("Dueсo", cInformacion[vehicleID][cOwner], MAX_PLAYER_NAME);
INI_Int("Seguro", cInformacion[vehicleID][cLocked]);
CrearVehiculo(cInformacion[vehicleID][cModelo], cInformacion[vehicleID][cx], cInformacion[vehicleID][cy], cInformacion[vehicleID][cz], cInformacion[vehicleID][cAngle], cInformacion[vehicleID][cCol1], cInformacion[vehicleID][cCol2], cInformacion[vehicleID][cRespawn], cInformacion[vehicleID][cOwner], cInformacion[vehicleID][cLocked]);
return 1;
}
stock SaveAllVehicles()
{
new saveindex = 0;
new fname[36];
for(new i = 0; i < MAX_VEHICLES; i ++)
{
if(validcar[i])
{
format(fname, sizeof(fname), "/Vehiculos/%d.ini", saveindex);
SaveVehicle(i, fname);
saveindex ++;
}
}
}
Y la funciуn del validcar:
pawn Код:
stock GetFreeVehicleSlot()
{
for(new i = 0; i < sizeof(validcar); i ++)
{
if(!validcar[i]) return i;
}
return -1;
}
Tal vez hay un error porquй al crear un auto en el GM, no lo toma como valid car, entonces usa su ID...