SA-MP Forums Archive
[HELP]Battery Life and Engine Life system - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [HELP]Battery Life and Engine Life system (/showthread.php?tid=513637)



[HELP]Battery Life and Engine Life system - Mavis100 - 17.05.2014

First, if you're in any vehicle and use /mycarstats to get info of VehicleInfo[vehicleid][carBatteryL] and VehicleInfo[vehicleid][carEngineL], they are 0 before i have set them to 100

PHP Code:
public OnVehicleHealthChange(vehicleidFloat:vehicle_newhealthFloat:vehicle_oldhealth)
{
  new
      
myArray[92];
  if(
vehicle_newhealth vehicle_oldhealth)
  {
    foreach(
Playeru)
    {
      
//lasthealth = vehicle_health_loss - floatround(vehicle_newhealth);
      
if(IsPlayerInVehicle(uvehicleid) && GetPlayerState(u) == PLAYER_STATE_DRIVER)
      {
        if(
vehicle_newhealth 550 && vehicle_newhealth 649)
        {
            
format(myArraysizeof(myArray), "damage @ vehicleID:%i, newhealth:%.3f, oldhealth:%.3f, difference:%.3f, BatteryL: %d EngineL:%d"vehicleidvehicle_newhealthvehicle_oldhealth, (vehicle_oldhealth vehicle_newhealth), VehicleInfo[vehicleid][carBatteryL], VehicleInfo[vehicleid][carEngineL]);
            
SendClientMessage(u0xFFFFFFFFmyArray);
            
VehicleInfo[vehicleid][carBatteryL] -= ((vehicle_health_loss vehicle_newhealth)/125.0);
            
VehicleInfo[vehicleid][carEngineL] -= ((vehicle_health_loss vehicle_newhealth)/150.0);
        }
        else if(
vehicle_newhealth 390 && vehicle_newhealth 549)
        {
            
format(myArraysizeof(myArray), "damage @ vehicleID:%i, newhealth:%.3f, oldhealth:%.3f, difference:%.3f, BatteryL: %d EngineL:%d"vehicleidvehicle_newhealthvehicle_oldhealth, (vehicle_oldhealth vehicle_newhealth), VehicleInfo[vehicleid][carBatteryL], VehicleInfo[vehicleid][carEngineL]);
            
SendClientMessage(u0xFFFFFFFFmyArray);
              
VehicleInfo[vehicleid][carBatteryL] -= ((vehicle_health_loss vehicle_newhealth)/100.0);
               
VehicleInfo[vehicleid][carEngineL] -= ((vehicle_health_loss vehicle_newhealth)/125.0);
        }
        else if(
vehicle_newhealth 250 && vehicle_newhealth 389)
        {
            
format(myArraysizeof(myArray), "damage @ vehicleID:%i, newhealth:%.3f, oldhealth:%.3f, difference:%.3f, BatteryL: %d EngineL:%d"vehicleidvehicle_newhealthvehicle_oldhealth, (vehicle_oldhealth vehicle_newhealth), VehicleInfo[vehicleid][carBatteryL], VehicleInfo[vehicleid][carEngineL]);
            
SendClientMessage(u0xFFFFFFFFmyArray);
            
VehicleInfo[vehicleid][carBatteryL] -= ((vehicle_health_loss vehicle_newhealth)/75.0);
            
VehicleInfo[vehicleid][carEngineL] -= ((vehicle_health_loss vehicle_newhealth)/100.0);
            
VehicleInfo[vehicleid][carBroken] = 1;
        }
        break;
      }
    }
  }
  return 
true;




Re: [HELP]Battery Life and Engine Life system - Dziugsas - 17.05.2014

Try to set the random values when gamemode is connected or when the car is spawned for example:

Code:
public OnGameModeInit()
{
	for(new i;i < MAX_VEHICLEs;i++)
	{
		VehicleInfo[vehicleid][BatteryLife] = random(500);
		VehicleInfo[vehicleid][EngineLife] = random(500);
	}
	return 1;
}