[Tutorial] Killstreaks for players!
#1

Killstreaks


'Sup y'all? Today, I'm showing you how to script the famous killstreaks which many servers are including!

Requirements:
  • PAWN Basic knowledge
  • Your brain
1. Adding the global-variable:


First of all, add the global variable on the top of your script:

pawn Code:
new Streaks[MAX_PLAYERS];
It will store how many kills you currently have, for the maximum amount of players!

2. Resetting the variable:



Under the callbacks "OnPlayerConnect" and "OnPlayerDisconnect", you should add this line:


pawn Code:
Streaks[playerid] = 0;
Why? Usually, player won't have a streak when they'll leave or join the server! So we're giving the variable the value '0' when a player connects / disconnects, infact that it'll get reset again!

3. Increasing the variable's value:


Search for your callback "OnPlayerDeath"! Now, we're going to add a code which looks a little bigger, so I'm gonna continue step-by-step. First, we're going to add these lines, explained in comments:

pawn Code:
public OnPlayerDeath(playerid, killerid, reason)
{
if(IsPlayerConnected(killerid) &&  killerid != INVALID_PLAYER_ID ) { //check if the player is connected and it's a VALID KILL
        if(GetPlayerWantedLevel(killerid) < 6) //if the player's wantedlevel is under 6
          {
            SetPlayerWantedLevel(killerid, GetPlayerWantedLevel(killerid) + 1); //increase it by 1
          }
            Streaks[killerid] ++; //the sign '++' means, increase the variable for the killerid by 1
            GivePlayerMoney(killerid, 500); //if you like, give the killer some money, else comment this line out
        }
            SetPlayerWantedLevel(playerid, 0); //the player who died will get his wanted level reset to 0
        Streaks[playerid] = 0; //and his streak will end, while giving the value '0' to this variable
4. Switching through cases:


So now, we arrived at the main part of this tutorial! Under your code you currently have under "OnPlayerDeath", add the following:

pawn Code:
SetPlayerScore(killerid,GetPlayerScore(killerid)+1); //not really necessary, would increase the player's score by 1 point
        new str[ 256 ], KillerName[MAX_PLAYER_NAME]; //here, you're defining a string and the killername
        GetPlayerName(killerid, KillerName, sizeof(KillerName)); //receive the information of the killer's name
        switch(Streaks[killerid]) //IMPORTANT: with the function "switch", you're switching / toggling through the killstreaks of a player (Streals). you need the killerid here, because the playerid is the one which is GETTING killed
        {
            case 2: // we won't start with the first kill (case 1), because it wouldn't be countable as streak
            {
                format(str, sizeof(str), "[KILLINGSPREE] ~g~%s has performed a ~y~double kill!", KillerName); //here, you're formatting the defined string and add the content (text)
                GameTextForAll(str,4000,4); //this is a function, which will show a short, colored big text for all the players (str, 4000ms, stylenumber 4)
            }
            case 3:
            {
                format(str, sizeof(str), "[KILLINGSPREE] ~y~Triple Kill for ~b~%s!", KillerName);
                GameTextForAll(str,4000,4);
            }
            case 4:
            {
                format(str, sizeof(str), "[KILLINGSPREE] ~p~Quadro Kill for ~r~%s!", KillerName);
                GameTextForAll(str,4000,4);
            }
            case 5:
            {
                format(str, sizeof(str), "[KILLINGSPREE] ~r~%s is dominating with ~p~five kills!", KillerName);
                GameTextForAll(str,4000,4);
            }
            case 6:
            {
                format(str, sizeof(str), "[KILLINGSPREE] ~w~%s is godlike with ~y~six kills!", KillerName);
                    GameTextForAll(str,4000,4);
            }
            case 7:
            {
                format(str, sizeof(str), "[KILLINGSPREE] ~r~RAMPAGE for %s with ~w~seven kills!", KillerName);
                GameTextForAll(str,4000,4);
            }
            case 8:
            {
                format(str, sizeof(str), "[KILLINGSPREE] ~p~%s is unbelievable with ~y~eight kills!", KillerName);
                GameTextForAll(str,4000,4);
            }
            case 9:
            {
                format(str, sizeof(str), "[KILLINGSPREE] ~g~%s is worldclass, ~b~nine kills!", KillerName);
                GameTextForAll(str,4000,4);
            }
            case 10:
            {
                format(str, sizeof(str), "[KILLINGSPREE] ~b~%s is annihilating with ~g~ten kills!", KillerName);
                GameTextForAll(str,4000,4);
            }
/*
            case 11:
            {
            just continue however you want, just in the same way as above
            }*/
IMPORTANT NOTE:
The function "GameTextForAll" might not work 100% because it might getting mixed up with other gametext / textdraws! If it didn't work, use the following:

pawn Code:
SendClientMessageToAll(COLOR, str);
Credits:
- Tutorial and explanations - Twisted Insane
Reply


Messages In This Thread
Killstreaks for players! - by Twisted_Insane - 24.03.2012, 16:58
Re: Killstreaks for players! - by emokidx - 25.03.2012, 05:27
Re: Killstreaks for players! - by Wickeed - 25.03.2012, 09:06
Re: Killstreaks for players! - by Twisted_Insane - 25.03.2012, 10:37
Re: Killstreaks for players! - by iGetty - 25.03.2012, 13:13
Re: Killstreaks for players! - by Vince - 25.03.2012, 13:22
Re: Killstreaks for players! - by Twisted_Insane - 25.03.2012, 13:23
Re: Killstreaks for players! - by iGetty - 25.03.2012, 13:23
Re: Killstreaks for players! - by Twisted_Insane - 25.03.2012, 13:36
Re: Killstreaks for players! - by 2KY - 25.03.2012, 18:50

Forum Jump:


Users browsing this thread: 4 Guest(s)