[Tutorial] Custom Damaging(with bodyparts) && Forbidding Weapons(0.3z)
#1

Custom Damaging(with bodyparts)


I wanted to explain how you could do custom damaging for specific Body-Parts with the new 0.3z update.

What you'll need:
**Some Scripting Knowledge**
**The 0.3z Pawno Package**

We'll start by setting everything up:

Код:
#include a_samp

#define WEAPON_BODY_PART_CHEST 3
#define WEAPON_BODY_PART_CROTCH 4
#define WEAPON_BODY_PART_LEFT_ARM 5
#define WEAPON_BODY_PART_RIGHT_ARM 6
#define WEAPON_BODY_PART_LEFT_LEG 7
#define WEAPON_BODY_PART_RIGHT_LEG 8
#define WEAPON_BODY_PART_HEAD 9
We'll have to define our body-part ID's, which we can easily use/refer back to. The Number inidicates the bodypart ID.

Then, we can either use OnPlayerTakeDamage, or OnPlayerGiveDamage. We'll use OnPlayerTakeDamage for this tutorial. Playerid will represent the player taking the damage, whilst the issuserID will be the person issuing the damage to the playerid. The "amount" float will be representing the amount of health playerid has lost.
The weaponID will be representing the weaponID used by the issuerid. Finally, the bodypart will represent which body-part was shot at, using our defines shown above.

This is what it will look like:

Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
    return 1;
}
Now, we will want to make sure both players are connected, to prevent any bugs. We will use IsPlayerConnected, by doing the following:

Код:
if(!IsPlayerConnected(playerid)) return 0;
if(!IsPlayerConnected(issuerid)) return 0;
So, now for the first example we'll use a one-shot sniper kill. But it will only do this if issuerid shoots the playerid in the head which is bodypart ID 9.

Код:
  if(issuerid != INVALID_PLAYER_ID && weaponid == 34 && bodypart == 9)
    {
        SetPlayerHealth(playerid, 0.0);
    }
Now, you can just replace the WeaponID with the weaponID you want. You can find the WeaponID'S by clicking here. You can adjust the bodypart thats shot by changing the bodypart. You can refer to the ID's by looking at the defines.

If you want to forbid/ban players using certain weapons such as RPG'S and mini-guns you can use the code found below:

if(issuerid != INVALID_PLAYER_ID && weaponid == 38 )
{
Ban(issuerid);
}

Obviously, replacing the WeaponID with the one you want to forbid. The final code is shown below.

Код:
#include a_samp

#define WEAPON_BODY_PART_CHEST 3
#define WEAPON_BODY_PART_CROTCH 4
#define WEAPON_BODY_PART_LEFT_ARM 5
#define WEAPON_BODY_PART_RIGHT_ARM 6
#define WEAPON_BODY_PART_LEFT_LEG 7
#define WEAPON_BODY_PART_RIGHT_LEG 8
#define WEAPON_BODY_PART_HEAD 9

public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
     if(!IsPlayerConnected(playerid)) return 0;
     if(!IsPlayerConnected(issuerid)) return 0;
     if(issuerid != INVALID_PLAYER_ID && weaponid == 34 && bodypart == 9)
     {
        SetPlayerHealth(playerid, 0.0);
     }
     if(issuerid != INVALID_PLAYER_ID && weaponid == 38)
     {
        Ban(issuerid);
     }
    return 1;
}
Lastly, if you get the "error 025: function heading differs from prototype" error it means you have the 0.3x pawno compiler or an even older version, and need to get the new 0.3z package from sa-mp.com/downloads.

Resources:
WeaponID'S: https://sampwiki.blast.hk/wiki/Weapons
OnPlayerTakeDamage: https://sampwiki.blast.hk/wiki/OnPlayerTakeDamage

I hope this helped you understand this, and if you have any questions at all either PM me or reply here below.

EDIT: I realize there are several grammar mistakes throughout, I'll edit / re-do the tutorial when I have time.
Reply
#2

I would not call this custom damage, as it only kills a player if one bodypart is hit. It can be much more extensive.
Reply
#3

Quote:
Originally Posted by Scaleta
Посмотреть сообщение
I would not call this custom damage, as it only kills a player if one bodypart is hit. It can be much more extensive.
That's easy to do, though! Especially with what he's already shown us.

Thank you evan!

Код:
     if(issuerid != INVALID_PLAYER_ID && weaponid == 34 && bodypart == 7)
     {
        new Float:phealth;
        GetPlayerHealth(playerid, phealth);
        //if you shoot him in the leg, it should only take like 5 damage...
        // I believe by default the sniper takes like 30, I'm not sure. But if it takes 30 damage you could do this
        SetPlayerHealth(playerid, phealth+25);
       // This just gives the player 25 health when he's shot with a sniper.
       // Keep in mind the sniper took some health, so giving him 25 back won't mean he can't be killed. Just takes more shots in the leg.
     }
Reply
#4

thanks for this tut i can make a headshotsystem simply now and also make my weps hit custom damge for some class alm though i know a different method to make custom damge but this way looks alot more simple
Reply
#5

Very nice tutorial man!
Reply
#6

Quote:
Originally Posted by Unfriendly
Посмотреть сообщение
That's easy to do, though! Especially with what he's already shown us.

Thank you evan!

Код:
     if(issuerid != INVALID_PLAYER_ID && weaponid == 34 && bodypart == 7)
     {
        new Float:phealth;
        GetPlayerHealth(playerid, phealth);
        //if you shoot him in the leg, it should only take like 5 damage...
        // I believe by default the sniper takes like 30, I'm not sure. But if it takes 30 damage you could do this
        SetPlayerHealth(playerid, phealth+25);
       // This just gives the player 25 health when he's shot with a sniper.
       // Keep in mind the sniper took some health, so giving him 25 back won't mean he can't be killed. Just takes more shots in the leg.
     }
By default, sniper rifle takes 42 HP. So you'd need to make allowances. Also, if someone was to shoot you in the leg with a sniper, do you think you would still be moving?
Reply
#7

Useful tutorial, Thanks Evan!
Reply
#8

Quote:
Originally Posted by Abagail
Посмотреть сообщение
Now, we will want to make sure both players are connected, to prevent any bugs. We will use IsPlayerConnected, by doing the following:

Код:
if(!IsPlayerConnected(playerid)) return 0;
if(!IsPlayerConnected(issuerid)) return 0;
Of course they're connected... The callback wouldn't be being called if they weren't. This is like using IsPlayerConnected under OnPlayerConnect.

Also you should really use [ pawn] tags not [ code ].
Reply
#9

Useful tutorial
Reply
#10

@MP2, It was just a "goof" check as sometimes there's hack methods of doing stuff... Just making me sure everythings legit is all. I plan on adding more to this tutorial.
Reply
#11

Nice.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)