[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


Messages In This Thread
How To Make Kill Streaks! - by brett7 - 23.09.2011, 15:55
Re: How To Make Kill Streaks! - by Max_Coldheart - 23.09.2011, 18:07
Re: How To Make Kill Streaks! - by IstuntmanI - 23.09.2011, 18:14
Re: How To Make Kill Streaks! - by brett7 - 24.09.2011, 19:40
Re: How To Make Kill Streaks! - by xMaGmOtAnEtHx - 18.08.2012, 00:52
Re: How To Make Kill Streaks! - by Coder_ - 19.08.2012, 12:23
Re: How To Make Kill Streaks! - by Error000 - 31.01.2014, 22:12
Re: How To Make Kill Streaks! - by SeV_ - 31.01.2014, 22:18

Forum Jump:


Users browsing this thread: 1 Guest(s)