[Tutorial] Simple Realistic Damage Values
#21

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;
}
Reply
#22

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;
Reply
#23

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

Wouldn't returning 0 work?
Reply
#25

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

Awww Awesome tutorial 11/10 Thank You!
Reply
#27

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

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.
Reply
#29

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.
Reply
#30

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
Reply
#31

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?
Reply
#32

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;
}
Reply
#33

Good tutorial,nice work man!
Reply
#34

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; 
Reply
#35

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

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
Reply
#37

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.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)