23.01.2010, 21:52
Function And/Or Callback that detects the tiniest damage on a vehicle?
#include vhealth.inc
public OnFilterScriptInit()
{
SetTimer("VehicleHCheck", 500, 1);
}
//put this callback where you want it
public OnVehicleDamage(driverid, vehicleid)
{
.....
}
//This is in here for security, just leave as is
#if defined _vhealthcallback_Included
#endinput
#endif
#define _vhealthcallback_Included
//have a variable for all players for their cars vehicle healths.
new Float:playerVHealth[GetMaxPlayers()];
//This is your callback, put this where you want it in your filterscript
forward OnVehicleDamage(driverid, vehicleid);
forward VehicleHCheck();
public VehicleHCheck()
{
new Float:VHealth, vehicleid;
for(new playerid=0; player<GetMaxPlayers();playerid++)
{
if(GetPlayerState(playerid)!=PLAYER_STATE_DRIVER) continue;
vehicleid = GetPlayerVehicleID(playerid);
GetVehicleHealth(vehicleid, VHealth);
if(VHealth < playerVHealth[playerid])
{
OnVehicleDamage(playerid, vehicle);
}
playerVHealth[playerid] = VHealth;
}
}
/* not tested, but it should work*/
forward myTimer();
forward OnVehicleHealthChange(vehicleid, newhealth, oldhealth);
new
oldVehicleHealth[MAX_VEHICLES], newVehicleHealth[MAX_VEHICLES]; // change MAX_VEHICLES to your own vehicle amount.
Float:VehicleHealth(vehicleid)
{
new
Float:health;
GetVehicleHealth(vehicleid, health);
return health;
}
public myTimer()
{
for(new v = 1; v <= MAX_VEHICLES; v++) // change MAX_VEHICLES to your own vehicle amount or use foreach function.
{
newVehicleHealth[v] = floatround(VehicleHealth(v));
if(newVehicleHealth[v] != oldVehicleHealth[v])
{
OnVehicleHealthChange(v, newVehicleHealth[v], oldVehicleHealth[v]);
oldVehicleHealth[v] = newVehicleHealth[v];
}
}
return true;
}
public OnVehicleHealthChange(vehicleid, newhealth, oldhealth)
{
if(newhealth < oldhealth)
{
// damage..
}
return true;
}
// under OnGameModeInit/OnFilterScriptInit-callback.
SetTimer("myTimer", 1000, true); // every second.
Originally Posted by Don Correlli
pawn Code:
|
Originally Posted by Torran
Still wouldnt work for what i want it for xd
|
Originally Posted by Don Correlli
Quote:
|
Originally Posted by Don Correlli
I already gave you the correct code.
|