SA-MP Forums Archive
Headshot Problem - 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: Headshot Problem (/showthread.php?tid=613976)



Headshot Problem - HassanShah - 03.08.2016

Hey....
My friend gave me a server but in the server you can headshot with any weapon but I want to change it to only sniper headshot... how can I edit it??


Код:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart) {
    if ((GetPlayerTeam(playerid) == NO_TEAM && GetPlayerTeam(issuerid) == NO_TEAM) || GetPlayerTeam(issuerid) != GetPlayerTeam(playerid)) {
	    if (bodypart == 9 && ! g_Player[playerid][playerHelmet]) {
	        SetPlayerHealth(playerid, 0.0);

			SendClientMessage(issuerid, COLOR_ORANGE, "Good job gangsta! You made a perfect headshot over that nigga! [+$3000 +1 Score]");
			GivePlayerMoney(issuerid, 3000);
			SetPlayerScore(issuerid, GetPlayerScore(issuerid) + 1);
			
	        return 0;
		}
	}
	return 1;
}
I need only sniper headshot and please how can I make that headshot meter too somethin' like textdraw...


Re: Headshot Problem - AndySedeyn - 03.08.2016

Add a check to see with which weapon the player fired:

PHP код:
if(weaponid == 34) {
    
// code

You'll have to create the textdraw yourself. ******: "SAMP textdraws", and the wiki page plus tons of tutorials should pop up.


Re: Headshot Problem - HassanShah - 03.08.2016

hmmm... any further information didn't understand what you said


Re: Headshot Problem - AndySedeyn - 03.08.2016

Sure. The callback you're using has a parameter called 'weaponid'. It holds the ID of the weapon that is used to damage the player. You can use that parameter to see if it is a sniper that damaged the player or not.

Weapon ids: https://sampwiki.blast.hk/wiki/Weapons
The OnPlayerTakeDamage callback: https://sampwiki.blast.hk/wiki/OnPlayerTakeDamage
Bodyparts: https://sampwiki.blast.hk/wiki/Body_Parts

Your code with that check:
PHP код:
public OnPlayerTakeDamage(playeridissueridFloat:amountweaponidbodypart) {
    if ((
GetPlayerTeam(playerid) == NO_TEAM && GetPlayerTeam(issuerid) == NO_TEAM) || GetPlayerTeam(issuerid) != GetPlayerTeam(playerid)) {
        if (
bodypart == && ! g_Player[playerid][playerHelmet] && weaponid == 34) {
            
SetPlayerHealth(playerid0.0);
            
SendClientMessage(issueridCOLOR_ORANGE"Good job gangsta! You made a perfect headshot over that nigga! [+$3000 +1 Score]");
            
GivePlayerMoney(issuerid3000);
            
SetPlayerScore(issueridGetPlayerScore(issuerid) + 1);
            
            return 
0;
        }
    }
    return 
1;

I added the following:
PHP код:
if (bodypart == && ! g_Player[playerid][playerHelmet] && weaponid == 34)
// I added '&& weaponid == 34' 
Translation of the code:
Код:
IF bodypart equals 9 AND the player isn't wearing a helmet AND the weapon used to damage him is a sniper rifle: instant kill the player



Re: Headshot Problem - HassanShah - 03.08.2016

ok thank you so much