18.06.2009, 21:10
Hi, i wanted to know the following, is it possible to check the difference between the old carhealth, and the new carhealt, like when you crash? Can someone explain that to me?
forward CarHealthTimer();
public CarHealthTimer()
{
for (new i=0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i) && IsPlayerInAnyVehicle(i))
{
new Float:current[MAX_PLAYERS];
GetVehicleHealth(GetPlayerVehicleID(i),current[i]);
if(current[i] < oldhealth[i]) { // action
}
// then you overwrite your old health..
oldhealth[i] = current[i];
}
}
}
Originally Posted by RemiX
And where do i define the oldhealth? :P

new oldhealth[MAX_PLAYERS];
forward CarHealthTimer();
forward OnPlayerVehicleHealthChange(playerid, vehicleid, Float:oldhealth, Float:newhealth);
public OnGameModeInit()
{
SetTimer("CarHealthTimer", 1000, true);
return 1;
}
public CarHealthTimer()
{
for (new i=0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i) && IsPlayerInAnyVehicle(i))
{
new Float:current;
new vehicleid = GetPlayerVehicleID(i);
GetVehicleHealth(vehicleid, current);
if(current != oldhealth[i])
{
OnPlayerVehicleHealthChange(i, vehicleid, oldhealth[i], current);
}
oldhealth[i] = current;
}
}
return 1;
}
public OnPlayerVehicleHealthChange(playerid, vehicleid, Float:oldhealth, Float:newhealth)
{
// Do something
return 1;
}