SetPlayerTeam(playerid, teamdi);
SetPlayerTeam(playerid, NO_TEAM);
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;
}
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;
}
EnableVehicleFriendlyFire();
public OnGameModeInit()
{
EnableVehicleFriendlyFire();
return 1;
}
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;
}
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(team, color, message[]);
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;
}
GameTextForTeam(team, message[], expiretime, style);
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;
}
CountTeamPlayers(team);
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;
}
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;
}
teamid - the team who will own the vehicle (players with only this teamid can drive the vehicle)
vehicletype - the model of the vehicle
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 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;
}
public OnGameModeExit()
{
DestroyVehicleForTeam(0);
DestroyVehicleForTeam(1);
DestroyVehicleForTeam(2);
DestroyVehicleForTeam(3);
return 1;
}
#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;
}
#include <streamer>
#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];
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!
}
basename - the base's name to be displayed
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!
}
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;
}
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;
}
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;
}
#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;
}
//------------------------
//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
}
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;
}
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.
|
Anti Team Vehicle Jack
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.
|
I haven't stated that it wont work, all i am curious about is Anti vehicle hit. Never tried it before.
|
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. |
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.
|
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.
|