18.12.2018, 20:49
How can I do so that Team 1 can not hurt Team 2? As if the two teams were one.
Players can not damage/kill players on the same team unless they use a knife to slit their throat. As of SA-MP 0.3x, players are also unable to damage vehicles driven by a player from the same team. This can be enabled with EnableVehicleFriendlyFire. |
public OnPlayerTakeDamage (playerid, issuerid, Float:amount, weaponid, bodypart) { //Do something }
native SetPlayerFaction(playerid, Faction: factionid) = SetPlayerTeam;
native Faction: GetPlayerFaction(playerid) = GetPlayerTeam;
new Team: gTeam[MAX_PLAYERS];
#define SetPlayerTeam(%0,%1) (gTeam[%0] = %1)
#define GetPlayerTeam(%0) gTeam[%0]
enum Faction {
F_NONE,
F_DEFEND, // T_PRESIDENT, T_BODYGUARD, T_POLICE
F_ATTACK, // T_TERRORIST
F_NEUTRAL // T_CIVILIAN
};
enum Team {
T_NONE,
T_PRESIDENT,
T_BODYGUARD,
T_POLICE,
T_TERRORIST,
T_CIVILIAN
};
// OnPlayerRequestClass
switch(classid) {
case 0: { // lets pretend this is the president class
SetPlayerFaction(playerid, F_DEFEND);
SetPlayerTeam(playerid, T_PRESIDENT);
}
// and so on
}
//Command
ShowPlayerDialog(playerid, Dialog_PTP, DIALOG_STYLE_LIST, "PTP - TEAMS", "President\nPolice\nTerrorist", "Select", "Close");
//OnDialogResponse
case Dialog_PTP:
{
if(response)
{
switch(listitem)
{
case 0:
{
SetPlayerTeam(playerid, Team_President); // team 0
new index = random(sizeof(Ptp_Pos[])), team = GetPlayerTeam(playerid);
SetPlayerPos(playerid, Ptp_Pos[team][index][0], Ptp_Pos[team][index][1], Ptp_Pos[team][index][2]);
SetPlayerFacingAngle(playerid, Ptp_Pos[team][index][3]);
//other codes
}
case 1:
{
SetPlayerTeam(playerid, Team_Police); // team 1
new index = random(sizeof(Ptp_Pos[])), team = GetPlayerTeam(playerid);
SetPlayerPos(playerid, Ptp_Pos[team][index][0], Ptp_Pos[team][index][1], Ptp_Pos[team][index][2]);
SetPlayerFacingAngle(playerid, Ptp_Pos[team][index][3]);
//other codes
}
case 2:
{
SetPlayerTeam(playerid, Team_Terrorist); // team 2
new index = random(sizeof(Ptp_Pos[])), team = GetPlayerTeam(playerid);
SetPlayerPos(playerid, Ptp_Pos[team][index][0], Ptp_Pos[team][index][1], Ptp_Pos[team][index][2]);
SetPlayerFacingAngle(playerid, Ptp_Pos[team][index][3]);
//other codes
}
}
}
return 1;
}
Does it mean that I should not use 'SetPlayerTeam' for each team?
This is what I have in my script, is it wrong?: |
native SetPlayerFaction(playerid, Faction: factionid) = SetPlayerTeam;
native Faction: GetPlayerFaction(playerid) = GetPlayerTeam;
new gTeam[MAX_PLAYERS];
#define SetPlayerTeam(%0,%1) (gTeam[%0] = %1)
#define GetPlayerTeam(%0) gTeam[%0]
// somewhere before your first usage
enum Faction {
Faction_Defend, // President, Police
Faction_Attack // Terrorist
};
//OnDialogResponse
case Dialog_PTP:
{
if(response)
{
switch(listitem)
{
case 0:
{
SetPlayerFaction(playerid, Faction_Defend);
SetPlayerTeam(playerid, Team_President);
//other codes
}
case 1:
{
SetPlayerFaction(playerid, Faction_Defend);
SetPlayerTeam(playerid, Team_Police);
//other codes
}
case 2:
{
SetPlayerFaction(playerid, Faction_Attack);
SetPlayerTeam(playerid, Team_Terrorist);
//other codes
}
}
}
return 1;
}
gTeam[playerid] = Team_Police;
SetPlayerTeam(playerid, Team_Defend);
SetPlayerPos(playerid, Ptp_Pos[ gTeam[playerid] ][index][0], Ptp_Pos[ gTeam[playerid] ][index][1], Ptp_Pos[ gTeam[playerid] ][index][2]);