31.03.2012, 03:11
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 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
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.
This is stating to OnPlayerTakeDamage that a custom, dynamic value, entitled HP, will be used somewhere throughout the callback.
This line is simply defining what the above Float will represent.
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:
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
Good bye!
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)
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;
}
pawn Код:
new Float:HP;
pawn Код:
GetPlayerHealth(playerid, HP);
pawn Код:
if(weaponid == 31) SetPlayerHealth(playerid, HP-25);
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;
}
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;
}