Headshot active for everyone
#1

Hello, can someone tell me what's wrong with this command? It's supposed to activate headshot for all players but it doesn't activate anything. Thank you.

pawn Код:
new headshot[MAX_PLAYERS];
pawn Код:
//-----------------------------------HEADSHOT-----------------------------------
    if(strcmp(cmd, "/ahs", true) == 0)
    {
        new activeheadshot;
        tmp = strtok(cmdtext, idx);
        activeheadshot = strval(tmp);
        if(logged[playerid] == 0)
        {
            SendClientMessage(playerid, COLOR_BRIGHTRED, "You must be logged in to use that command.");
            return 1;
        }
        if(PlayerInfo[playerid][pAdmin] < 2)
        {
            SendClientMessage(playerid, COLOR_BRIGHTRED, "You are not an admin!");
            return 1;
        }
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /ahs [0/1]");
            return 1;
        }
        if(activeheadshot > 1 || activeheadshot < 0)
        {
            SendClientMessage(playerid, COLOR_BRIGHTRED, "You must enter 1 or 0 to activate or deactivate headshots.");
            return 1;
        }
        if(activeheadshot == 1)
        {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            headshot[i]=1;
        }
            dini_IntSet("server.ini","headshot", activeheadshot);
            SendClientMessage(playerid, COLOR_ORANGE, "You have enabled headshots for everyone.");
            GetPlayerName(playerid, sendername, sizeof(sendername));
            format(string, sizeof(string), "Admin %s enabled headshots !", sendername);
            SendClientMessageToAll(COLOR_WHITE, string);
            format(string, sizeof(string), "~w~HEADSHOT ENABLED");
            GameTextForAll(string, 5000, 3 );
            return 1;
        }
        if(activeheadshot == 0)
        {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            headshot[i]=0;
        }
            dini_IntSet("server.ini","headshot", activeheadshot);
            GetPlayerName(playerid, sendername, sizeof(sendername));
            SendClientMessage(playerid, COLOR_ORANGE, "You have disabled headshots for everyone.");
            format(string, sizeof(string), "Admin %s disabled headshots !", sendername);
            SendClientMessageToAll(COLOR_WHITE, string);
            format(string, sizeof(string), "~w~HEADSHOT DISABLED");
            GameTextForAll(string, 5000, 3);
            return 1;
        }
        return 1;
    }
pawn Код:
public OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid, bodypart)
{
    if(headshot[playerid] == 1)
    {
    if(damagedid != INVALID_PLAYER_ID && weaponid == 24 && bodypart == 9)
     {
        SetPlayerHealth(damagedid, 0.0);
     }
    if(damagedid != INVALID_PLAYER_ID && weaponid == 33 && bodypart == 9)
     {
        SetPlayerHealth(damagedid, 0.0);
     }
    if(damagedid != INVALID_PLAYER_ID && weaponid == 34 && bodypart == 9)
     {
        SetPlayerHealth(damagedid, 0.0);
     }
    }
    return 1;
}
Reply
#2

here you go :-
Код:
#include <a_samp>
#include <zcmd>
#include <sscanf>

new headshot[MAX_PLAYERS];


//-----------------------------------HEADSHOT-----------------------------------
CMD:ahs(playerid, parmas[])
{
		new activeheadshot;
		new text[128];
		if(logged[playerid] == 0) return SendClientMessage(playerid, COLOR_BRIGHTRED, "You must be logged in to use that command.");
		if(PlayerInfo[playerid][pAdmin] < 2)return SendClientMessage(playerid, COLOR_BRIGHTRED, "You are not an admin!");
		if(sscanf(parmas, "i", activeheadshot)) returnSendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /ahs [0/1]");
	    if(activeheadshot > 1 || activeheadshot < 0) return SendClientMessage(playerid, COLOR_BRIGHTRED, "You must enter 1 or 0 to activate or deactivate headshots.");
		
        for(new i = 0; i < MAX_PLAYERS; i++)
		{
		if(activeheadshot == 1)
		{

			headshot[i] = 1;

            dini_IntSet("server.ini","headshot", activeheadshot);
			SendClientMessage(playerid, COLOR_ORANGE, "You have enabled headshots for everyone.");
			GetPlayerName(playerid, sendername, sizeof(sendername));
			format(string, sizeof(string), "Admin %s enabled headshots !", sendername);
	        SendClientMessageToAll(COLOR_WHITE, string);
            format(string, sizeof(string), "~w~HEADSHOT ENABLED");
            GameTextForAll(string, 5000, 3 );
			return 1;
		}
		if(activeheadshot == 0)
		{
		    headshot[i] = 0;

            dini_IntSet("server.ini","headshot", activeheadshot);
            GetPlayerName(playerid, sendername, sizeof(sendername));
			SendClientMessage(playerid, COLOR_ORANGE, "You have disabled headshots for everyone.");
			format(string, sizeof(string), "Admin %s disabled headshots !", sendername);
	        SendClientMessageToAll(COLOR_WHITE, string);
            format(string, sizeof(string), "~w~HEADSHOT DISABLED");
            GameTextForAll(string, 5000, 3);
			return 1;
		}
	}
		return 1;
}
	
public OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid, bodypart)
{
    if(headshot[playerid] == 1)
    {
	  if(damagedid != INVALID_PLAYER_ID)
		 {
			if(bodypart == 9)
				{
					if(weaponid == 24 || weaponid == 33 || weaponid == 34)
					   {
						   SetPLayerHealth(damagedid, 0.0);
					   }
				}
		 }
    }
}

    return 1;
}
download zcmd and sscanf include. it will make your work easier. I used them for this script and this should work. (REMEMBER it is untested!)
Reply
#3

the above code can be optimized.
Reply
#4

script above doesn't work only texts are showing up but no headshots when I shoot at someone's head.
Reply
#5

Alot better code, you don't need to active headshots for every playerid.
One command to enable/disable

PHP код:
new hstoggle 1;
public 
OnPlayerCommandText(playeridcmdtext[])
{
    if(!
strcmp(cmdtext"/hstoggle"true))
    {
        if(
logged[playerid] == 0) return SendClientMessage(playeridCOLOR_BRIGHTRED"You must be logged in to use that command.");
        if(
PlayerInfo[playerid][pAdmin] < 2) return SendClientMessage(playeridCOLOR_BRIGHTRED"You are not an admin!");
        switch(
hstoggle)
        {
            case 
0hstoggle 1GameTextForAll("Headshots Enabled!"50003);
            case 
1hstoggle 0GameTextForAll("Headshots Disabled!"50003);
        }
        return 
1;
    }
    return 
0;
}
public 
OnPlayerGiveDamage(playeriddamagedidFloatamountweaponidbodypart)
{
    if(
hstoggle == && damagedid != INVALID_PLAYER_ID && bodypart == && (weaponid == 24 || weaponid == 33 || weaponid == 34)) SetPlayerHealth(damagedid0.0);
    return 
1;

Reply
#6

Thanks but doesn't work either...
Reply
#7

Are you getting the Texts "enabled/disabled"?
Try change to this

PHP код:
new hstoggle 1;
public 
OnPlayerCommandText(playeridcmdtext[])
{
    if(!
strcmp(cmdtext"/hstoggle"true))
    {
        if(
logged[playerid] == 0) return SendClientMessage(playeridCOLOR_BRIGHTRED"You must be logged in to use that command.");
        if(
PlayerInfo[playerid][pAdmin] < 2) return SendClientMessage(playeridCOLOR_BRIGHTRED"You are not an admin!");
        switch(
hstoggle)
        {
            case 
0hstoggle 1GameTextForAll("Headshots Enabled!"50003);
            case 
1hstoggle 0GameTextForAll("Headshots Disabled!"50003);
        }
        return 
1;
    }
    return 
0;
}
public 
OnPlayerTakeDamage(playeridissueridFloatamountweaponidbodypart)
{
    if(
hstoggle == && issuerid != INVALID_PLAYER_ID && bodypart == && (weaponid == 24 || weaponid == 33 || weaponid == 34)) SetPlayerHealth(playerid0);
    return 
1;

Reply
#8

I changed to it and still the headshot doesn't work but yes I get the texts.
Reply
#9

BUMP.

Here is the code I use, headshot works but even after disabled and works only for id 0.
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
        {
        if(activeheadshot == 1)
        {
            headshot[i] = 1;
            dini_IntSet("server.ini","headshot", activeheadshot);
            SendClientMessage(playerid, COLOR_ORANGE, "Vous avez activй le headshot pour tout le monde.");
            GetPlayerName(playerid, sendername, sizeof(sendername));
            format(string, sizeof(string), "L'admin %s a activй les headshots. (Eagle, Rifle, Sniper)", sendername);
            SendClientMessageToAll(COLOR_WHITE, string);
            format(string, sizeof(string), "~w~HEADSHOT ACTIVE");
            GameTextForAll(string, 5000, 3 );
            return 1;
        }
        if(activeheadshot == 0)
        {
            headshot[i] = 0;

            dini_IntSet("server.ini","headshot", activeheadshot);
            GetPlayerName(playerid, sendername, sizeof(sendername));
            SendClientMessage(playerid, COLOR_ORANGE, "Vous avez dйsactivй le headshot pour tout le monde.");
            format(string, sizeof(string), "Ladmin %s a dйsactivй les headshots.", sendername);
            SendClientMessageToAll(COLOR_WHITE, string);
            format(string, sizeof(string), "~r~HEADSHOT DESACTIVE");
            GameTextForAll(string, 5000, 3);
            return 1;
        }
        }
Reply
#10

Quote:
Originally Posted by Adamsy
Посмотреть сообщение
BUMP.

Here is the code I use, headshot works but even after disabled and works only for id 0.
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
        {
        if(activeheadshot == 1)
        {
            headshot[i] = 1;
            dini_IntSet("server.ini","headshot", activeheadshot);
            SendClientMessage(playerid, COLOR_ORANGE, "Vous avez activй le headshot pour tout le monde.");
            GetPlayerName(playerid, sendername, sizeof(sendername));
            format(string, sizeof(string), "L'admin %s a activй les headshots. (Eagle, Rifle, Sniper)", sendername);
            SendClientMessageToAll(COLOR_WHITE, string);
            format(string, sizeof(string), "~w~HEADSHOT ACTIVE");
            GameTextForAll(string, 5000, 3 );
            return 1;
        }
        if(activeheadshot == 0)
        {
            headshot[i] = 0;

            dini_IntSet("server.ini","headshot", activeheadshot);
            GetPlayerName(playerid, sendername, sizeof(sendername));
            SendClientMessage(playerid, COLOR_ORANGE, "Vous avez dйsactivй le headshot pour tout le monde.");
            format(string, sizeof(string), "Ladmin %s a dйsactivй les headshots.", sendername);
            SendClientMessageToAll(COLOR_WHITE, string);
            format(string, sizeof(string), "~r~HEADSHOT DESACTIVE");
            GameTextForAll(string, 5000, 3);
            return 1;
        }
        }
your return statements in the loop breaks it so only first iteration will work that is id 0 so you have to remove it

PHP код:
for(new 0MAX_PLAYERSi++)
        {
        if(
activeheadshot == 1)
        {
            
headshot[i] = 1;
            
dini_IntSet("server.ini","headshot"activeheadshot);
            
SendClientMessage(playeridCOLOR_ORANGE"Vous avez activй le headshot pour tout le monde.");
            
GetPlayerName(playeridsendernamesizeof(sendername));
            
format(stringsizeof(string), "L'admin %s a activй les headshots. (Eagle, Rifle, Sniper)"sendername);
            
SendClientMessageToAll(COLOR_WHITEstring);
            
format(stringsizeof(string), "~w~HEADSHOT ACTIVE");
            
GameTextForAll(string5000);
            
        }
        if(
activeheadshot == 0)
        {
            
headshot[i] = 0;
            
dini_IntSet("server.ini","headshot"activeheadshot);
            
GetPlayerName(playeridsendernamesizeof(sendername));
            
SendClientMessage(playeridCOLOR_ORANGE"Vous avez dйsactivй le headshot pour tout le monde.");
            
format(stringsizeof(string), "Ladmin %s a dйsactivй les headshots."sendername);
            
SendClientMessageToAll(COLOR_WHITEstring);
            
format(stringsizeof(string), "~r~HEADSHOT DESACTIVE");
            
GameTextForAll(string50003);
            
        }
}
        
return 
1;} 
Even though i edited your code i wont suggest it as its not optimized so i suggest you to
*use zcmd instead of strcmp
*use foreach for looping through players
*use sql saving system.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)