Team System UPDATE: 5th March, 2015

* If you dont understand anything of this tutorial, have an awesome suggestion or need help regarding this, simply post down here in the Reply section.
* I have almost made a remastered version of this tutoril. All tested and build in proper way and a good scheme. Thanks to Ryz & Neufox for testing.

Content
Anti team attack
Ant team vehicle jack | IMPORTANT
Anti team vehicle hit
SendClientMessageForTeam(team, color, message[]);
GameTextForTeam (team, message[], expiretime, style);
CountTeamPlayers (team);
Team vehicles system
Team Bases
Anti Team Knifing | IMPORTANT

Anti Team Attack
For resisting team attacks or damage, simply use SAMP's team functions or system.

A simple function:
Code:
SetPlayerTeam(playerid, teamdi);
This will set the player's team to a specific team id. so all users with teamid 0 can damage each other.

For reseting player team or setting it to no team, use:
Code:
SetPlayerTeam(playerid, NO_TEAM);
Reset player's team so he/she can hit anyone!

Example:
Code:
public OnPlayerConnect(playerid)
{
SetPlayerTeam(playerid, 0);//this wil set the player team to 0, so all the players with teamid 0 can't hit or damage each other
return 1;
}

This system is to resist player to hit his own teammate by a gametext warning whenever they do so.
Whenever the player gives damage to someone, this callback is called.
In this we check if the player teams are identical, if so, we send them gametext warning.
Code:
public OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid, bodypart)
{
if( GetPlayerTeam(playerid) != NO_TEAM//if player is of a valid team
&& IsPlayerConnected(damagedid)//is the target connected
&& GetPlayerTeam(playerid) == GetPlayerTeam(damagedid))//if the team ids matches
{
GameTextForPlayer(playerid, "~r~Don't attack your Teammates", 3000, 3);//a warning gametext to player
return 0;//stop the damage and the action to be taken
}
return 1;
}
Now here, whenever anyone hits a teammember, he/she gets a message or warning. This can be used when a player is far sniping random players. To recognize its our team member, message system can be used.

Anti Team Vehicle Attack
Now lets make a vehicle damage system, This is how we will resist a teammate to shoot a teammate's vehicle by sending a gametext warning.!

Usage of SAMP's functions:
Code:
EnableVehicleFriendlyFire();
This enables no friendly damage, so you cant hit or damage your team vehicles.

Example:
Code:
public OnGameModeInit()
{
EnableVehicleFriendlyFire();
return 1;
}

This system is to resist team vehicle hit, actually shows a message.
First we check if the bullet has hit a vehicle. Further we loop through all connected player and get the driver id. Once we have the driverid, we check the teams and if they match, the player gets a gametext warning.
Code:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
if(hittype == BULLET_HIT_TYPE_VEHICLE)//if the bullet hits a vehicle
{
new target = INVALID_PLAYER_ID;//by default, an invalid player
for(new i; i < MAX_PLAYERS; i++)
{
if( i != playerid//if the loop case is not matching the playerid
&& IsPlayerConnected(i)//if the player is connected
&& GetPlayerVehicleID(i) == hitid//if the player is in vehicle that got hit
&& GetPlayerVehicleSeat(i) == 0)//if is driver
{
target = i;//store the playerid in "target" variable
break;//stop the loop and continue
}
}
if( target != INVALID_PLAYER_ID//if the target is not an invalid player
&& GetPlayerTeam(playerid) != NO_TEAM//if target id is having a valid team
&& GetPlayerTeam(playerid) == GetPlayerTeam(target))//if the target player is having same team id that of the shooter
{
GameTextForPlayer(playerid, "~r~Don't attack a Team vehicle", 3000, 3);//a warning gametext to player
return 0;//stop the vehicle to get damage and the action to be taken
}
}
return 1;
}

Anti Team Vehicle Jack
This is a simple method to stop players to jack team vehicles. I have used ClearAnimations and SetPlayerPos for stopping the action. This is as usually done in callback OnPlayerEnterVehicle.

This code dont work for passegers. Here we loop through all player for detecting the driver with some several checks within. Once we have our id, we break the loop and check if the team of the driver(target) is identical to that of player. If so, no action is taken and the player simply gets a jerk.
Code:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
if(! ispassenger)//if the player is entering as a driver
{
new target = INVALID_PLAYER_ID;//by default, an invalid player
for(new i; i < MAX_PLAYERS; i++)
{
if( i != playerid//if the loop case is not matching the playerid
&& IsPlayerConnected(i)//if the player is connected
&& GetPlayerVehicleID(i) == vehicleid//if the player is in vehicle that got hit
&& GetPlayerVehicleSeat(i) == 0)//if is driver
{
target = i;//store the playerid in "target" variable
break;//stop the loop and continue
}
}
if( target != INVALID_PLAYER_ID//if the target is not an invalid player
&& GetPlayerTeam(playerid) != NO_TEAM//if target id is having a valid team
&& GetPlayerTeam(playerid) == GetPlayerTeam(target))//if the target player is having same team id that of the shooter
{
ClearAnimations(playerid);//clear all animations of player that were being runned

new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);//store player position coords
SetPlayerPos(playerid, x, y, z+5);//a sort of eject system, simply sets player height!

GameTextForPlayer(playerid, "~r~Don't jack your Team vehicle", 3000, 3);//a warning gametext to player
return 0;//stop the player to take over the vehicle and the action to be taken
}
}
return 1;
}

SendClientMessageForTeam
Code:
SendClientMessageForTeam(team, color, message[]);
- team: the team id to whom the message is to sent
- color: client message color
- message: the message, its a string

Returns: true

Source:
Code:
stock SendClientMessageForTeam(team, color, message[])
{
for(new i; i < MAX_PLAYERS; i++)
{
if( IsPlayerConnected(i)//if player is connected
&& GetPlayerTeam(i) == team)//if team id matches
{
SendClientMessage(i, color, message);//message sent
}
}
return 1;
}

Usage:
Send client message to all players having the specified team id.

GameTextForTeam
Code:
GameTextForTeam(team, message[], expiretime, style);
- team: the team id to whom the message is to sent
- message: the message, its a string
- expiretime: the amount of time after the message will disappear
- style: the font style, same of the gametext

Returns: true;

Source:
Code:
stock GameTextForTeam(team, message[], expiretime, style)
{
for(new i; i < MAX_PLAYERS; i++)
{
if( IsPlayerConnected(i)//if player is connected
&& GetPlayerTeam(i) == team)//if team id matches
{
GameTextForPlayer(i, message, expiretime, style);//gamttext sent
}
}
return 1;
}

Usage:
Send game text message to all players having the specified team id.

CountTeamPlayers
Code:
CountTeamPlayers(team);
- team: the team id to whom the message is to sent

Returns: integer, number of players with the specified teamid

Source:
Code:
stock CountTeamPlayers(team)
{
new count;
for(new i; i < MAX_PLAYERS; i++)
{
if( IsPlayerConnected(i)//if player is connected
&& GetPlayerTeam(i) == team)//if team id matches
{
count++;//add one to the count
}
}
return count;
}

Usage:
Count total players having the specified team id. Can be used in team balancing system.

Team Vehicles
Vehicles that can be only accessed by a specific team member. The enemies can take out and jack or sit as passenger but can't drive!

Now first we need to add enum to store create team vehicles data.
Code:
enum team_vehicle_info
{
v_id,//the vehicle id
v_team,//the vehicle's team id
bool:v_exist//boolean to check if vehicle exists
}
new team_vehicle[ MAX_VEHICLES][ team_vehicle_info ];
Here MAX_VEHICLES is a samp's macro, This is the maximum limit of vehicles in server. You can also set the value your self by redefining the macro!

For reseting the enum, we use:
Code:
main()
{
for(new slot; slot < MAX_VEHICLES; slot++)
{
team_vehicle[slot][v_id] = -1;//set to invalide vehicle model id
team_vehicle[slot][v_team] = NO_TEAM;//set for NO_TEAM
team_vehicle[slot][v_exist] = false;//the vehicle don't exist
}
}

Now lets create a function or stock function so we can very easily create a team vehicle.
Code:
stock CreateVehicleForTeam(teamid, vehicletype, Float:x, Float:y, Float:z, Float:rotation, color1, color2, respawn_delay)
{
if(teamid == NO_TEAM) return false; // if the vehicle teamid is NO_TEAM(255), then this function won't work
for(new slot; slot < MAX_VEHICLES; slot++)
{
if(team_vehicle[slot][v_exist] == false)//checks if the vehicle is not created, then only proceed or else catch another loop case!
{
//creat the main vehicle and store its id
team_vehicle[slot][v_id] = CreateVehicle(vehicletype, x, y, z, rotation, color1, color2, respawn_delay);

team_vehicle[team_vehicle[slot][v_id]][v_team] = teamid;//storing the teamid
team_vehicle[team_vehicle[slot][v_id]][v_exist] = true;//setting created value "yes", so this says that the vehicle is created!

return team_vehicle[slot][v_id];//returns the vehicle id
}
}
return true;
}
Params note:
Code:
teamid - the team who will own the vehicle (players with only this teamid can drive the vehicle)
vehicletype - the model of the vehicle

Now lets create a destry vehicle stock function, this is necessary because we need to reset the arrays too! Here we destroy the vehicle and reset the data as INVALID.
Code:
stock DestoryVehicleForTeam(vehicleid)
{
DestroyVehicle(vehicleid);//destorying the vehicle
team_vehicle[vehicleid][v_team] = NO_TEAM;//set for NO_TEAM
team_vehicle[vehicleid][v_exist] = false;//the vehicle don't exist
return true;
}

Ok, lets implement these functions in your script. You can use these stock functions anywhere in your script. Currently i am creating team vehicles in OnGameModeInit callback.
Code:
public OnGameModeInit()
{
CreateVehicleForTeam(0, 413, 327.8443, -1809.2729, 4.5733, 359.3342, 91, 1, 0);//team vehicle for teamid 0
CreateVehicleForTeam(0, 467, 740.4370, -1793.5476, 12.9180, 349.2087, 58, 8, 0);//team vehicle for teamid 0
CreateVehicleForTeam(1, 473, 823.7594, -2066.2686, -0.1017, 112.6381, 56, 53,0);//team vehicle for teamid 1
CreateVehicleForTeam(1, 467, 892.0507, -1797.3351, 13.4070, 175.4098, 60, 1, 0);//team vehicle for teamid 1
return 1;
}

Now lets make the main function, Not letting other team players enter other team cars. Its quiet simple, here we first loop through all vehicles and then check if its a team vehicle. Further we check players team is matching with the vehicle's team. If so, the player is allowed to drive else removed.
Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)//Player entered a vehicle as a driver
{
new vehicleid = GetPlayerVehicleID(playerid);
for(new slot; slot < MAX_VEHICLES; slot++)
{
if(team_vehicle[slot][v_exist] && vehicleid == team_vehicle[slot][v_id])//if vehicle is a team vehicle!
{
if(GetPlayerTeam(playerid) != team_vehicle[slot][v_team])//if team id don't matches
{
RemovePlayerFromVehicle(playerid);//remove the player from vehicle
GameTextForPlayer(playerid, "~r~You can't enter enemie's vehicle", 3000, 3);//send the player a message
break;
}
}
}
}
return 1;
}
A message will appear that the player can't enter a enemy's vehicle.

NOTE: Don't forget to destroy a team vehicle at GameModeExit.
Code:
public OnGameModeExit()
{
DestroyVehicleForTeam(0);
DestroyVehicleForTeam(1);
DestroyVehicleForTeam(2);
DestroyVehicleForTeam(3);
return 1;
}

Full code:
Code:
#include <a_samp>

enum team_vehicle_info
{
v_id,//the vehicle id
v_team,//the vehicle's team id
bool:v_exist//boolean to check if vehicle exists
}
new team_vehicle[ MAX_VEHICLES ][ team_vehicle_info ];

main()
{
for(new slot; slot < MAX_VEHICLES; slot++)
{
team_vehicle[slot][v_id] = -1;//set to invalide vehicle model id
team_vehicle[slot][v_team] = NO_TEAM;//set for NO_TEAM
team_vehicle[slot][v_exist] = false;//the vehicle don't exist
}
}

stock CreateVehicleForTeam(teamid, vehicletype, Float:x, Float:y, Float:z, Float:rotation, color1, color2, respawn_delay)
{
if(teamid == NO_TEAM) return false; // if the vehicle teamid is NO_TEAM(255), then this function won't work
for(new slot; slot < MAX_VEHICLES; slot++)
{
if(team_vehicle[slot][v_exist] == false)//checks if the vehicle is not created, then only proceed or else catch another loop case!
{
//creat the main vehicle and store its id
team_vehicle[slot][v_id] = CreateVehicle(vehicletype, x, y, z, rotation, color1, color2, respawn_delay);

team_vehicle[team_vehicle[slot][v_id]][v_team] = teamid;//storing the teamid
team_vehicle[team_vehicle[slot][v_id]][v_exist] = true;//setting created value "yes", so this says that the vehicle is created!

return team_vehicle[slot][v_id];//returns the vehicle id
}
}
return true;
}

stock DestoryVehicleForTeam(vehicleid)
{
DestroyVehicle(vehicleid);//destorying the vehicle
team_vehicle[vehicleid][v_team] = NO_TEAM;//set for NO_TEAM
team_vehicle[vehicleid][v_exist] = false;//the vehicle don't exist
return true;
}

public OnGameModeInit()
{
CreateVehicleForTeam(0, 413, 327.8443, -1809.2729, 4.5733, 359.3342, 91, 1, 0);//team vehicle for teamid 0
CreateVehicleForTeam(0, 467, 740.4370, -1793.5476, 12.9180, 349.2087, 58, 8, 0);//team vehicle for teamid 0
CreateVehicleForTeam(1, 473, 823.7594, -2066.2686, -0.1017, 112.6381, 56, 53,0);//team vehicle for teamid 1
CreateVehicleForTeam(1, 467, 892.0507, -1797.3351, 13.4070, 175.4098, 60, 1, 0);//team vehicle for teamid 1
return 1;
}

public OnGameModeExit()
{
DestoryVehicleForTeam(0);
DestoryVehicleForTeam(1);
DestoryVehicleForTeam(2);
DestoryVehicleForTeam(3);
return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)//Player entered a vehicle as a driver
{
new vehicleid = GetPlayerVehicleID(playerid);
for(new slot; slot < MAX_VEHICLES; slot++)
{
if(team_vehicle[slot][v_exist] && vehicleid == team_vehicle[slot][v_id])//if vehicle is a team vehicle!
{
if(GetPlayerTeam(playerid) != team_vehicle[slot][v_team])//if team id don't matches
{
RemovePlayerFromVehicle(playerid);//remove the player from vehicle
GameTextForPlayer(playerid, "~r~You can't enter other team's vehicle", 3000, 3);//send the player a message
break;
}
}
}
}
return 1;
}

Team Bases
Team base, this part contains team based gangzones. So whenever a player enters the base, a gametext will appear with the base name.
Its pretty simple to make a team base with certain stuff of samp, like gangzones, vehicles and objects. Now we will discuss making a team base with gangzones.

To create a gangzone, we must get a in-game gangzone maker. Here is a in game gangzone maker http://forum.sa-mp.com/showthread.php?t=311553 by Lorenc_.

After we have our gangzone coordinates. Now let make a team base using it.

We need streamer plugin http://forum.sa-mp.com/showthread.php?t=102865 by Incognito. So add this on the top of your script.
Code:
#include <streamer>

We will now add an enum to store the data. We have also made a macro MAX_BASES which will help us in loop through all bases.loop. Just enter the maximum number of bases your script will have into the macro.
Code:
#define MAX_BASES 2//set how many team bases your server may have, this is the maximum limit

enum baseinfo
{
b_base,//this array store the main gangzone
b_dynamic//this array stores dynamic area
b_name[25]
}
new team_base[MAX_TEAMS][baseinfo];

Now lets create a stock function to create a team base, this will make us easy to add a team base just like we made a team vehicle! Here is the function:
Code:
stock CreateTeamBase(basename[25], Float:minx, Float:miny, Float:maxx, Float:maxy)
{
for(new baseid; baseid < MAX_BASES; baseid++)//loop created, we must loop through max bases and check which slot is empty in increasing order!
{
if(! IsValidDynamicArea(team_base[baseid][b_dynamic]))//an smart check if the dynamic area is created. If not, means the base is not created! So we continue
{
team_base[baseid][b_base] = GangZoneCreate(minx, miny, maxx, maxy);//this creates the main gangzone
team_base[baseid][b_dynamic] = CreateDynamicRectangle(minx, miny, maxx, maxy);//this is the dynamic area, its imaginary but used to display base names!
team_base[baseid][b_name] = basename;
return baseid;//return the base's id, so we can perform all the functions over it
}
}
return -1;//this will come up if the base wasn't created!
}
Param Note:
Code:
basename - the base's name to be displayed

After this we need to code to destroy the base too, So get this in your code involved! We simply destroy dynamic area as well as the gangzone.
Code:
stock DestoryTeamBase(baseid)
{
if(IsValidDynamicArea(team_base[baseid][b_dynamic]))//an smart check if the dynamic area is created, if yes, we continue!
{
GangZoneDestory(team_base[baseid][b_base]);//this destorys the main gangzone
DestroyDynamicRectangle(team_base[baseid][b_dynamic]);//this is the dynamic area, DESTROYED IN SECONDS!
return true;//success
}
return false;//un successfull!
}

Now we are done 85%. These were the main functions. Now making the zone names system, we must make use of dynamic zones/areas. So we edit this callback:
This callback is called when you enter a dynamic area, indirectly a base. Here we loop through all bases and detect the player's base in which he is in!
Code:
public OnPlayerEnterDynamicArea(playerid, areaid)
{
for(new baseid; baseid < MAX_BASES; baseid++)
{
if(areaid == team_base[baseid][b_dynamic])
{
GameTextForPlayer(playerid, team_base[baseid][b_name], 5000, 1);//gives a gametext message displaying the base name!
break;
}
}
return 1;
}
We are done 100%. Now make your team bases with a display name. Whenever you enter a team base, the base name will be displayed in Gametext.

Now for performing our gangzone functions on base, we can get base's gangzone:
Code:
stock ReturnBaseGangZone(baseid)
{
if(IsValidDynamicArea(team_base[baseid][b_dynamic]))//an smart check if the dynamic area is created, if yes, we continue!
{
return team_base[baseid][b_base];
}
return -1;
}
This will return the gangzone id of the base. Reading from the baseid. For example you create a base and it returns you id 0. So for getting the gangzone id of the base, we use this function.

Now create a base in GameModeInit(recommended) or other places. Note, with a variable to store its id, so that we can perform gangzone functions on the base.
Example:
Code:
new base;//this is just a example variable in which we will store base id

public OnGameModeInit()
{
base = CreateTeamBase("~r~test ~h~base", 1248.011, 2072.804, 1439.348, 2204.319);//just example
return 1;
}
Now the base is created and the baseid is stored in the var base.

Now after creating the base we can use SAMP gangzone functions on the base, read: http://wiki.sa-mp.com/wiki/GangZoneShowForPlayer.
For example: Showing the main base's gangzone to the player.
Code:
public OnPlayerSpawn(playerid)
{
GangZoneShowForPlayer(playerid, ReturnBaseGangZone(base), 35643); //this will show the player the stored base with the specified color
return 1;
}

Full code:
Code:
#include <a_samp>

#define MAX_BASES 2//set how many team bases your server may have, this is the maximum limit

enum baseinfo
{
b_base,//this array store the main gangzone
b_dynamic,//this array stores dynamic area
b_name[25]
}
new team_base[MAX_BASES][baseinfo];

stock CreateTeamBase(basename[25], Float:minx, Float:miny, Float:maxx, Float:maxy)
{
for(new baseid; baseid < MAX_BASES; baseid++)//loop created, we must loop through max bases and check which slot is empty in increasing order!
{
if(! IsValidDynamicArea(team_base[baseid][b_dynamic]))//an smart check if the dynamic area is created. If not, means the base is not created! So we continue
{
team_base[baseid][b_base] = GangZoneCreate(minx, miny, maxx, maxy);//this creates the main gangzone
team_base[baseid][b_dynamic] = CreateDynamicRectangle(minx, miny, maxx, maxy);//this is the dynamic area, its imaginary but used to display base names!
team_base[baseid][b_name] = basename;
return baseid;//return the base's id, so we can perform all the functions over it
}
}
return -1;//this will come up if the base wasn't created!
}

stock DestoryTeamBase(baseid)
{
if(IsValidDynamicArea(team_base[baseid][b_dynamic]))//an smart check if the dynamic area is created, if yes, we continue!
{
GangZoneDestory(team_base[baseid][b_base]);//this destorys the main gangzone
DestroyDynamicRectangle(team_base[baseid][b_dynamic]);//this is the dynamic area, DESTROYED IN SECONDS!
return true;//success
}
return false;//un successfull!
}

stock ReturnBaseGangZone(baseid)
{
if(IsValidDynamicArea(team_base[baseid][b_dynamic]))//an smart check if the dynamic area is created, if yes, we continue!
{
return team_base[baseid][b_base];
}
return -1;
}

public OnPlayerEnterDynamicArea(playerid, areaid)
{
for(new baseid; baseid < MAX_BASES; baseid++)
{
if(areaid == team_base[baseid][b_dynamic])
{
GameTextForPlayer(playerid, team_base[baseid][b_name], 5000, 1);//gives a gametext message displaying the base name!
break;
}
}
return 1;
}

//------------------------
//EXAMPLE
new base;//this is just a example variable in which we will store base id

public OnGameModeInit()
{
base = CreateTeamBase("~r~test ~h~base", 1248.011, 2072.804, 1439.348, 2204.319);//just example
return 1;
}

public OnPlayerSpawn(playerid)
{
GangZoneShowForPlayer(playerid, ReturnBaseGangZone(base), 35643); //this will show the player the stored base with the specified color
return 1;
}
//------------------------

Anti Team Knifing
Hello this is a very important part for your team deathmatch server. Actually this avoids team mates to stabb their own team mates. This can prevent desyncing of players through knifing.
This method actually checks for animation and some range and target checks for detecting that wheather the checks are not fake!

Now lets make a simple sync system.
Here i actually change the player virtual world(+1) to stream everything out and then set to spectating so as to change the state. After the code, i instantly reset everything.
Code:
//synchronize system, not 100% !!
stock SyncPlayer(playerid)
{
new world = GetPlayerVirtualWorld(playerid);//store player virtual world in var

TogglePlayerSpectating(playerid, true);//set player to spectate mode, this will refresh the player state, actually make a change!

SetPlayerVirtualWorld(playerid, world + 1);//changing the world id

TogglePlayerSpectating(playerid, false);//now lets take him back, this wil set player state to default one!

SetPlayerVirtualWorld(playerid, world);//set the default world
return true;//sucess
}

Now after creating the sync function, we must add a check if the player is knifing then do our stuff!
We will understànd this in steps.
1. First we check if the player have a knife, armed
2. Second we detect if the player have identical animations that of stabbing with a knife
3. We check if the target(one being stabbed) is connected
4. We check for range between them
5. Last, we check if both are of same teams
6. If all those conditions satisfy, we return 0 and sync the target player and clear the attacckers animations.
Code:
public OnPlayerUpdate(playerid)
{
if(GetPlayerWeapon(playerid) == 4)//if the player have a knife
{
if(GetPlayerAnimationIndex(playerid) != 0)//if an animation is being run over
{
new animation[2][35];//variable where we will store animation data
GetAnimationName(GetPlayerAnimationIndex(playerid) , animation[0], 35, animation[1], 35);//getting the animation data

if( !strcmp(animation[0], "KNIFE", true)//if player is having animation from "KNIFE@" library
&& !strcmp(animation[1], "KILL_Knife_Player", true))//if the animation is "stabbing" knife animation
{
new target = GetPlayerTargetPlayer(playerid);//get the player target, the one who is going to get stabbed

if(IsPlayerConnected(target))//if the target player is connected, then proceed
{
new Float:x, Float:y, Float:z;
GetPlayerPos(target, x, y, z);//store player position data in FLOATING variables

if(IsPlayerInRangeOfPoint(playerid, 5.0, x, y, z))//an aditional check if the player is in range so that false detects or animations are not detected! You can set the range accordingly!
{
if(GetPlayerTeam(playerid) == GetPlayerTeam(target))//if the target's team is same that of player, then proceed
{
ClearAnimations(playerid);//clear player animations

GetPlayerPos(playerid, x, y, z);//store player position coords
SetPlayerPos(playerid, x, y, z+5);//a sort of eject system, simply sets player height!

GameTextForPlayer(playerid, "~r~Don't knife your Teammates", 3000, 3);//a warning gametext to player

SyncPlayer(target);//sync the target who got stabbed! This is not 100% sure system, maybe the desync is still there!
return 0;
}
}
}
}
}
}
return 1;
}

Changelog
7 January, 2015
Added Anti team attack
Added anti team vehicle hit
Added anti team vehicle jack
Function SendClientMessageForTeam
Function GameTextForTeam
Function CountTeamPlayers

9 January, 2015
Added Team Vehicles system
Added Team Bases system

10 January, 2015
Fixed Anti team vehicle jack
Fixed anti Team vehicle hit
Added Anti Team knifing

26 January, 2015
Added Synchronize system in Anti Team knifing

5th March, 2015
Improved some issues with team bases
Added more content, necessary explainations