[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
#2

Here are some errors with the script

1. MAX_PLAYERS is case sensitive so max_players will return a unknown error.
2. max_playerp_name isn't a defined variable and max_player_name needs to be capitalized to be a defined variable.
3. There is no value assigned to name1 or name2
4.
pawn Code:
format(msg1, strlen(msg1), "%s has ended his killstreak", name1);
Who has ended who's killstreak? If the person wasn't on a killstreak, it would still show.

5. OnPlayerDisConnect should be OnPlayerDisconnect, remember the case.

You should explain the tutorial better, what does each function do?
Reply
#3

And what, have you tested this?
Reply
#4

Well, that just shows how tired I am. :P I appologize for the errors. I will fix them right now. Thanks for the responses though.
Reply
#5

Where do I put Step 3? Under which "public"? :S
Reply
#6

Quote:
Originally Posted by Hansrutger
View Post
Where do I put Step 3? Under which "public"? :S
Ye , where?
Reply
#7

Sooo everytime a player dies... messages will be spammed continuously? That's what it looks like from my observation.
Reply
#8

Quote:
Originally Posted by Hansrutger
View Post
Where do I put Step 3? Under which "public"? :S
Well
The Step 3 contains a Stock Script part Place it in lowest part of script
Its best place to place stocks
Reply
#9

Quote:
Originally Posted by Jagat
View Post
Well
The Step 3 contains a Stock Script part Place it in lowest part of script
Its best place to place stocks
Thank you!
Reply
#10

Quote:
Originally Posted by Jagat
View Post
Well
The Step 3 contains a Stock Script part Place it in lowest part of script
Its best place to place stocks
So your saying to just scroll down to the bottom of my script and CTRL+V it there?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)