[Tutorial] Team System (avoid team abuses and some functions)
#1

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:
pawn 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:
pawn Code:
SetPlayerTeam(playerid, NO_TEAM);
Reset player's team so he/she can hit anyone!

Example:
pawn 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.
pawn 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:
pawn Code:
EnableVehicleFriendlyFire();
This enables no friendly damage, so you cant hit or damage your team vehicles.

Example:
pawn 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.
pawn 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.
pawn 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
pawn 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:
pawn 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
pawn 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:
pawn 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
pawn Code:
CountTeamPlayers(team);
- team: the team id to whom the message is to sent

Returns: integer, number of players with the specified teamid

Source:
pawn 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.
pawn 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:
pawn 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.
pawn 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:
pawn 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.
pawn 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.
pawn 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.
pawn 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.
pawn Code:
public OnGameModeExit()
{
    DestroyVehicleForTeam(0);
    DestroyVehicleForTeam(1);
    DestroyVehicleForTeam(2);
    DestroyVehicleForTeam(3);
    return 1;
}
Full code:
pawn 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 https://sampforum.blast.hk/showthread.php?tid=311553 by Lorenc_.

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

We need streamer plugin https://sampforum.blast.hk/showthread.php?tid=102865 by Incognito. So add this on the top of your script.
pawn 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.
pawn 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:
pawn 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:
pawn 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.
pawn 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!
pawn 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:
pawn 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:
pawn 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: https://sampwiki.blast.hk/wiki/GangZoneShowForPlayer.
For example: Showing the main base's gangzone to the player.
pawn 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:
pawn 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.
pawn 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.
pawn 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
Reply
#2

Quote:
Originally Posted by ginger
View Post
I hope this helped you people, i haven't tested this, so any bugs or errors, try reporting. Any suggestions, reply here! The reason i haven't tested this because my GTA SA is missing! I lost it.
If you can't test it, then don't post it. People try to learn something from your code. If you can't assure them that it's working, then it's probably useless to them.

Also, when you make a tutorial, try to explain things. Why do you do it the way you do it... Explain the code step by step.
Reply
#3

Does this part really works?

pawn Code:
Anti Team Vehicle Jack
Reply
#4

Quote:
Originally Posted by Henkie
View Post
If you can't test it, then don't post it. People try to learn something from your code. If you can't assure them that it's working, then it's probably useless to them.
I haven't stated that it wont work, all i am curious about is Anti vehicle hit. Never tried it before.

Quote:
Originally Posted by Henkie
View Post
Also, when you make a tutorial, try to explain things. Why do you do it the way you do it... Explain the code step by step.
Explain things more, ahh that useless phrase people comment, try to explain your explanations, try posting the bugs or ways to improve my code instead just saying "Explain more"!

Step by step, well you must read the quoted pawn code, i have explained the steps i took. Also given the links to understand the callbacks.

@Edit:
Quote:
Originally Posted by Ryz
View Post
Does this part really works?

pawn Code:
Anti Team Vehicle Jack
Yes!
Reply
#5

Quote:
Originally Posted by ginger
View Post
I haven't stated that it wont work, all i am curious about is Anti vehicle hit. Never tried it before.
Ok, so you make a tutorial to teach people something about coding. In this case: A team system. Now you're stating that you never tried it yourself. How can you teach other people something when you don't know it yourself?

Quote:
Originally Posted by ginger
View Post
Explain things more, ahh that useless word people comment, try to explain your explanations, try posting the bugs or ways to improve my code instead just saying "Explain more"!

Step by step, well you must read the quoted pawn code, i have explained the steps i took. Also given the links to understand the callbacks.
You should try to teach people something about your way of thinking when you're making such a code. Just putting some quick commentary in your code and giving some links won't teach them your way of thinking.

It's just a tip, but it might help you when you make another tutorial.
Reply
#6

Quote:
Originally Posted by Henkie
View Post
Ok, so you make a tutorial to teach people something about coding. In this case: A team system. Now you're stating that you never tried it yourself. How can you teach other people something when you don't know it yourself?



You should try to teach people something about your way of thinking when you're making such a code. Just putting some quick commentary in your code and giving some links won't teach them your way of thinking.

It's just a tip, but it might help you when you make another tutorial.
I may figure out this tutorial, (that ain't commentary). What else i must explain, thats the point.
Reply
#7

Quote:
Originally Posted by ginger
View Post
I may figure out this tutorial, (that ain't commentary). What else i must explain, thats the point.
First of all, make sure that your code is working. If it's working, you can explain for example why you're using the functions, what the loop does, what && means and so on..
Reply
#8

Thanks, those patches are quiet useful, +1.
Reply
#9

SetPlayerTeam disables friendly fire. I'm not even sure if it calls any of the damage callbacks at all. EnableVehicleFriendlyFire can do the same for vehicles.
Reply
#10

Quote:
Originally Posted by Vince
View Post
SetPlayerTeam disables friendly fire. I'm not even sure if it calls any of the damage callbacks at all. EnableVehicleFriendlyFire can do the same for vehicles.
I never knew vehicle friendly fire function. All i made this for is the servers which dont have friendly fire disabled.
I know SetPlayerTeam resists friendly fire but this makes difference, such for an example you are with a sniper rifle far located and shooting players. So if the name tags arent visible, gametext message helps to locate teammates.
Reply
#11

Amazing, the SyncPlayer works perfect.
+1
Reply
#12

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

Check the thread for source.
Reply
#13

Good work, quiet well explained this time.
Reply
#14

Anti team knifing can be detected in OnPlayerTakeDamage. But i doubt for fake checks or even server using custom damage!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)