Headshot not working!
#1

Код:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{
    if(issuerid != INVALID_PLAYER_ID && weaponid == 34 && bodypart == 9)
    {
    SetPlayerHealth(playerid, 0);
    GameTextForPlayer(issuerid,"~r~Headshot",2000,3) && GameTextForPlayer(playerid,"~r~Headshot",2000,3);
    PlayerPlaySound(playerid, 17802, 0.0, 0.0, 0.0)  && PlayerPlaySound(issuerid, 17802, 0.0, 0.0, 0.0);
    }
I added this headshot code into my server but while playing in game, whenever i hit on someones head, it doesnt work :/ and ordinary health is lost by the player!
Reply
#2

Hi friend

Your script is good but can you show me full OnPlayerTakeDamage code by which i can understand more and help you like sometimes it caused by return values, So.

TY
Reply
#3

Sure
Код:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{
    if(issuerid != INVALID_PLAYER_ID && weaponid == 34 && bodypart == 9)
    {
    SetPlayerHealth(playerid, 0);
    GameTextForPlayer(issuerid,"~r~Headshot",2000,3) && GameTextForPlayer(playerid,"~r~Headshot",2000,3);
    PlayerPlaySound(playerid, 17802, 0.0, 0.0, 0.0)  && PlayerPlaySound(issuerid, 17802, 0.0, 0.0, 0.0);
    }
    if(issuerid != INVALID_PLAYER_ID && playerData[issuerid][isInDM])
    {
        return 0;
	}
	
	if(issuerid != INVALID_PLAYER_ID && playerData[issuerid][isInCVR])
    {
        return 0;
	}
	if(issuerid != INVALID_PLAYER_ID && playerData[issuerid][isinFREEFORALL])
    {
        return 0;
	}

    if(issuerid != INVALID_PLAYER_ID && playerData[issuerid][isInEvent])
    {
        return 0;
	}
	
	if(issuerid != INVALID_PLAYER_ID && playerData[issuerid][isInDuel])
    {
        return 0;
	}

	if (playerData[playerid][isInDM])
	{
 		return 0;
 	}
 	
 	if (playerData[playerid][isInCVR])
	{
 		return 0;
 	}
 	if (playerData[playerid][isinFREEFORALL])
	{
 		return 0;
 	}

 	if (playerData[playerid][isInEvent])
	{
 		return 0;
 	}
 	
 	if (playerData[playerid][isInDuel])
	{
 		return 0;
 	}

    if(issuerid != INVALID_PLAYER_ID)
    {
		if(playerData[issuerid][playerHitmarker])
		{
			new string[128];

			format(string, sizeof(string), "%0.2f damage", amount);
			PlayerTextDrawSetString(issuerid, playerData[issuerid][playerHitmarkerTD], string);
			SetTimerEx("hideHitmarkerTD", 2000, false, "i", issuerid);
			PlayerPlaySound(issuerid, 17802, 0.0, 0.0, 0.0);
		}

		if(playerData[issuerid][playerClass] == CLASS_CIVILIAN || playerData[issuerid][playerClass] == CLASS_FIREFIGHTER || playerData[issuerid][playerClass] == CLASS_MEDIC)
		{
			if(playerData[playerid][playerClass] == CLASS_ARMY || playerData[playerid][playerClass] == CLASS_POLICE || playerData[playerid][playerClass] == CLASS_CIA || playerData[playerid][playerClass] == CLASS_FBI || playerData[playerid][playerClass] == CLASS_SECRETSERVICE)
			{
				if(playerData[issuerid][playerWantedLevel] == 0)
				{
					if(playerData[playerid][playerJailTime] <= 0)
					{
						givePlayerWanted(issuerid, 6);
						sendWantedMessage(issuerid, 6);
						newPlayerColour(issuerid);
					}
				}
			}
		}
		else if(playerData[issuerid][playerClass] == CLASS_POLICE || playerData[issuerid][playerClass] == CLASS_ARMY || playerData[issuerid][playerClass] == CLASS_CIA  || playerData[issuerid][playerClass] == CLASS_FBI || playerData[issuerid][playerClass] == CLASS_SECRETSERVICE)
		{
		    if(playerData[playerid][playerClass] == CLASS_CIVILIAN || playerData[playerid][playerClass] == CLASS_FIREFIGHTER || playerData[playerid][playerClass] == CLASS_MEDIC)
		    {
		        if (playerData[playerid][playerWantedLevel] == 0)
		        {
					new Float:theirHealth;
	            	GetPlayerHealth(playerid, theirHealth);
	            	SetPlayerHealth(playerid, theirHealth - 0);
				}
		    }
		}
		else if (playerData[issuerid][playerAdminDuty])
		{
		    GameTextForPlayer(issuerid, "You're AoD! Do not harm players!", 3000, 4);
		}
	}

    return 1;
}
Reply
#4

PHP код:
if(issuerid != INVALID_PLAYER_ID && playerData[issuerid][isInDM])
    {
        return 
0;
    }
    if(
issuerid != INVALID_PLAYER_ID && playerData[issuerid][isInCVR])
    {
        return 
0;
    }
    if(
issuerid != INVALID_PLAYER_ID && playerData[issuerid][isinFREEFORALL])
    {
        return 
0;
    }
    if(
issuerid != INVALID_PLAYER_ID && playerData[issuerid][isInEvent])
    {
        return 
0;
    }
    if(
issuerid != INVALID_PLAYER_ID && playerData[issuerid][isInDuel])
    {
        return 
0;
    }
    if (
playerData[playerid][isInDM])
    {
         return 
0;
     }
     if (
playerData[playerid][isInCVR])
    {
         return 
0;
     }
     if (
playerData[playerid][isinFREEFORALL])
    {
         return 
0;
     }
     if (
playerData[playerid][isInEvent])
    {
         return 
0;
     }
     if (
playerData[playerid][isInDuel])
    {
         return 
0;
     } 
This cause OnPlayerTakeDamage not work in other scripts return 1 instead

my only guess is that you also use OnPlayerTakeDamage in other scripts and return there 0 too change it to 1!
Reply
#5

Kindly explain pls! I dont get it what you was trying to say!
Reply
#6

He wanted to say that by using return 0; that callback also function in other scripts.
Reply
#7

I haven't returned anything in Headshot! Should i return?
Код:
    if(issuerid != INVALID_PLAYER_ID && weaponid == 34 && bodypart == 9)
    {
    SetPlayerHealth(playerid, 0);
    GameTextForPlayer(issuerid,"~r~Headshot",2000,3) && GameTextForPlayer(playerid,"~r~Headshot",2000,3);
    PlayerPlaySound(playerid, 17802, 0.0, 0.0, 0.0)  && PlayerPlaySound(issuerid, 17802, 0.0, 0.0, 0.0);
    }
Reply
#8

if you use 2 script or even more and all of them use onplayertake damage

and u do like this for example

BAD:

PHP код:
public OnPlayerTakeDamage(playeridissueridFloat:amountweaponidbodypart)
{
    if(
IsPlayerNPC(playerid)) return 0;

return 0 will block OnPlayerTakeDamage for other scripts so it will only work in the first script

GOOD:

PHP код:
public OnPlayerTakeDamage(playeridissueridFloat:amountweaponidbodypart)
{
    if(
IsPlayerNPC(playerid)) return 1;

return 1 will allow OnPlayerTakeDamage to be called in other filterscripts

EDIT

@TadePoleMG hehe sorry my bad

FIXED!
Reply
#9

oh GOD

PHP код:
public OnPlayerTakeDamage(OnPlayerTakeDamage(playeridissueridFloat:amountweaponidbodypart
What is this?
Reply
#10

np Bro
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)