Onplayetgetshoot
#1

Hello, I am making a system by which if ill hit a bullet of M4 to someone then he/ she will loose 50% of his HP/ armo.
How can I do it with this function?

Код:
public OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid)
{
    new string[128], victim[MAX_PLAYER_NAME], attacker[MAX_PLAYER_NAME];
    new weaponname[24];
    GetPlayerName(playerid, attacker, sizeof (attacker));
    GetPlayerName(damagedid, victim, sizeof (victim));
 
    GetWeaponName(weaponid, weaponname, sizeof (weaponname));
    format(string, sizeof(string), "%s has made %.0f damage to %s, weapon: %s", attacker, amount, victim, weaponname);
    SendClientMessageToAll(0xFFFFFFFF, string);
    return 1;
}
Thank you
Reply
#2

OnPlayerGiveDamage is when you shoot the player on your screen you probably want OnPlayerTakeDamage.
Reply
#3

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
OnPlayerGiveDamage is when you shoot the player on your screen you probably want OnPlayerTakeDamage.
To extend on Pottus' point, you'll want to check if the weaponID is equal to that of an M4, and then use SetPlayerHealth to change the health of the player hit by a fraction of the total amount.
Reply
#4

Sorry, I didn't get you properly..
Reply
#5

Also keep in mind you can't set weapon damage less than the maximum damage of that weapon because the player would already be dead!
Reply
#6

pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    if(issuerid != INVALID_PLAYER_ID)
    {
        if(weaponid == 31)
        {
            new Float:health;
            GetPlayerHealth(playerid, health);
            SetPlayerHealht(playerid, health - 50);
         }
     }
return 1;
}
This is the basic code.
You need to modify it to add armour loss, checking if the health doesn't go beyond 0, and all that!
Reply
#7

Quote:
Originally Posted by Rajat_Pawar
Посмотреть сообщение
pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    if(issuerid != INVALID_PLAYER_ID)
    {
        if(weaponid == 31)
        {
            new Float:health;
            GetPlayerHealth(playerid, health);
            SetPlayerHealht(playerid, health - 50);
         }
     }
return 1;
}
This is the basic code.
You need to modify it to add armour loss, checking if the health doesn't go beyond 0, and all that!
He wants their health to decrease by 50%, not 50. It doesn't make much sense considering theoretically the player would never die, but mine as well give him what he asked for.

Instead of subtracting 50, you would divide the current player's health by 2.
Reply
#8

Don't forget to set all players to the same team to eliminate default weapon damage!
Reply
#9

Quote:
Originally Posted by king_hual
Посмотреть сообщение
Don't forget to set all players to the same team to eliminate default weapon damage!
What are you smoking ? He's using OnPlayerTakeDamage(), OnPlayerGiveDamage() was definitely a mistake on his part.

@RVRP That would only work if he has 11hp or more. Your right in theory he would never die but in practice he will die at 10hp or less no matter what.
Reply
#10

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
What are you smoking ? He's using OnPlayerTakeDamage(), OnPlayerGiveDamage() was definitely a mistake on his part.
It does not matter the slightest bit. If they don't set the players to the same team, both the damage he would like AND the default damage would be taken, and that messes things up. In other words, setting the players to the same team means much more control over damage. There are plenty of tutorials on that. Also, I don't smoke.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)