[Tutorial] Make Teams and Anti Team-Kill (gTeam)
#1

Hi Guys I am New To Scripting
I am Making A Server I Wanted To Make Anti Team Kill I Tried to Find It On Internet But I Could Hardly Find It.
So I wanted To Share It
So Here It Is How It Comes
First Of All Define Teams
Code:
#define blue 0
#define red 1
#define green 2
#define yellow 3
#define blue_color 0x33CCFFAA
#define red_color 0xAA3333AA
#define green_color 0x12900BBF
#define yellow_color 0xFFFF00AA
Then Under #else type
Code:
new gTeam[MAX_PLAYERS];
Then Under public OnGameModeInit() Add Classes
Code:
public OnGameModeInit()
{	
        AddPlayerClass(287, 1382.8832,794.5979,10.8280,177.3541, 33, 1000, 24, 1000, 25, 1000);//blue
	AddPlayerClass(124, 754.6019,274.7502,27.3949,3.6705, 33, 1000, 24, 1000, 25, 1000);//Red
	AddPlayerClass(73, -468.3686,-91.8865,60.0957,348.3795, 33, 1000, 24, 1000, 25, 1000);//Green
	AddPlayerClass(117, 1019.3360,-287.2638,73.9931,178.4066, 33, 1000, 24, 1000, 25, 1000);//Yellow 
	return 1;
}
First One Is Skin Id "287" And "1382.8832,794.5979,10.8280,177.3541" Is Spawn Area Where The Team Player Will Spawn And Next Are Weapon ids and ammo

After That Come To public OnPlayerRequestClass(playerid, classid)
Code:
public OnPlayerRequestClass(playerid, classid)
{	
           if(classid == 0) {
	    SetPlayerSkin(playerid, 287); //skin for team blue
        GameTextForPlayer(playerid,"~B~Blue",1000,4);
	    SetPlayerColor(playerid, blue_color);//color for team blue
	    gTeam[playerid] = 1; //class 0 will be ally of class 1
 }
 	if(classid == 1) {
	    SetPlayerSkin(playerid, 124); //skin for team red
        GameTextForPlayer(playerid,"~R~Red",1000,4);//color for team red
	    SetPlayerColor(playerid, red_color);
	    gTeam[playerid] = 0; //class 1 will be ally of class 0
 }
	if(classid == 2) {
	    SetPlayerSkin(playerid, 73); //skin for team green
        GameTextForPlayer(playerid,"~G~Green",1000,4);
	    SetPlayerColor(playerid, green_color);//color for team green
	    gTeam[playerid] = 3;//class 2 will be ally of class 3
 }
 	if(classid == 3) {
	    SetPlayerSkin(playerid, 117); //skin for team yellow
        GameTextForPlayer(playerid,"~Y~Yellow",1000,4);
	    SetPlayerColor(playerid, yellow_color);//color for team yellow
	    gTeam[playerid] = 2;//class 3 will be ally of class 2
 }
	return 1;
}
We made Teams Now Lets Move To Anti Team Kill For It We Must Go To public OnPlayerSpawn(playerid)

Code:
public OnPlayerSpawn(playerid)
{    
        new Skin=GetPlayerSkin(playerid);
	switch(Skin)
	{
		case 287,117: //The Skins Which Will Be Ally
		{
			SetPlayerTeam(playerid,Blue);//Team Blue And Its Ally Like Blue And Red They Cant Kill Each Other
		}
		case 73,124: //The Skins Which Will Be Ally
		{
			SetPlayerTeam(playerid,Green);//Team Green And Its Ally Like Green And Yellow
		}
	}
	return 1;
}
Reply
#2

If There Is Any Mistake Please Tell Me
Reply
#3

A Small mistake , In the anti team attack , But good job anyway +Rep
Reply
#4

You could use OnPlayerShootPlayer https://sampforum.blast.hk/showthread.php?tid=195439

Code:
public OnPlayerShootPlayer(Shooter,Target,Float:HealthLost,Float:ArmourLost)
{
    if ( Shooter != INVALID_PLAYER_ID )
    {
        if ( GetPlayerTeam( Target ) == GetPlayerTeam( Shooter ) )
        {

            new Float:hp;
            GetPlayerHealth(Target, hp);
            SetPlayerHealth(Target, hp + HealthLost);
        }
    }
    return 1;
}
Reply
#5

Quote:
Originally Posted by K0UMA
View Post
You could use OnPlayerShootPlayer https://sampforum.blast.hk/showthread.php?tid=195439

Code:
public OnPlayerShootPlayer(Shooter,Target,Float:HealthLost,Float:ArmourLost)
{
    if ( Shooter != INVALID_PLAYER_ID )
    {
        if ( GetPlayerTeam( Target ) == GetPlayerTeam( Shooter ) )
        {

            new Float:hp;
            GetPlayerHealth(Target, hp);
            SetPlayerHealth(Target, hp + HealthLost);
        }
    }
    return 1;
}
If you checked in the link you gave it will say: EDIT 2013: THIS INCLUDE IS OLD AND OUTDATED! SA-MP HAS DEVELOPED NATIVE FUNCTIONS FOR THIS.

But there is a similar code to OnPlayerShootPlayer but better, you can see it in the wiki here.
Reply
#6

Why does one start every word with a capital letter? It makes one look either incredibly stupid or incredibly ignorant.

Pro tip: do not write tutorials if you are "new to scripting". If you write a tutorial you are saying: "I am qualified to write about this matter", but clearly you are not. Assumptions, duplicated code and the fact that SA-MP has this functionality built in (AddPlayerClassEx, GetPlayerTeam, SetPlayerTeam). You're not even using "gTeam" at all. You assign it a value, but then what?
Reply
#7

Quote:
Originally Posted by Vince
View Post
Why does one start every word with a capital letter? It makes one look either incredibly stupid or incredibly ignorant.

Pro tip: do not write tutorials if you are "new to scripting". If you write a tutorial you are saying: "I am qualified to write about this matter", but clearly you are not. Assumptions, duplicated code and the fact that SA-MP has this functionality built in (AddPlayerClassEx, GetPlayerTeam, SetPlayerTeam). You're not even using "gTeam" at all. You assign it a value, but then what?
Lowe the guy hes new Geez
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)