SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 23/09/2011, 04:55 PM   #1
brett7
Gangsta
 
brett7's Avatar
 
Join Date: Nov 2007
Location: samp is #1
Posts: 732
Reputation: 14
Default How To Make Kill Streaks!

Hi, this is my first tutorial. I have seen a few filterscipts that create kill streaks but I thought I would make a tutorial to explain how they work.

Basically this is how to add a kill streak feature to your game mode just like in call of duty. What this will do is every time you kill a player you will get +1 to your kill streak and a start for every player you kill. If you kill 2 or more in a row a message will appear telling everyone. Once you die it will be reset.



1. Firstly at the top of your script near the defines you will need to add:
Code:
new KillStreak[MAX_PLAYERS];
This is the variable that will store how many kills you have.



2. Next OnPlayerConnect you need to add:
Code:
public OnPlayerConnect(playerid)
{
	    KillStreak[playerid] = 0;
        return 1;
}
So when a player connects they haven't killed anyone so they will be set to 0.



3. And OnPlayerDisconnect:
Code:
public OnPlayerDisconnect(playerid, reason)
{
	KillStreak[playerid] = 0;
	return 1;
}
When the player disconnects we set their killstreak to 0.



4. Ok now on to the main killing, we need a bigish piece of code so I'll break it down (this part goes under OnPlayerDeath):
Code:
if(IsPlayerConnected(killerid) && killerid != INVALID_PLAYER_ID)
{
      if(GetPlayerWantedLevel(killerid) < 6)
	  {
    	SetPlayerWantedLevel(killerid, GetPlayerWantedLevel(killerid) + 1);
	  }
        KillStreak[killerid]++;
	GivePlayerMoney(killerid, 1000);
}
This bit will add a wanted level on every kill. We check that the killer is connected and that its not an invalid id. Then we check that the killer hasn't got a wanted level smaller than 6, then we add one extra.

Then we add +1 to the "KillStreak" variable we declared earlier. (the ++ means add 1). Finally we give the killer a $1000.

5.
Code:
SetPlayerWantedLevel(playerid,0);
KillStreak[playerid] = 0;
When a player dies, their killstreak will end and their wanted level and streak will be set to 0.



6. On every death we do a check to see what killstreak someone has:
Code:
	new str[256], PlayerName[MAX_PLAYER_NAME]; //This part we declare a new string
	GetPlayerName(killerid, PlayerName, sizeof(PlayerName)); //This will get the killer name

 	switch( KillStreak[ killerid ] ) 
       {
	      case 1: //You wouldn't really count 1 kill as a streak but it gives you an idea
       {       
             format(str, sizeof(str), "~r~ %s is on a kill!", PlayerName);
             GameTextForAll(str,4000,4);
        }
As you can see if the killers killstreak is one it will send game text to everyone saying they have killed someone. We use the switch function so that if the killstreak[killerid] = 1 then it will do on to say Player is on a kill!




The entire piece:
Code:
public OnPlayerDeath(playerid, killerid, reason)
{
      if(IsPlayerConnected(killerid) && killerid != INVALID_PLAYER_ID)
      {
             if(GetPlayerWantedLevel(killerid) < 6)
	    {
    	      SetPlayerWantedLevel(killerid, GetPlayerWantedLevel(killerid) + 1);
	     }
       
            KillStreak[killerid]++;         
            GivePlayerMoney(killerid, 1000);
      }

	SetPlayerWantedLevel(playerid,0);
        KillStreak[playerid] = 0;


	new str[256], PlayerName[MAX_PLAYER_NAME];
	GetPlayerName(killerid, PlayerName, sizeof(PlayerName));

        switch( KillStreak[ killerid ] ) 
      {
	case 1: //You wouldn't really count 1 kill as a streak but it gives you an idea
    {       
        format(str, sizeof(str), "~r~ %s is on a kill!", PlayerName);
        GameTextForAll(str,4000,4);
    }
    case 2:
    {
        format(str, sizeof(str), "~r~ %s is on a ~b~double kill!", PlayerName);
        GameTextForAll(str,4000,4);
    }
    case 3:
    {
        format(str, sizeof(str), "~y~%s is on a ~r~killing spree!", PlayerName);
        GameTextForAll(str,4000,4);
    }
    case 4:
    {
        format(str, sizeof(str), "~g~%s is on a ~b~mmmmmonster kill!", PlayerName);
        GameTextForAll(str,4000,4);
    }
    case 5:
    {
        format(str, sizeof(str), "~r~%s is ~p~dominating!", PlayerName);
        GameTextForAll(str,4000,4);
    }
    case 6:
    {
        format(str, sizeof(str), "~p~%s is ~y~unstopable!", PlayerName);
        GameTextForAll(str,4000,4);
    }/*
    case 7: //You can do this as many times as you like
    {
        format(str,sizeof(str),"%s is annihilating!",Killername);
        GameTextForAll(str,4000,4);
    }
    case 10:
    {
        format(str,sizeof(str),"%s is GodLike!",Killername);
        GameTextForAll(str,4000,4);
    }*/
    }

	return 1;
}

Thanks for reading and I hope this helped you!
By brett7

Last edited by brett7; 24/09/2011 at 02:21 PM.
brett7 is offline   Reply With Quote
Old 23/09/2011, 07:07 PM   #2
Max_Coldheart
Guest
 
Posts: n/a
Default Re: How To Make Kill Streaks!

Seems good, I think this will be helpful to people who doesn't know how to make killstreaks.
  Reply With Quote
Old 23/09/2011, 07:14 PM   #3
IstuntmanI
High-roller
 
IstuntmanI's Avatar
 
Join Date: Mar 2009
Location: Romania
Posts: 1,885
Reputation: 370
Default Re: How To Make Kill Streaks!

Very simple and useful.

Change
Code:
if(KillStreak[killerid] == 1) //You wouldn't really count 1 kill as a streak but it gives you an idea
    {       
        format(str, sizeof(str), "~r~ %s is on a kill!", PlayerName);
        GameTextForAll(str,4000,4);
    }

    if(KillStreak[killerid] == 2)
    {
        format(str, sizeof(str), "~r~ %s is on a ~b~double kill!", PlayerName);
        GameTextForAll(str,4000,4);
    }
    if(KillStreak[killerid] == 3)
    {
        format(str, sizeof(str), "~y~%s is on a ~r~killing spree!", PlayerName);
        GameTextForAll(str,4000,4);
    }
    if(KillStreak[killerid] == 4)
    {
        format(str, sizeof(str), "~g~%s is on a ~b~mmmmmonster kill!", PlayerName);
        GameTextForAll(str,4000,4);
    }
    if(KillStreak[killerid] == 5)
    {
        format(str, sizeof(str), "~r~%s is ~p~dominating!", PlayerName);
        GameTextForAll(str,4000,4);
    }
    if(KillStreak[killerid] == 6)
    {
        format(str, sizeof(str), "~p~%s is ~y~unstopable!", PlayerName);
        GameTextForAll(str,4000,4);
    }/*
    if(KillStreak[killerid] == 7) //You can do this as many times as you like
    {
        format(str,sizeof(str),"%s is annihilating!",Killername);
        GameTextForAll(str,4000,4);
    }
    if(KillStreak[killerid] == 10)
    {
        format(str,sizeof(str),"%s is GodLike!",Killername);
        GameTextForAll(str,4000,4);
    }*/
to
Code:
switch( KillStreak[ killerid ] ) 
{
	case 1: //You wouldn't really count 1 kill as a streak but it gives you an idea
    {       
        format(str, sizeof(str), "~r~ %s is on a kill!", PlayerName);
        GameTextForAll(str,4000,4);
    }
    case 2:
    {
        format(str, sizeof(str), "~r~ %s is on a ~b~double kill!", PlayerName);
        GameTextForAll(str,4000,4);
    }
    case 3:
    {
        format(str, sizeof(str), "~y~%s is on a ~r~killing spree!", PlayerName);
        GameTextForAll(str,4000,4);
    }
    case 4:
    {
        format(str, sizeof(str), "~g~%s is on a ~b~mmmmmonster kill!", PlayerName);
        GameTextForAll(str,4000,4);
    }
    case 5:
    {
        format(str, sizeof(str), "~r~%s is ~p~dominating!", PlayerName);
        GameTextForAll(str,4000,4);
    }
    case 6:
    {
        format(str, sizeof(str), "~p~%s is ~y~unstopable!", PlayerName);
        GameTextForAll(str,4000,4);
    }/*
    case 7: //You can do this as many times as you like
    {
        format(str,sizeof(str),"%s is annihilating!",Killername);
        GameTextForAll(str,4000,4);
    }
    case 10:
    {
        format(str,sizeof(str),"%s is GodLike!",Killername);
        GameTextForAll(str,4000,4);
    }*/
}
'switch' is faster.
IstuntmanI is offline   Reply With Quote
Old 24/09/2011, 08:40 PM   #4
brett7
Gangsta
 
brett7's Avatar
 
Join Date: Nov 2007
Location: samp is #1
Posts: 732
Reputation: 14
Default Re: How To Make Kill Streaks!

Updated!
brett7 is offline   Reply With Quote
Old 18/08/2012, 01:52 AM   #5
xMaGmOtAnEtHx
Big Clucker
 
Join Date: Aug 2012
Posts: 79
Reputation: 0
Default Re: How To Make Kill Streaks!

Very nice!!! But how do I add Filterscripts I am trying to on this filterscript to make it have a 3 kill streak and make the filterscript work please help!
xMaGmOtAnEtHx is offline   Reply With Quote
Old 19/08/2012, 01:23 PM   #6
Coder_
Big Clucker
 
Join Date: Jul 2012
Posts: 68
Reputation: 1
Default Re: How To Make Kill Streaks!

Nice
http://forum.sa-mp.com/showthread.ph...31#post1751831
Coder_ is offline   Reply With Quote
Old 31/01/2014, 11:12 PM   #7
Error000
Big Clucker
 
Error000's Avatar
 
Join Date: Jan 2013
Location: FoCo
Posts: 108
Reputation: 9
Default Re: How To Make Kill Streaks!

Helped.
Error000 is offline   Reply With Quote
Old 31/01/2014, 11:18 PM   #8
SeV_
High-roller
 
SeV_'s Avatar
 
Join Date: Jul 2012
Location: __________________.
Posts: 1,468
Reputation: 154
Default Re: How To Make Kill Streaks!

LoL man..

Topic Date: 23/09/2011
__________________
Importação de peças para veículos do grupo VAG.
SeV_ is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] How to make anti spawn kill iJumbo Tutorials 21 04/04/2011 12:36 AM
Kill Streaks ZaaRawwR Help Archive 12 06/03/2011 04:04 PM
How to make it so when I kill I get a point Jack_Rocker Help Archive 2 06/02/2011 03:06 AM
Kill deaths ratio how to make? iStarzz Help Archive 1 21/05/2010 11:13 AM
Help with health re-generation + Kill Streaks benyaminx Help Archive 0 10/01/2010 10:04 PM


All times are GMT. The time now is 12:17 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.