Vehicle Health
#1

Hello, how you doing? So I got this problem with vehicle health. Right now I'm working on writing server vehicles data. To do that I'm using ****** y_ini include. When a server saves vehicle data, in .ini file at scriptfiles folder it shows that vehicle (for example) has 900 health. But when I restart the server all saved vehicles explode! Why? Here's my code:

Код:
enum vInfo
{
	vModel,
	Float:vHealth[MAX_VEHICLES],
	Float:vX[MAX_VEHICLES],
	Float:vY[MAX_VEHICLES],
	Float:vZ[MAX_VEHICLES],
	Float:vAngle[MAX_VEHICLES],
}
Код:
public LoadVehicle_data(vehicleid, name[], value[])
{
	INI_Int("Model", VehicleInfo[vehicleid][vModel]);
	INI_Float("Health", VehicleInfo[vehicleid][vHealth]);
	INI_Float("X", VehicleInfo[vehicleid][vX]);
	INI_Float("Y", VehicleInfo[vehicleid][vY]);
	INI_Float("Z", VehicleInfo[vehicleid][vZ]);
	INI_Float("Angle", VehicleInfo[vehicleid][vAngle]);
	return 1;
}
Код:
stock SaveVehicleData(vehicleid)
{
	new vini[32];
	format(vini, sizeof(vini), "Vehicles/%d.ini", vehicleid);
	new INI:File = INI_Open(vini);
	
	new model = GetVehicleModel(vehicleid);
	GetVehiclePos(vehicleid, VehicleInfo[vehicleid][vX], VehicleInfo[vehicleid][vY], VehicleInfo[vehicleid][vZ]);
  	GetVehicleZAngle(vehicleid, VehicleInfo[vehicleid][vAngle]);
	GetVehicleHealth(vehicleid, VehicleInfo[vehicleid][vHealth]);
  	
	INI_SetTag(File,"data");
	INI_WriteInt(File,"Model", model);
	INI_WriteFloat(File,"Health", VehicleInfo[vehicleid][vHealth]);
	INI_WriteFloat(File,"X", VehicleInfo[vehicleid][vX]);
	INI_WriteFloat(File,"Y", VehicleInfo[vehicleid][vY]);
	INI_WriteFloat(File,"Z", VehicleInfo[vehicleid][vZ]);
	INI_WriteFloat(File, "Angle", VehicleInfo[vehicleid][vAngle]);
	INI_Close(File);
	return 1;
}
This I put under OnGameModeInit
Код:
stock LoadServerVehicles()
{
    for(new v = 0; v <= MAX_VEHICLES; v++)
	{
	        new vini[32];
		format(vini, sizeof(vini), "Vehicles/%d.ini", v);
		if(fexist(vini))
    	{
	    	        INI_ParseFile(vini, "LoadVehicle_%s", .bExtra = true, .extra = v);
	    	        CreateVehicle(VehicleInfo[v][vModel], VehicleInfo[v][vX], VehicleInfo[v][vY], VehicleInfo[v][vZ], VehicleInfo[v][vAngle], VehicleInfo[v][Color1], VehicleInfo[v][Color2], -1);
			return 1;
		}else{
                        // Bunch of AddStaticVehiclesEx ...
			return 1;
		}
	}
	return 1;
}
OnVehicleCreated is from MP2 include called Vehicle Functions. Great Include!
Код:
public OnVehicleCreated(vehicleid)
{ 
    new vini[32];
	format(vini, sizeof(vini), "Vehicles/%d.ini", vehicleid);
	
	if(fexist(vini))
	{
                INI_ParseFile(vini, "LoadVehicle_%s", .bExtra = true, .extra = vehicleid);
                SetVehiclePos(vehicleid, VehicleInfo[vehicleid][vX], VehicleInfo[vehicleid][vY], VehicleInfo[vehicleid][vZ]);
		SetVehicleZAngle(vehicleid, VehicleInfo[vehicleid][vAngle]);
		SetVehicleHealth(vehicleid, VehicleInfo[vehicleid][vHealth]);
	}else{
               // ...
               }
	
		SaveVehicleData(vehicleid);
	}
	return 1;
}
Please, I need your help!
Reply
#2

is there a car health saving mate? and position saving
Reply
#3

what do you mean?
Reply
#4

Oh, yeah there's under OnPlayerExitVehicle
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)