12.07.2010, 19:33
(
Last edited by ToPhrESH; 12/07/2010 at 10:00 PM.
)
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:
Now we will define the gTeam to set the teams from each other:
Now we've defined gTeam and our teams lets create the teams and their classes. Do this in:
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.
Now we must make the teamkill protection and timer. First lets make the timer. At the top of your script, again add
Now lets make the teamkill protecter. We will be editing here:
Under that add these lines:
Now we will create a public for the timer.
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:
No go back down to the timer used with public and add:
Now you are done. This is just a basic team kill system.
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"
pawn Code:
new gTeam[MAX_PLAYERS];
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.
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;
}
}
pawn Code:
forward TeamKill(); //This is a forward. It will wnable us to make the TeamKill() a public and create effects in the timer.
pawn Code:
public OnPlayerDeath(playerid, killerid, reason)
{
return 1;
}
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
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;
}
pawn Code:
forward TeamKill(playerid);//this is just making us able to use playerid in this timer
pawn Code:
public TeamKill(playerid)