[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


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)