17.06.2013, 15:09
Best way to do this is don't use OnPlayerDeath(), OnPlayerStateChange() and OnPlayerTakeDamage() can be used to detect when a player is killed then call your own death function - OnPlayerDeathEx().
This is definitely the way to go, you can still use OnPlayerDeath() to detect for fake kills but it wouldn't have any effect on the system anymore.
Here is what I have in my OnPlayerStateChange()
I won't paste the rest of the system, basically all you need to do is make your own OnPlayerTakeDamage() system to keep track of the players health and initiate the death callback.
Notice the calls to OnPlayerDeathExtended()?
The nice thing about it is it you can kill the player anywhere in the script now and form your own death callback parameters.
This is definitely the way to go, you can still use OnPlayerDeath() to detect for fake kills but it wouldn't have any effect on the system anymore.
Here is what I have in my OnPlayerStateChange()
I won't paste the rest of the system, basically all you need to do is make your own OnPlayerTakeDamage() system to keep track of the players health and initiate the death callback.
pawn Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(IsPlayerNPC(playerid)) { return 1; } // Player Is NPC Do Nothing
if(newstate == PLAYER_STATE_WASTED && !PlayerIsDead[playerid])
{
// Player was inside a vehicle when they died
if (oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
{
OnPlayerDeathExtended(playerid, MAX_PLAYERS + 12, 51);
print("1:OnPlayerDeathExtended called OnPlayerStateChange");
}
// Player died in some other way
else
{
printf("2:OnPlayerDeathExtended called OnPlayerStateChange newstate: %i oldstate: %i", newstate, oldstate);
// This if statement prevents a possible bug from false calls.
if(oldstate != PLAYER_STATE_SPAWNED) OnPlayerDeathExtended(playerid, MAX_PLAYERS + 11, 47);
}
}
return 1;
}
The nice thing about it is it you can kill the player anywhere in the script now and form your own death callback parameters.