How to use TeamKill Protection
#1

I have recently seeing lots of people asking for "how to use team kill protection" or something like that. Therefore, I will make a simple and easy tutorial on how to make Team Kill protection.

First, we need to define the teams at the top of your script write:
pawn Code:
#define TEAM_RED 0 // This is creating the first team named "Red"
#define TEAM_BLUE 1 // This is creating the second team named "Blue"
Now we will define the gTeam to set the teams from each other:
pawn Code:
new gTeam[MAX_PLAYERS];
Now we've defined gTeam and our teams lets create the teams and their classes. Do this in:
Code:
public OnGameModeInit()
{
     return 1;
}
pawn Code:
AddPlayerClass(118, 0, 0, 0, 0, 1, 2, 10, 10, 11,11);// This is creating a class for the player to choose from. As you should know 118 is the skin, the first three 0's are X, Y , Z and the fourth 0 is the rotation. Then the 1 is weapon id and the 2 is the ammo for weapon id 1 to spawn with and e.t.c.
AddPlayerClass(118, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);// Make sure you make these with what skins you want the teams to have and use make them spawn with their team.
Now we have the classes created we seperate the teams. Add SetPlayerTeamFromClass(playerid, classid) in your script. Make sure it is no in any other functions.
pawn Code:
SetPlayerTeamFromClass(playerid, classid)
{
      if (classid == 0)//This is using what we had at the top. #define TEAM_RED 0 if the classid = 0 then they are team red.
      {
               gTeam[playerid] = TEAM_RED;
      }
      else  //Else means any other ones will be
      {
               gTeam[playerid] = TEAM_BLUE;
      }
}
Now we must make the teamkill protection and timer. First lets make the timer. At the top of your script, again add
pawn Code:
forward TeamKill(); //This is a forward. It will wnable us to make the TeamKill() a public and create effects in the timer.
Now lets make the teamkill protecter. We will be editing here:
pawn Code:
public OnPlayerDeath(playerid, killerid, reason)
{
     return 1;
}
Under that add these lines:
pawn Code:
if(gTeam[killerid] == gTeam[playerid]) // [killerid] is the player who kills a/the player on their team. [playerid] is the player who is killed. Therefore it is saying if a player from a team kills a player on their team then they will have these effects belowll
     {
          SendClientMessage(killerid,0xAA3333AA,"You can't team kill,this is unfair,you are now frozen for 5 seconds.");// this is telling them they will be punished.
          TogglePlayerControllable(killerid,0); //this is making them freeze
          SetTimerEx("TeamKill", 5000, 0, "i", killerid); //this is creating the timer.TeamKill is what we used forward on. TeamKill will be the timer's name. 5000 is the milliseconds the timer will last. 0 means that it will not repeat. "i" means anyplayer that teamkills, and killerid is the player who killedthem.
          return 1;
     }
//Here you can have else and saying if it is a valid kill them give them money
Now we will create a public for the timer.
pawn Code:
public TeamKill()
{
    TogglePlayerControllable(playerid, 1); //unfreezing them
    SendClientMessage(playerid, 0xAA3333AA, "* You have been unfrozen!"); //sending a message saying you are unfrozen
    GameTextForPlayer(playerid, "~b~Unfrozen!", 8000, 3); //not neccesarry just creating gametext saying you are unfrozen
    return 1;
}
Now run. The script should have errors right? Well thats when you scroll up through the script and find where we forwarded the timer and do this:
pawn Code:
forward TeamKill(playerid);//this is just making us able to use playerid in this timer
No go back down to the timer used with public and add:
pawn Code:
public TeamKill(playerid)
Now you are done. This is just a basic team kill system.
Reply


Messages In This Thread
HowTo: Create Punishment for TeamKill - by ToPhrESH - 12.07.2010, 19:33
Re: How to use TeamKill Protection - by Hiddos - 12.07.2010, 19:38
Re: How to use TeamKill Protection - by ToPhrESH - 12.07.2010, 19:49
Re: How to use TeamKill Protection - by Hiddos - 12.07.2010, 19:55
Re: How to use TeamKill Protection - by MikkelGutten - 12.07.2010, 20:01
Re: How to use TeamKill Protection - by Grim_ - 12.07.2010, 20:39
Re: How to use TeamKill Protection - by Aleluja - 12.07.2010, 21:16
Re: How to use TeamKill Protection - by ToPhrESH - 12.07.2010, 21:41
Re: How to use TeamKill Protection - by Grim_ - 12.07.2010, 21:44
Re: How to use TeamKill Protection - by ToPhrESH - 12.07.2010, 21:59
Re: How to use TeamKill Protection - by Hiddos - 13.07.2010, 10:33
Re: How to use TeamKill Protection - by iZN - 13.07.2010, 10:36
Re: How to use TeamKill Protection - by Grim_ - 13.07.2010, 14:32
Re: How to use TeamKill Protection - by ToPhrESH - 13.07.2010, 21:59
Re: How to use TeamKill Protection - by Nonameman - 14.07.2010, 00:31
Re: How to use TeamKill Protection - by ToPhrESH - 14.07.2010, 04:21
Re: How to use TeamKill Protection - by snoob - 14.07.2010, 04:28
Re: How to use TeamKill Protection - by Carlton - 14.07.2010, 04:38
Re: How to use TeamKill Protection - by Grim_ - 14.07.2010, 04:50

Forum Jump:


Users browsing this thread: 2 Guest(s)