
forward CargarCoches();
enum InfoCoche
{
Modelo,
Float:Posicionx,
Float:Posiciony,
Float:Posicionz,
ColorUno
};
new Coche[2][InfoCoche];
for(new h = 0; h < sizeof(Coche); h++)
{
CreateVehicle(Coche[h][Modelo],Coche[h][Posicionx],Coche[h][Posiciony],Coche[h][Posicionz],180,Coche[h][ColorUno],16,0);
}
public CargarCoches()
{
new arrCoords[5][64];
new strFromFile2[256];
new File: file = fopen("Coches/cars.cfg", io_read);
if (file)
{
new idx;
while (idx < sizeof(Negocio))
{
fread(file, strFromFile2);
split(strFromFile2, arrCoords, ',');
Coche[idx][Modelo] = strval(arrCoords[0]);
Coche[idx][Posicionx] = floatstr(arrCoords[1]);
Coche[idx][Posiciony] = floatstr(arrCoords[2]);
Coche[idx][Posicionz] = floatstr(arrCoords[3]);
Coche[idx][ColorUno] = strval(arrCoords[4]);
idx++;
}
fclose(file);
}
return 1;
}
idx = 0;
while (idx < sizeof(Coche))
{
new coordsstring[256];
format(coordsstring, sizeof(coordsstring), "%d,%f,%f,%f,%d\n",
Coche[idx][Modelo],
Coche[idx][Posicionx],
Coche[idx][Posiciony],
Coche[idx][Posicionz],
Coche[idx][ColorUno]);
if(idx == 0)
{
file2 = fopen("Coches/cars.cfg", io_write);
}
else
{
file2 = fopen("Coches/cars.cfg", io_append);
}
fwrite(file2, coordsstring);
idx++;
fclose(file2);
}

CargarCoches();

#define MAX_COCHES (100)
new cochesitos[MAX_COCHES];
// leer el archivo
new File:archivo = fopen("coches/cars.cfg", io_read), datos[200], autos;
if(archivo){
while(fread(archivo, datos)){
_StripNewLine(datos);
new Float:coord[4], model;
if(!sscanf(datos, "p<,>dffff", model, coord[0],coord[1],coord[2], coord[4])){
cochesitos[autos] = AddStaticVehicleEx(model, coord[0],coord[1],coord[2], coord[4], -1, -1, 99999);
}
autos++;
}
fclose(archivo);
}
// guardar en archivo
new File:archivo = fopen("coches/cars.cfg", io_write), datos[200];
if(archivo){
for(new vehicleid=0; vehicleid<MAX_VEHICLES; vehicleid++) {
if(IsValidVehicle(vehicleid)){
for(new autos=0; autos<sizeof(cochesitos); autos++){
if(vehicleid == cochesitos[autos]){
new Float:coord[4], model;
model = GetVehicleModel(cochesitos[autos]);
GetVehiclePos(cochesitos[autos], coord[0],coord[1],coord[2]);
GetVehicleZAngle(cochesitos[autos], coord[4]);
format(datos,sizeof(datos),"%d,%f,%f,%f,%f\r\n", model,coord[0],coord[1],coord[2], coord[4]);
fwrite(archivo, datos);
DestroyVehicle(cochesitos[autos]);
}
}
}
}
fclose(archivo);
}
stock _StripNewLine(string[]) {//dini
new len = strlen(string);
if (string[0]==0) return ;
if ((string[len - 1] == '\n') || (string[len - 1] == '\r')) {
string[len - 1] = 0;
if (string[0]==0) return ;
if ((string[len - 2] == '\n') || (string[len - 2] == '\r')) string[len - 2] = 0;
}
}
|
Gracias, acabo de hacer eso, pero ahora hay un problema, ahora ningъn vehнculo aparece en el server cuando lo inicio, ni siquiera los del GameMode.
![]() їQuй puede ser? |
|
Entonces hay un problema con la funciуn guardado o cargado de coches
|
new idx;
while (idx < sizeof(Negocio)) // Esta parte
{
|
Hay una parte en la funciуn donde cargas los vehнculos, que posiblemente sea la que causa eso:
pawn Код:
|