[Tutorial] Simple Realistic Damage Values
#1

Introduction
This short and sweet tutorial was designed for the beginner scripter. By the end of this tutorial you should be able to easily edit the damage values of any weapon on your server, using the basics of Pawno, no filterscripts, no extra includes, nothing! I will explain everything as thoroughly as I feel it needs to be. If you feel that there is an aspect that needs expanding on, please post here, and I will do so.

References
During this tutorial we will use all of the below functions and callbacks at one point or another, so it would behoove you to familiarize yourself with them before continuing on.
https://sampwiki.blast.hk/wiki/OnPlayerTakeDamage
https://sampwiki.blast.hk/wiki/GetPlayerHealth
https://sampwiki.blast.hk/wiki/SetPlayerHealth

OnPlayerTakeDamage
I will give a quick rundown of this callback and it's parameters now. It is called once the server detects a player receiving damage from a second player. It has four parameters.
Код:
(playerid, issuerid, Float:amount, weaponid)
playerid The player that took damage.
issuerid The player that caused the damage.
amount The amount of health/armor playerid has lost.
weaponid The weapon that caused the damage.


Modifying the M4
pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    new Float:HP;
    GetPlayerHealth(playerid, HP);
    if(weaponid == 31) SetPlayerHealth(playerid, HP-25);
    return 1;
}
The script above will decrease a player's HP by 25 when fired upon by a second player wielding an M4. Allow me to go through the code line by line.

pawn Код:
new Float:HP;
This is stating to OnPlayerTakeDamage that a custom, dynamic value, entitled HP, will be used somewhere throughout the callback.

pawn Код:
GetPlayerHealth(playerid, HP);
This line is simply defining what the above Float will represent.

pawn Код:
if(weaponid == 31) SetPlayerHealth(playerid, HP-25);
Now this line is completing two things. First, it's checking if the weaponid (https://sampwiki.blast.hk/wiki/Weapons), a variable defined in the OnPlayerTakeDamage callback, is weapon 31 (An M4). If it is, it is using SetPlayerHealth to define the custom damage value. It is setting our player's health to HP, our player's current health level, subtracted by 25, or whatever other damage value you would like the M4 to omit. Remember that a player's full HP is 100, so anything equal to or above that would kill the player after one shot. This would be useful for putting in a one-shot-one-kill system on your server's sniper rifles.

Modifying multiple weapons
To edit the damage of more than one weapon is very simple. Simply add a second line and edit the Weapon ID and HP values to fit your next weapon. As an example, a semi-replica of the LS:RP damage system can be found below:
pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    new Float:HP;
    GetPlayerHealth(playerid, HP);
    if(weaponid == 24) SetPlayerHealth(playerid, HP-50);//DesertEagle
    if(weaponid == 22) SetPlayerHealth(playerid, HP-50);//Colt45
    if(weaponid == 32) SetPlayerHealth(playerid, HP-10);//Tec9
    if(weaponid == 28) SetPlayerHealth(playerid, HP-10);//Uzi
    if(weaponid == 23) SetPlayerHealth(playerid, HP-50);//SilencedColt
    if(weaponid == 31) SetPlayerHealth(playerid, HP-35);//M4
    if(weaponid == 30) SetPlayerHealth(playerid, HP-40);//AK
    if(weaponid == 29) SetPlayerHealth(playerid, HP-18);//MP5
    if(weaponid == 34) SetPlayerHealth(playerid, HP-300);//SniperRifle
    if(weaponid == 33) SetPlayerHealth(playerid, HP-35);//CuntGun
    if(weaponid == 25) SetPlayerHealth(playerid, HP-100);//PumpShotgun
    if(weaponid == 27) SetPlayerHealth(playerid, HP-70);//Spaz12
    return 1;
}
Template
If you think you've got the whole concept down, and need to get this job done fast, here is a template you may use to quickly edit your server's weapon damages. Be careful; if you have anything other than this code in your OnPlayerTakeDamage callback, I'd advise you not use this template. If you decide to, simply replace the "X" variable with your desired weapon IDs and damage values. https://sampwiki.blast.hk/wiki/Weapons
pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    new Float:HP;
    GetPlayerHealth(playerid, HP);
    if(weaponid == X) SetPlayerHealth(playerid, HP-X);
    if(weaponid == X) SetPlayerHealth(playerid, HP-X);
    if(weaponid == X) SetPlayerHealth(playerid, HP-X);
    if(weaponid == X) SetPlayerHealth(playerid, HP-X);
    if(weaponid == X) SetPlayerHealth(playerid, HP-X);
    if(weaponid == X) SetPlayerHealth(playerid, HP-X);
    if(weaponid == X) SetPlayerHealth(playerid, HP-X);
    if(weaponid == X) SetPlayerHealth(playerid, HP-X);
    if(weaponid == X) SetPlayerHealth(playerid, HP-X);
    if(weaponid == X) SetPlayerHealth(playerid, HP-X);
    if(weaponid == X) SetPlayerHealth(playerid, HP-X);
    if(weaponid == X) SetPlayerHealth(playerid, HP-X);
    return 1;
}
Good bye!
Reply
#2

Don't create a tutorial thread every one hour that will cause some spamming.

by the way 10/10 good job. Well done explain good for beginners!
Reply
#3

Using the range also would be nice.

You should also use either switch() or an array.
Reply
#4

Quote:
Originally Posted by Reklez
Посмотреть сообщение
Don't create a tutorial thread every one hour that will cause some spamming.

by the way 10/10 good job. Well done explain good for beginners!
I don't see how they're causing spam, I've only posted two tonight, thanks though!
Reply
#5

Well, they're proper tutorials, not the crap you see which is

pawn Код:
hello today i help u make a script to pawno

1st u need to open pawno XDDDDDDDDDDDDDDDD

then u need tipe ur cmd
CBA to write the rest, but you get my point.
Reply
#6

er with the on player take-damage callback wont the damage given to the player be the added to the health you are removing as it is called after the damage is given.
Reply
#7

Quote:
Originally Posted by AceFlyer
Посмотреть сообщение
er with the on player take-damage callback wont the damage given to the player be the added to the health you are removing as it is called after the damage is given.
I don't completely understand what you're stating/asking, but this system works as it is designed to. I personally use edits similar to the examples above myself.
Reply
#8

i wanted to know whether the original damage given by the gun will be given to the player in addition to the health the script takes away from the player through.
- ps: Sorry if i cant be understood cant think of a better way to rephrase it
Код:
if(weaponid == 31) SetPlayerHealth(playerid, HP-25);
Reply
#9

Well then yes, the two damage values will stack. The only workaround I can think of is to edit your own values with the original damages in mind so that the sum of the two is what you want. Would just take a bit of thinking.

For the example I posted, here are the sums.
Reply
#10

Would this work ?
Anyway nice tutorial its very useful in my game-mode thanks!
pawn Code:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    new Float:HP;
   
    GetPlayerHealth(playerid, HP);
    if(weaponid == 31) SetPlayerHealth(playerid, HP+amount-25);
    return 1;
}
Reply
#11

Quote:
Originally Posted by AceFlyer
View Post
Would this work ?
Anyway nice tutorial its very useful in my game-mode thanks!
pawn Code:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    new Float:HP;
   
    GetPlayerHealth(playerid, HP);
    if(weaponid == 31) SetPlayerHealth(playerid, HP+amount-25);
    return 1;
}
Actually, I think that just might do it!
Reply
#12

Well, you also need to take in to account armour.
Reply
#13

pawn Code:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    new Float:HP,Float:A;
    GetPlayerHealth(playerid, HP);
    GetPlayerArmour(playerid,A);
    if(A > 0.0)
    {
        if(weaponid == 31) SetPlayerArmour(playerid, A+amount-25);
        if(weaponid == 30) SetPlayerArmour(playerid, A+amount-26);
        if(weaponid == 34) SetPlayerArmour(playerid, A+amount-90);
        if(weaponid == 29) SetPlayerArmour(playerid, A+amount-20);
        if(weaponid == 24) SetPlayerArmour(playerid, A+amount-50);
        if(weaponid == 4) SetPlayerArmour(playerid, A+amount-60);
        if(weaponid == 26) SetPlayerArmour(playerid, A+amount-30);
        if(weaponid == 32) SetPlayerArmour(playerid, A+amount-20);
    }
    else
    {
        if(weaponid == 31) SetPlayerHealth(playerid, HP+amount-25);
        if(weaponid == 30) SetPlayerHealth(playerid, HP+amount-26);
        if(weaponid == 34) SetPlayerHealth(playerid, HP+amount-90);
        if(weaponid == 29) SetPlayerHealth(playerid, HP+amount-20);
        if(weaponid == 24) SetPlayerHealth(playerid, HP+amount-50);
        if(weaponid == 4) SetPlayerHealth(playerid, HP+amount-60);
        if(weaponid == 26) SetPlayerHealth(playerid, HP+amount-30);
        if(weaponid == 32) SetPlayerHealth(playerid, HP+amount-20);
    }
    return 1;
}
im not sure whether that would work though.
Reply
#14

Why not use switch() ? It's faster than if statement.
Reply
#15

What if their armour is 1? They'll only lose 1 armour, and no health.
Reply
#16

Nice man, very well explained!
Reply
#17

Quote:
Originally Posted by AceFlyer
View Post
pawn Code:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    new Float:HP,Float:A;
    GetPlayerHealth(playerid, HP);
    GetPlayerArmour(playerid,A);
    if(A > 0.0)
    {
        if(weaponid == 31) SetPlayerArmour(playerid, A+amount-25);
        if(weaponid == 30) SetPlayerArmour(playerid, A+amount-26);
        if(weaponid == 34) SetPlayerArmour(playerid, A+amount-90);
        if(weaponid == 29) SetPlayerArmour(playerid, A+amount-20);
        if(weaponid == 24) SetPlayerArmour(playerid, A+amount-50);
        if(weaponid == 4) SetPlayerArmour(playerid, A+amount-60);
        if(weaponid == 26) SetPlayerArmour(playerid, A+amount-30);
        if(weaponid == 32) SetPlayerArmour(playerid, A+amount-20);
    }
    else
    {
        if(weaponid == 31) SetPlayerHealth(playerid, HP+amount-25);
        if(weaponid == 30) SetPlayerHealth(playerid, HP+amount-26);
        if(weaponid == 34) SetPlayerHealth(playerid, HP+amount-90);
        if(weaponid == 29) SetPlayerHealth(playerid, HP+amount-20);
        if(weaponid == 24) SetPlayerHealth(playerid, HP+amount-50);
        if(weaponid == 4) SetPlayerHealth(playerid, HP+amount-60);
        if(weaponid == 26) SetPlayerHealth(playerid, HP+amount-30);
        if(weaponid == 32) SetPlayerHealth(playerid, HP+amount-20);
    }
    return 1;
}
im not sure whether that would work though.
Guess this will not work, when player's will have more then 0 armour and you shoot him he will lost armour BUT, after another shot armour will be increased to 100. That's what I think.
Reply
#18

Awesome & Useful Tutorial ^^ 10/10
Reply
#19

Excellent tutorial.
Reply
#20

Alternatively, you could do:

pawn Code:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    new Float:HP;
    GetPlayerHealth(playerid, HP);
    SetPlayerHealth( playerid, HP + amount );
   
    switch( weaponid )
    {
         case 31: SetPlayerHealth( playerid, HP - 25.0 );
         // Et Cetera.
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)