[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
#2

Nice thanks, Rep+
i'm working on Gangwars GM and that will help me for sure ^_^
Reply
#3

Oops, I forgot :
pawn Code:
SetTimerEx("DamagedHP", 1500, false, "i", playerid); // create a timer to display the DAMAGE ICONS.
SetTimerEx("DamagedAP", 1500, false, "i", playerid);  // create a timer to display the DAMAGE ICONS.
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.
}
Reply
#4

very good
Reply
#5

The damage icons are pretty cool.
I'll use them on my server.
Reply
#6

Man (Y) thats awesome
Reply
#7

why HP-0 though?
Reply
#8

Hello Kar,

so with this smart script you can "personalize" your WeaponDamage, so I've tryed to to GetPlayerHealth, and when he take a damage from any weapons he will receive -0dmg(if they are in the same team). So, It's will don't increase players health/armour.

pawn Code:
new Float:HP;
GetPlayerHealth(playerid, HP); // We get his HP.
if(GetPlayerWeapon(issuerid)) SetPlayerHealth(playerid, HP-0);
But, I don't know if I do a mistake, I would simply simply use :
pawn Code:
SetPlayerHealth(playerid, HP);
Reply
#9

Nice tutorial, certainly explained me how to use this.
Reply
#10

Thanks you !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)