[Tutorial] Simple Killstreaks
#1

Hello all! How are you? First of all, I would like to thank you for reading this, and appologize if I make any errors in the code. Now to the tutorial.

STEP 1:
First of all, we will make the variable for the player's killstreak.
Code:
new killstreak[MAX_PLAYERS];
We made it an array so that it can save the killstreak of many players.

STEP 2:
Next, we will make sure that the killstreak of the player is set to 0 when he joins and leavs the server. That way, it will be fair. Heres the code:
Code:
public OnPlayerConnect(playerid)
{
     killstreak[playerid] = 0; //sets the player's killstreak to 0
     return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
     killstreak[playerid] = 0;
     return 1;
}
Again, this is so that the player's killstreak is 0 on connect/disconnect. You could remove ont of them and it would work still but... just for safety, I use both.

STEP 3:
Next, we will make the function to handle the killstreaks. Just to make the script cleaner. Heres the function:
Code:
stock HandleKS(playerid, killerid) //put this function outside of any callbacks or functions
{
     killstreak[playerid] = 0;
     killstreak[killerid] ++;
     
     new msg1[64], msg2[64], name1[MAX_PLAYER_NAME], name2[MAX_PLAYER_NAME];

     GetPlayerName(playerid, name1, strlen(name1));
     GetPlayerName(playerid, name2, strlen(name2));

     format(msg1, strlen(msg1), "%s has ended %s's killstreak", name2, name1);
     format(msg2, strlen(msg2), "%s is now on a killsreak of %i", name2, killstreak[killerid]);

     SendClientMessageToAll(-1, msg1);
     SendClientMessageToAll(-1, msg2);

     switch(killstreak[killerid])
     {
          case 3: 
          {
               //killstreak code - make ur killstreak here
          }
          case 6: 
          {
               //killstreak code - make ur killstreak here
          }
          case 9:  //change the numbers as desired and add/remove as many as you want
          {
               //killstreak code - make ur killstreak here
          }
     }
     return 1;
}
Basically what this code does, is it changes the killstreaks of the players, sends a message to everyone about the players's killtreaks, and if the killer got a killstreak, does it.

STEP 4:
now, we just add the function that handles the killstreaks to the onplsyerdeath callback. That way, the player doesnt just have 0 killstreak the whole time. :P
Code:
public OnPlayerDeath(playerid, killerid, reason)
{
     HandleKS(playerid, killerid);
     return 1;
}
Now, the whole system is done. :P

So now, you should have a working killstreak system. Thank you for reading and thank you for your time.

p.s. Comment any errors I made and I'll fix them.
Reply


Messages In This Thread
Simple Killstreaks - by sciman001 - 13.11.2011, 02:03
Re: Simple Killstreaks - by [HiC]TheKiller - 13.11.2011, 02:45
Re: Simple Killstreaks - by Xx_OutLawZ_xX - 13.11.2011, 02:47
Re: Simple Killstreaks - by sciman001 - 13.11.2011, 05:27
Re: Simple Killstreaks - by Hansrutger - 16.11.2011, 20:27
Re: Simple Killstreaks - by Astralis - 17.11.2011, 04:21
Re: Simple Killstreaks - by TheLazySloth - 17.11.2011, 08:10
Re: Simple Killstreaks - by Niko_boy - 19.11.2011, 16:01
Re: Simple Killstreaks - by Hansrutger - 19.11.2011, 23:21
Re: Simple Killstreaks - by krystiang1 - 25.11.2011, 20:53

Forum Jump:


Users browsing this thread: 3 Guest(s)