[Tutorial] How To Make Kill Streaks!
#1

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:
pawn Code:
new KillStreak[MAX_PLAYERS];
This is the variable that will store how many kills you have.



2. Next OnPlayerConnect you need to add:
pawn 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:
pawn 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):
pawn 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.
pawn 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:
pawn 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:
pawn 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
Reply
#2

Seems good, I think this will be helpful to people who doesn't know how to make killstreaks.
Reply
#3

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.
Reply
#4

Updated!
Reply
#5

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!
Reply
#6

Nice
http://forum.sa-mp.com/showthread.ph...31#post1751831
Reply
#7

Helped.
Reply
#8

LoL man..

Topic Date: 23/09/2011
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)