SA-MP Forums Archive
[HELP] Restricting command to several teams - 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: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [HELP] Restricting command to several teams (/showthread.php?tid=114479)



[HELP] Restricting command to several teams - Galcio - 19.12.2009

Ok, I'm trying to restrict a command. First let me post the code then I'll explain a bit deeper.
pawn Код:
if(!strcmp(cmdtext, "/area51", true, 30))
    {
    if(gTeam[playerid] == TEAM_ARMY && gTeam[playerid] == TEAM_FBI && gTeam[playerid] == TEAM_SWAT) //check if the player is law enforcement
    {
            SetPlayerPos(playerid, -63.7372,1777.3805,17.2696);
            SendClientMessage(playerid, 0xFFFFFFFF, "Mission: Kill any terrorist you see, if any other law enforcement team attack you, kill them.");
    }
      else
      {
        SetPlayerPos(playerid, 3615.0876464844, 492.53094482422, 60.263984680176);
        SendClientMessage(playerid,0xFFFFFFFF,"Mission: Deffend the army base, don't let law enforcement set their foot inside."); //if no
        }
        return 1;
    }
As you can see I'm trying to make TEAM_ARMY, TEAM_FBI, TEAM_SWAT only being able to spawn at one location. And the rest of the teams (terrorists and civilians) should spawn at an other spot. The script compiles fine. But once I connect to my server and type /area51 I receive this: "Mission: Deffend the army base, don't let the law enforcement set their foot inside." and then I get teleported where to the civilians and terrorists should spawn.

Please don't say "search". Becuase I have, and still can't find what I'm looking for.

Thanks.


Re: [HELP] Restricting command to several teams - Flo_White - 19.12.2009

change
Код:
if(gTeam[playerid] == TEAM_ARMY && gTeam[playerid] == TEAM_FBI && gTeam[playerid] == TEAM_SWAT)
to
Код:
if(gTeam[playerid] == TEAM_ARMY || gTeam[playerid] == TEAM_FBI || gTeam[playerid] == TEAM_SWAT)
and why do you need 30? 7 is enough ^^


Re: [HELP] Restricting command to several teams - Galcio - 19.12.2009

Tested some things, that's why I had 30. It works now, thank you.


Re: [HELP] Restricting command to several teams - Damon_Black - 19.12.2009

If you end up with a bunch of instances of this in your script:

if(gTeam[playerid] == TEAM_ARMY && gTeam[playerid] == TEAM_FBI && gTeam[playerid] == TEAM_SWAT)


You can combine them into one definition:

Код:
IsACop(playerid)
{
   if(gTeam[playerid] == TEAM_ARMY || gTeam[playerid] == TEAM_FBI || gTeam[playerid] == TEAM_SWAT) //check if the player is law enforcement
   {
      return 1;
   }
   return 0;
}
Because if(IsACop(playerid)) is alot more manageable and you can easily go back and edit the definition without retracing your steps 20 times throughout the script.