25% Chance to Headshot
#1

That's something that I added on OnPlayerTakeDamage, I want a headshot to be succesful with a sniper but with any other weapon it must have a 25% to success or else it will miss the shot, but it seems that one shot with a weapon kills the player.

Код:
new rando;
	if(bodypart == BODY_PART_HEAD)
	{
	    if(weaponid == 34)
	    {
		   	SetPlayerHealth(playerid, 0);
	    }
	   	else
	   	{
			rando = random(3);
			switch(rando)
			{
			    case 0, 1, 2:
				{
					return 0;
				}
			    case 4:
				{
					SetPlayerHealth(playerid, 0);
			    }
			}
		}
	}
	if(bodypart == BODY_PART_RIGHT_ARM)
	{
	 	SetPlayerArmedWeapon(playerid, 0);
	}
Reply
#2

This code is okey. Then where is the problem?
Reply
#3

random(3) can be 0,1,2 (three options)
You need to use random(4), which can be 0,1,2,3 (four options)

Also, fixed your code.

PHP код:
if(bodypart == BODY_PART_HEAD)
{
    if(
weaponid == 34)
    {
        
rando random(4);
        switch(
rando)
        {
            case 
012:
            {
                return 
0;
            }
            case 
3:
            {
                
SetPlayerHealth(playerid0);
            }
        }
    }

Reply
#4

Quote:
Originally Posted by Sellize
Посмотреть сообщение
random(3) can be 0,1,2 (three options)
You need to use random(4), which can be 0,1,2,3 (four options)

Also, fixed your code.

PHP код:
if(bodypart == BODY_PART_HEAD)
{
    if(
weaponid == 34)
    {
        
rando random(4);
        switch(
rando)
        {
            case 
012:
            {
                return 
0;
            }
            case 
3:
            {
                
SetPlayerHealth(playerid0);
            }
        }
    }

Thank you very much, here's your reputation.
Reply
#5

Why are you returning 0, just simplify it:
pawn Код:
if(bodypart == BODY_PART_HEAD && weaponid == 34)
{
    new chance = random(4);
    if(chance == 3) SetPlayerHealth(playerid, 0);
}
Reply
#6

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
Why are you returning 0, just simplify it:
pawn Код:
if(bodypart == BODY_PART_HEAD && weaponid == 34)
{
    new chance = random(4);
    if(chance == 3) SetPlayerHealth(playerid, 0);
}
I just want it to not deal any damage because he missed the shot, with a sniper it will deal 100% damage
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)