31.03.2012, 03:11
![](http://i.imgur.com/0Tcpw.png)
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;
}