05.09.2013, 18:34
(
Last edited by Matnix; 05/09/2013 at 07:14 PM.
)
ONPLAYERTAKEDAMAGE
(playerid, issuerid, Float:amount, weaponid)
So in this tutorial, I'll show you some cool stuff you can do with this callback. As his name said, this callback is called everytime when a player takes damage. The features you will found on this tutorials are pretty simple but can help some newcomer at pawn scripting : Anti-Team-Killing - Damage icons (health, armor).I - Anti Team Killing :
pawn Code:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid)
{
if(issuerid != INVALID_PLAYER_ID) /// If not self-inflicted
{ // open
if(gTeam[issuerid] != gTeam[playerid]) // If we wasn't in the team of the guys who damage him.
{ // open
// code (not for the moment)
return 1;
}
else // If the guys who shoot him was in his teams.
{ // open
new Float:HP;
GetPlayerHealth(playerid, HP); // We get his HP.
if(GetPlayerWeapon(issuerid)) SetPlayerHealth(playerid, HP-0); // Get the weapon wich he got damaged and set the damage to 0.
GameTextForPlayer(issuerid, "~r~WATCH YOUR SHOOT", 1500, 5); // Alert him because he is actualy shooting on his team mates.
return 1;
}
}// If he have been damaged by him-self we do nothing.
return 1;
}
For that you will have to use SetPlayerAttachedObject - and I try to found any AttachedObject filterscript.
pawn Code:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid)
{
if(issuerid != INVALID_PLAYER_ID) /// If not self-inflicted
{ // open
if(gTeam[issuerid] != gTeam[playerid]) // If we wasn't in the team of the guys who damage him.
{ // open
if(GetPlayerArmour(playerid) > 0.0) // We have to get players armour to know if we show him the ARMOUR ICONS.
{// open
SetTimerEx("DamagedAP", 1500, false, "i", playerid); // create a timer to display the DAMAGE ICONS.
SetPlayerAttachedObject(playerid,1,1242,17,0.601999,-0.036000,0.011000,96.299972,79.500015,-81.599990,1.000000,1.000000,1.000000); // ARMOUR ICONS.
}// close
if(GetPlayerHealth(playerid) > 0.0) // We have to get players health to know if we show him HEALTH ICONS.
{
SetTimerEx("DamagedHP", 1500, false, "i", playerid); // create a timer to display the DAMAGE ICONS.
SetPlayerAttachedObject(playerid,2,1240,17,0.587000,-0.027000,0.028000,86.100051,79.499977,-69.599990,1.000000,1.000000,1.000000); // HEALTH ICONS.
}// close
return 1;
} // close
else // If the guys who shoot him was in his teams.
{ // open
// Anti-Team-Kill
} // close
}// If he have been damaged by him-self we do nothing.
return 1;
}
pawn Code:
forward DamagedHP(playerid);
public DamagedHP(playerid)
{
RemovePlayerAttachedObject(playerid, 2); // we remove the icons from his head after 1,5 seconds.
}
forward DamagedAP(playerid);
public DamagedAP(playerid)
{
RemovePlayerAttachedObject(playerid, 1); // we remove the icones from his head after 1,5 seconds.
}