[Tutorial] HeadShot System [Explained]
#1

Tutorial - HeadShot System


Intro
Nothing special, just a small tutorial explaining about how to make a "HeadShot" system, i do not claim this as effort, since its pretty easy & quick... But since i could not find any decent tutorial i thought... lets do dis.


Content

  • Explaining OnPlayerTakeDamage, since we're going to need it.
  • HeadShot system mini-script.
  • Team Protection (cant hit same team).
  • Enable/Disable HeadShot system.
  • Anti-HeadShot spam(looks weired?)



Let's Get Started

For this tutorial we're going to base on callback OnPlayerTakeDamage.

Description according to wiki page:
Quote:

This callback is called when a player takes damage.

That one explains pretty much everything... but lets look at it deeply with its parameters:
PHP код:
public OnPlayerTakeDamage(playeridissueridFloat:amountweaponidbodypart
  • playerid - player who took damage.
  • issuerid - Player who gave damage(The Shooter), can be INVALID_PLAYER_ID if the damage was caused by self.
  • Float:amount - Amount in Float, of much damage did player took (not needed in our case actually, but you could use it for other things... such as labels on head "Damage -amount")
  • weaponid - ID of the weapon that was used while giving damage.
  • bodypart - The bodypart where player got hit (0.3z+)



Code
We will need a global variable called "HeadShotSystem", so lets define it, anywhere outside a callback/function (near includes?)

PHP код:
booleanserver variable not player variable
new bool:HeadShotSystem
Main Code

PHP код:
public OnPlayerTakeDamage(playeridissueridFloat:amountweaponidbodypart)
{    
    
// check if there was a shooter, weaponID was 34(Sniper) and bodypart was 9(Head)
    
if(issuerid != INVALID_PLAYER_ID && weaponid == 34 && bodypart == 9)
    {
        
//checking if headshot system is ON.
        
if(HeadShotSystem == true)
        {
            
// checks if both players have same team, except NO_TEAM. if not procced, otherwise send error message
//*A edit by our genius friend sickattack
            
if(GetPlayerTeam(issuerid) | GetPlayerTeam(playerid) == NO_TEAM || GetPlayerTeam(issuerid) != GetPlayerTeam(playerid)) 
            {    
//check if player is dead... if not proceed(by Gammix)
                
if (GetPlayerState(playerid) != PLAYER_STATE_WASTED)
                {
                    
//variables, first one to format the message, second and third contain player names.
                    
new headmsg[128], dead[24], killer[24];
                    
//on player's screen we show him a message for 3 seconds "HeadShot"
                    
GameTextForPlayer(playerid"~r~Head Shot",3000,4);
                    
// same to issuer's screen
                    
GameTextForPlayer(issuerid"~r~Head Shot!",3000,4);
                    
// we get the victims name with this function and store it into our previously made variable "dead";
                    
GetPlayerName(playeriddeadsizeof(dead));
                    
// we get the victims name with this function and store it into our previously made variable "killer";
                    
GetPlayerName(issueridkillersizeof(killer));
                    
//format the message, means we put that text into "headmsg".
                    
format(headmsgsizeof(headmsg), "{FFDC2E}%s (%i) Has Been Killed in a Headshot by %s (%i)!",deadplayeridkiller,issuerid);
                    
// once we've formatted the message we're ready to send the message to all players!
                    
SendClientMessageToAll(0xAA3333AAheadmsg);
                    
//kill the player
                    
SetPlayerHealth(playerid0.0);
                    
//and tell the server that he's dead!
                
}
            }
        }
        else
            
SendClientMessage(issuerid, -1"That player is in your team!");        
    }
    return 
1;

Command to enable/disable headshot system

*Optimized by Sreyas
PHP код:
COMMAND:seths(playeridparams[]) 

        
//replace with your admin system 
        
if(IsPlayerAdmin(playerid)) 
        { 
            
HeadShotSystem = !HeadShotSystem
            new 
string11[109], pname[24]; 
            
GetPlayerName(playeridpname24); 
            
format(string11sizeof(string11), "[Admin] Server admin %s(%d) has %s Headshot system!"pname,playerid,(HeadShotSystem)?("enabled"):("disabled")); 
            
SendClientMessageToAll(-1string11); 
        } 
        return 
1




Requirements:
- SA:MP version 0.3z +(bodypart)
- sscanf (for the cmd we've used)
- A IDE


Credits:
- SA:MP Team.
- ****** for sscanf



Did i miss something, lemme know with a post, and remember! this is a shit tutorial!
Reply


Messages In This Thread
HeadShot System [Explained] - by iLearner - 11.01.2017, 17:35
Re: HeadShot System [Explained] - by Gammix - 11.01.2017, 17:43
Re: HeadShot System [Explained] - by Logic_ - 11.01.2017, 17:44
Re: HeadShot System [Explained] - by iLearner - 11.01.2017, 17:45
Re: HeadShot System [Explained] - by RedRex - 11.01.2017, 17:54
Re: HeadShot System [Explained] - by saffierr - 11.01.2017, 18:02
Re: HeadShot System [Explained] - by Logic_ - 11.01.2017, 18:05
Re: HeadShot System [Explained] - by iLearner - 11.01.2017, 18:06
Re: HeadShot System [Explained] - by saffierr - 11.01.2017, 18:08
Re: HeadShot System [Explained] - by RyderX - 11.01.2017, 18:32
Re: HeadShot System [Explained] - by PhoneixViper - 11.01.2017, 18:55
Re: HeadShot System [Explained] - by Gammix - 11.01.2017, 19:06
Re: HeadShot System [Explained] - by iLearner - 11.01.2017, 19:07
Re: HeadShot System [Explained] - by SickAttack - 11.01.2017, 19:27
Re: HeadShot System [Explained] - by iLearner - 11.01.2017, 19:35
Re: HeadShot System [Explained] - by SickAttack - 11.01.2017, 19:48
Re: HeadShot System [Explained] - by saffierr - 12.01.2017, 00:14
Re: HeadShot System [Explained] - by SickAttack - 12.01.2017, 00:28
Re: HeadShot System [Explained] - by saffierr - 12.01.2017, 00:58
Re: HeadShot System [Explained] - by muzammilfreeman - 12.01.2017, 01:01
Re: HeadShot System [Explained] - by Lordzy - 12.01.2017, 11:04
Re: HeadShot System [Explained] - by SyS - 12.01.2017, 11:57
Re: HeadShot System [Explained] - by iLearner - 12.01.2017, 12:39
Re: HeadShot System [Explained] - by Gammix - 12.01.2017, 13:16
Re: HeadShot System [Explained] - by SickAttack - 12.01.2017, 14:11
Re: HeadShot System [Explained] - by Lordzy - 12.01.2017, 14:23
Re: HeadShot System [Explained] - by iLearner - 12.01.2017, 14:27
Re: HeadShot System [Explained] - by GoldenLion - 12.01.2017, 14:32
Re: HeadShot System [Explained] - by SickAttack - 12.01.2017, 14:33
Re: HeadShot System [Explained] - by iLearner - 12.01.2017, 14:42
Re: HeadShot System [Explained] - by GoldenLion - 12.01.2017, 14:45
Re: HeadShot System [Explained] - by saffierr - 12.01.2017, 14:52
Re: HeadShot System [Explained] - by iLearner - 12.01.2017, 15:07
Re: HeadShot System [Explained] - by GhostHacker9 - 20.01.2017, 08:28

Forum Jump:


Users browsing this thread: 1 Guest(s)