SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 18/12/2018, 08:49 PM   #1
SapMan
Banned
 
Join Date: Jul 2017
Posts: 140
Reputation: 12
Default Teams

How can I do so that Team 1 can not hurt Team 2? As if the two teams were one.
SapMan is offline   Reply With Quote
Old 18/12/2018, 11:00 PM   #2
SapMan
Banned
 
Join Date: Jul 2017
Posts: 140
Reputation: 12
Default Re: Teams

someone?
SapMan is offline   Reply With Quote
Old 19/12/2018, 03:10 AM   #3
Threshold
High-roller
 
Threshold's Avatar
 
Join Date: Nov 2012
Location: Australia
Posts: 3,122
Reputation: 529
Default Re: Teams

Set them to the same team.

http://wiki.sa-mp.com/wiki/SetPlayerTeam

Quote:
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.
__________________


Kar's Cops and Robbers 2020
Threshold is offline   Reply With Quote
Old 19/12/2018, 02:55 PM   #4
SapMan
Banned
 
Join Date: Jul 2017
Posts: 140
Reputation: 12
Default Re: Teams

That's what I do not want, I want to do that only damage can not be done. I do not want to put them on the same team.

I know it's possible, if it were not possible, how do they do on the servers "protect the president" that I played? In which the minitro, the vice president, security, swat, president, etc. They can not hurt themselves.
SapMan is offline   Reply With Quote
Old 19/12/2018, 03:24 PM   #5
Osamakurdi
Big Clucker
 
Join Date: Mar 2017
Location: Syria
Posts: 193
Reputation: 19
Default Re: Teams

I think that what are you trying to find ?
Code:
public OnPlayerTakeDamage (playerid, issuerid, Float:amount, weaponid, bodypart)
{
    //Do something
}
You will take the issuerid and check if he is from team1 and check if playerid(who took the shot) from team2
If this statement is true you will set the playerid's health to 100(or his health before shot).
__________________
(( لا تقسروا اولادكم على ادابكم فانهم مخلوقون لزمان غير زمانكم ))

((Do not oppress your children to your literature, they are created for a time other than your time))
Osamakurdi is offline   Reply With Quote
Old 19/12/2018, 05:49 PM   #6
Nero_3D
High-roller
 
Nero_3D's Avatar
 
Join Date: Jun 2007
Location: Germany
Posts: 2,852
Reputation: 675
Default Re: Teams

Like Threshold said, you should use SetPlayerTeam but not for the "teams" itself but for the factions who can't damage each other
For the teams itself, you need to use an additional array
Something like that
PHP Code:
native SetPlayerFaction(playeridFactionfactionid) = SetPlayerTeam;
native FactionGetPlayerFaction(playerid) = GetPlayerTeam;

new 
TeamgTeam[MAX_PLAYERS];

#define SetPlayerTeam(%0,%1) (gTeam[%0] = %1)
#define GetPlayerTeam(%0) gTeam[%0] 
Example PTP:

PHP Code:
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(playeridF_DEFEND);
        
SetPlayerTeam(playeridT_PRESIDENT);
    }
    
// and so on

Nero_3D is offline   Reply With Quote
Old 19/12/2018, 10:18 PM   #7
SapMan
Banned
 
Join Date: Jul 2017
Posts: 140
Reputation: 12
Default Re: Teams

Ok.. But how do I do so that the police can not harm the president (who belongs to another team)?

If you choose the president team, then it will be SetPlayerTeam (playerid, Team_President);

and if you choose the police team, then it will be SetPlayerTeam (playerid, Team_Police); Therefore, there are 2 different teams and at the moment of shooting they will damage themselves.

If you have ever played "protect the president" you will see that the police team is blue and have their own spawn apart, and the president's team is white and have their own spawn and different from the police. But when they shoot at each other, no harm is done, and that's why I think putting them on the same team is going to wrap the whole script around the separate positions, colors and weapons.

I really need a little help with this, or a good clarification on how to do it.
SapMan is offline   Reply With Quote
Old 20/12/2018, 02:16 AM   #8
Threshold
High-roller
 
Threshold's Avatar
 
Join Date: Nov 2012
Location: Australia
Posts: 3,122
Reputation: 529
Default Re: Teams

Unless your script specifically uses 'GetPlayerTeam' to define what team or faction a player is using, then you won't have any issues. You need to mentally unassign 'SetPlayerTeam' being tied with the player's actual team.

You are linking SetPlayerTeam with the faction they've chosen, which is untrue. It does not correspond to their choice of faction at all despite it changing their 'Team'. This is an illusion in your mind that you need to work around.

Nero_3D has given you a perfect example of how to accomplish this. Read over his post again, slowly, until you work out a solution.
__________________


Kar's Cops and Robbers 2020
Threshold is offline   Reply With Quote
Old 20/12/2018, 05:43 PM   #9
SapMan
Banned
 
Join Date: Jul 2017
Posts: 140
Reputation: 12
Default Re: Teams

Does it mean that I should not use 'SetPlayerTeam' for each team?

This is what I have in my script, is it wrong?:

PHP Code:
//Command

ShowPlayerDialog(playeridDialog_PTPDIALOG_STYLE_LIST"PTP - TEAMS""President\nPolice\nTerrorist""Select""Close");

//OnDialogResponse

case Dialog_PTP:
{
    if(
response)
    {
        switch(
listitem)
        {
            case 
0:
            {
                
SetPlayerTeam(playeridTeam_President); // team 0
            
                
new index random(sizeof(Ptp_Pos[])), team GetPlayerTeam(playerid);
                
SetPlayerPos(playeridPtp_Pos[team][index][0], Ptp_Pos[team][index][1], Ptp_Pos[team][index][2]);
                
SetPlayerFacingAngle(playeridPtp_Pos[team][index][3]);
                
                
//other codes
            
}
            case 
1:
            {
                
SetPlayerTeam(playeridTeam_Police); // team 1
                
                
new index random(sizeof(Ptp_Pos[])), team GetPlayerTeam(playerid);
                
SetPlayerPos(playeridPtp_Pos[team][index][0], Ptp_Pos[team][index][1], Ptp_Pos[team][index][2]);
                
SetPlayerFacingAngle(playeridPtp_Pos[team][index][3]);
                
                
//other codes
            
}
            case 
2:
            {
                
SetPlayerTeam(playeridTeam_Terrorist); // team 2
                
                
new index random(sizeof(Ptp_Pos[])), team GetPlayerTeam(playerid);
                
SetPlayerPos(playeridPtp_Pos[team][index][0], Ptp_Pos[team][index][1], Ptp_Pos[team][index][2]);
                
SetPlayerFacingAngle(playeridPtp_Pos[team][index][3]);
                
                
//other codes
            
}
        }
    }
    return 
1;

SapMan is offline   Reply With Quote
Old 20/12/2018, 06:03 PM   #10
Nero_3D
High-roller
 
Nero_3D's Avatar
 
Join Date: Jun 2007
Location: Germany
Posts: 2,852
Reputation: 675
Default Re: Teams

Quote:
Originally Posted by SapMan View Post
Does it mean that I should not use 'SetPlayerTeam' for each team?

This is what I have in my script, is it wrong?:
It is not wrong if you only have teams but in your case we need teams and factions (several teams grouped together)

Just put these 5 lines in an include files and include it or put them before the first SetPlayerTeam / GetPlayerTeam in your code
This code simply defines SetPlayerFaction and GetPlayerFaction, nothing more nothing less
PHP Code:
native SetPlayerFaction(playeridFactionfactionid) = SetPlayerTeam;
native FactionGetPlayerFaction(playerid) = GetPlayerTeam;

new 
gTeam[MAX_PLAYERS];

#define SetPlayerTeam(%0,%1) (gTeam[%0] = %1)
#define GetPlayerTeam(%0) gTeam[%0] 
In your code you just need to use them
PHP Code:
// 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(playeridFaction_Defend);
                
SetPlayerTeam(playeridTeam_President);
                
                
//other codes
            
}
            case 
1:
            {
                
SetPlayerFaction(playeridFaction_Defend);
                
SetPlayerTeam(playeridTeam_Police);
                
                
//other codes
            
}
            case 
2:
            {
                
SetPlayerFaction(playeridFaction_Attack);
                
SetPlayerTeam(playeridTeam_Terrorist);

                
//other codes
            
}
        }
    }
    return 
1;

Maybe you will notice the similarity to the code from before
Nero_3D is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] [TUT] Teams - Setting up teams - Team restricted vehicles - Team Restricted base retart441 Tutorials 79 08/02/2015 10:43 AM
[Include] [Organisations] Make and use teams/groups/factions/VIP/admin TEAMS easily!! RajatPawar Includes 14 27/07/2013 08:31 AM
Teams and teams vehicles, need help. needhack Scripting Help 5 23/02/2013 04:01 PM
I need help with teams. fie Help Archive 1 21/03/2011 04:20 PM
Two teams, How to do this Torran Help Archive 2 26/01/2010 07:01 PM


All times are GMT. The time now is 05:26 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.