23.09.2011, 15:55
(
Last edited by brett7; 24/09/2011 at 01:21 PM.
)
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:
This is the variable that will store how many kills you have.
2. Next OnPlayerConnect you need to add:
So when a player connects they haven't killed anyone so they will be set to 0.
3. And OnPlayerDisconnect:
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):
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.
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:
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:
Thanks for reading and I hope this helped you!
By brett7
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];
2. Next OnPlayerConnect you need to add:
pawn Code:
public OnPlayerConnect(playerid)
{
KillStreak[playerid] = 0;
return 1;
}
3. And OnPlayerDisconnect:
pawn Code:
public OnPlayerDisconnect(playerid, reason)
{
KillStreak[playerid] = 0;
return 1;
}
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);
}
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;
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);
}
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;
}
By brett7