SA-MP Forums Archive
25% Chance to Headshot - 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)
+--- Thread: 25% Chance to Headshot (/showthread.php?tid=575993)



25% Chance to Headshot - dionisak0s - 31.05.2015

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);
	}



Re: 25% Chance to Headshot - SoFahim - 31.05.2015

This code is okey. Then where is the problem?


Re: 25% Chance to Headshot - Sellize - 31.05.2015

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);
            }
        }
    }




Re: 25% Chance to Headshot - dionisak0s - 31.05.2015

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.


Re: 25% Chance to Headshot - SickAttack - 31.05.2015

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);
}



Re: 25% Chance to Headshot - dionisak0s - 04.06.2015

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