SA-MP Forums Archive
[Tutorial] Make Teams and Anti Team-Kill (gTeam) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Make Teams and Anti Team-Kill (gTeam) (/showthread.php?tid=577789)



Make Teams and Anti Team-Kill (gTeam) - Gokhan152 - 14.06.2015

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;
}



Re: Make Teams and Anti Team-Kill (gTeam) - Gokhan152 - 17.06.2015

If There Is Any Mistake Please Tell Me


Re: Make Teams and Anti Team-Kill (gTeam) - MichaelJones - 25.06.2015

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


Re: Make Teams and Anti Team-Kill (gTeam) - K0UMA - 26.06.2015

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;
}



Re: Make Teams and Anti Team-Kill (gTeam) - Youssef221 - 26.06.2015

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.


Re: Make Teams and Anti Team-Kill (gTeam) - Vince - 26.06.2015

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?


Re: Make Teams and Anti Team-Kill (gTeam) - Joron - 15.12.2015

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