[Tutorial] OnPlayerTakeDamage(..)
#1

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;
}
I - Damage Icons :

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.
}
Well, It's was simple I hope you will like it. And sorry for the bad english.
Reply


Messages In This Thread
OnPlayerTakeDamage(..) - by Matnix - 05.09.2013, 18:34
Re: OnPlayerTakeDamage(..) - by hossa - 05.09.2013, 18:46
Re : OnPlayerTakeDamage(..) - by Matnix - 05.09.2013, 19:12
Re: OnPlayerTakeDamage(..) - by P1c4550 - 06.09.2013, 08:08
Re: OnPlayerTakeDamage(..) - by AaronKillz - 06.09.2013, 08:11
Re: OnPlayerTakeDamage(..) - by Omar55555 - 10.09.2013, 12:27
Re: OnPlayerTakeDamage(..) - by Kar - 10.09.2013, 23:02
Re : OnPlayerTakeDamage(..) - by Matnix - 10.09.2013, 23:09
Re: OnPlayerTakeDamage(..) - by DanishHaq - 10.09.2013, 23:22
Re : OnPlayerTakeDamage(..) - by Matnix - 28.09.2013, 20:18

Forum Jump:


Users browsing this thread: 1 Guest(s)