SA-MP Forums Archive
[Tutorial] Simple Realistic Damage Values - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Simple Realistic Damage Values (/showthread.php?tid=330005)

Pages: 1 2


Re: Simple Realistic Damage Values - [ABK]Antonio - 02.04.2012

I would do something along the lines of this.

pawn Code:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid)
{
    new Float:stat[2];
    GetPlayerHealth(playerid, stat[0]);
    GetPlayerArmour(playerid, stat[1]);
    new Damage;
    switch(weaponid)
    {
        case 31: Damage = 25; //set the damage here for when this switch is over
    }
    if(stat[1] > Damage) SetPlayerArmour(playerid, stat[1]-Damage);
    else if(stat[1] == Damage) SetPlayerArmour(playerid, 0);
    else if(stat[1] < Damage && stat[1] > 0)
    {
        new subval = floatround(stat[1])-Damage;
        //takes their armor, subtracts 25 from it. Then it adds that negative number to their health
        //For instance, 15 armor -25 = -10. So we subract 10 basically.
        SetPlayerArmour(playerid, 0);
        SetPlayerHealth(playerid, stat[0]+subval);
    }
    else SetPlayerHealth(playerid, stat[0]-Damage);
    return 1;
}



Re: Simple Realistic Damage Values - rati555 - 02.04.2012

Quote:
Originally Posted by [ABK]Antonio
View Post
I would do something along the lines of this.

pawn Code:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid)
{
    new Float:stat[2];
    GetPlayerHealth(playerid, stat[0]);
    GetPlayerArmour(playerid, stat[1]);
    new Damage;
    switch(weaponid)
    {
        case 31: Damage = 25; //set the damage here for when this switch is over
    }
    if(stat[1] > Damage) SetPlayerArmour(playerid, stat[1]-Damage);
    else if(stat[1] == Damage) SetPlayerArmour(playerid, 0);
    else if(stat[1] < Damage && stat[1] > 0)
    {
        new subval = stat[1]-Damage;
        //takes their armor, subtracts 25 from it. Then it adds that negative number to their health
        //For instance, 15 armor -25 = -10. So we subract 10 basically.
        SetPlayerArmour(playerid, 0);
        SetPlayerHealth(playerid, stat[0]+subval);
    }
    else SetPlayerHealth(playerid, stat[0]-Damage);
    return 1;
}
I've got tag mismatch warning at this line
pawn Code:
new subval = stat[1]-Damage;



Re: Simple Realistic Damage Values - [ABK]Antonio - 02.04.2012

new subval = floatround(stat[1])-Damage;


Re: Simple Realistic Damage Values - DaRealShazz - 06.06.2012

Wouldn't returning 0 work?


Re: Simple Realistic Damage Values - Keelo - 18.07.2012

Hey I suck, I'm new on scripting please help me, in what .pwn should I copy this script? Plzz answer.


Re: Simple Realistic Damage Values - Coder_ - 19.07.2012

Awww Awesome tutorial 11/10 Thank You!


Re: Simple Realistic Damage Values - Coder_ - 31.07.2012

What the fuck! i use this on 3e and kill hud show i killed myself PLEASE HELP ME!


Respuesta: Simple Realistic Damage Values - Pottus - 05.08.2012

This tutorial does not address the implications of using such a system, if you guys think such a system can be implemented effectively this way think again there is a lot of elements not even shown here that are vital! One issue for instance is such a system will not work correctly if you don't kill the player when they reach less than 50hp. Why is that? Well what happens if there HP is 40 and they get shot by deagle which is 46 damage, they die but the system is configured that they take 30 HP! This kind of system really takes tons and tons of testing to get working nicely it's not as simple as the tutorial would have you believe.


Re: Simple Realistic Damage Values - KingHual - 03.10.2012

Quote:
Originally Posted by zDevon
Посмотреть сообщение
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.
OR you could use SetPlayerTeam and set everyone to the same team, to disable native damage.


Re: Simple Realistic Damage Values - Dziugsas - 09.05.2016

Quote:
Originally Posted by zDevon
View Post
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.
Shotgun damage above 100?Unless you check the range...because if player hits him in long distance it is not realistic


Re: Simple Realistic Damage Values - Manyula - 09.05.2016

I still don't quite get why I should use OnPlayerUpdate over OnPlayerTakeDamage. The latter only gets called whenever it is triggered, whereas the other is triggered on every single player update. Let's assume the same scenario Slice pointed out. How would OnPlayerUpdate work in contrast to what Slice said above about OnPlayerTakeDamage?


Re: Simple Realistic Damage Values - pWesley - 10.05.2016

The situation there only adds damage, does not change. If the damage was to change from a gun, would be as follows:

Code:
switch(weaponid)
{
	case 0: amount = 0;
	case 9: amount = 10.1;
	case 24: amount = (amount < 10 ? 5 : 32);
	case 25: amount *= 0.6;
	case 38: amount = 0;
	case 34: amount = 40.0;
}



Re: Simple Realistic Damage Values - iSpy - 14.05.2016

Good tutorial,nice work man!


Re: Simple Realistic Damage Values - TheMallard - 30.05.2016

Don't mess with floats: floats MUST end with .0. If not, compiler will call float function.
For example:

PHP Code:
new Float:health;
GetPlayerHealth(playeridhealth);
health 5// compiler: health - float(5);
health 5.0// compiler: health - 5.0; 



Re: Simple Realistic Damage Values - Markhoss - 15.07.2016

This is perfect thanks so much will try later today now I am in bed.


Re: Simple Realistic Damage Values - Sibuscus - 16.03.2017

with adding a buncha random values you could optimize this script and make it extremely realistic, like a bullet may hit your main artery or some crap, you know. Thanks for this, will definitely implement it to my own server


Re: Simple Realistic Damage Values - Dirda - 24.02.2018

Please make it works to all bodyparts and ADD prevent health damage when the opponent has armor.
I don't know why it only works to Torso.