[HOW-TO] Make An Automatic Gate (NOT BY ME!)
#1

How-To make an Actual Automatic Gate (not by me ! By Giacomand)


( When player is in an area, the gate opens )

First we will need to know how to make a: isPlayerInArea.

This will check if someone is in the area or not.


to do that, I made it how wiki told me, lol

Note: I didn't make "is" with caps, so that I can use the function IsPlayerInArea, which is for command based texts, and the Automatic isPlayerInArea

put this before main.
PAWN Code:

Код:
forward isPlayerInArea()
put this in OnGameModeInit - This will check if you're in the area or not.
PAWN Code:

Код:
SetTimer("isPlayerInArea",1000, 1);
Put this code somewhere, then fill in the "?"s
PAWN Code:

Код:
public isPlayerInArea()
  {
    new Float:X, Float:Y, Float:Z; //We use this to store player position
    for(new i=0; i < MAX_PLAYERS; i++) //This line defines a name for all player, the name is "i"
    {
      GetPlayerPos(i, X, Y, Z); //Here we are storing the player position on the variables X, Y, and Z defined previously
      if (X <= ?maxX? && X >= ?minX? && Y <= ?maxY? && Y >= ?minY?)
      /* This line is the important one!. Here, is where you change those numbers, by the ones
      you get from the /pos command. As you can see, those coordinates, are only the X and Y ones, the Z
      doesn't matter*/
How the MinX's, MaxX's, MinY's, MaxY's work?

Well first we will need to get them.

use this code to help you:

PAWN Code:

Код:
if (strcmp("/pos", cmdtext, true, 10) == 0)
{
      new string1[256];
      new Float:X,Float:Y,Float:Z;
      GetPlayerPos(playerid,X,Y,Z);
      format(string1,sizeof(string1),"Position = X: %.0f , Y: %.0f , Z: %.0f",X,Y,Z);
      SendClientMessage(playerid,0x33FF33AA,string1);
      return 1;
  }
( A pen and paper would be useful to remember them )

Okay, go IG.

go to the location you want to be an area.

The Area system works like this:


North MaxX/Y
|------------|
| |
| |
| |
|------------|
MinX/Y South

Go to the bottom left of the area, ( When I mean Bottom I mean south ), then /pos and write down the codes.

Then go to the top right ( North ) of the area, then /pos and write them down.


Then fill in those gaps. ( The "??'s" )


Note: Min X/Y is always smaller than Max X/Y, and Max X/Y is always bigger than Min X/Y


Now we should have something like this:


PAWN Code:

Код:
forward isPlayerInArea()
PAWN Code:

Код:
public OnGameModeInIt()


SetTimer("isPlayerInArea",1000, 1);
PAWN Code:

Код:
public isPlayerInArea()
  {
    new Float:X, Float:Y, Float:Z; //We use this to store player position
    for(new i=0; i < MAX_PLAYERS; i++) //This line defines a name for all player, the name is "i"
    {
      GetPlayerPos(i, X, Y, Z); //Here we are storing the player position on the variables X, Y, and Z defined previously
      if (X <= ?maxX? && X >= ?minX? && Y <= ?maxY? && Y >= ?minY?)
      /* This line is the important one!. Here, is where you change those numbers, by the ones
      you get from the /pos command. As you can see, those coordinates, are only the X and Y ones, the Z
      doesn't matter*/
now we add the gates..

First get the coordinates of the gates by either using an IG Object Editor or Using one of the Applications you can download ( I recommend the REAL object editor )

Lets say for instants, This was my Object Code:

PAWN Code:

Код:
CreateObject(975, 214.45, 1875.53, 13.80, 0.00, 0.00, 0.00); // Main gate closed
This is the gate of Area51.

First we will have to like...define it to the pawno script, what its ID is.

over the main, put:

PAWN Code:

Код:
new maingate; // change its name if you like.
then on OnGameModeInIt ( Where you put your cars and spawns )

put this:

PAWN Code:

Код:
maingate = CreateObject(975, 214.45, 1875.53, 13.80, 0.00, 0.00, 0.00); // Main gate closed
This will tell the script what that "new maingate" means and it will define it.

Next is the actual automatic part.

Go back to: public isPlayerInArea()

now we add this like so:

PAWN Code:

Код:
public isPlayerInArea()
  {
    new Float:X, Float:Y, Float:Z; //We use this to store player position
    for(new i=0; i < MAX_PLAYERS; i++) //This line defines a name for all player, the name is "i"
    {
      GetPlayerPos(i, X, Y, Z); //Here we are storing the player position on the variables X, Y, and Z defined previously
      if (X <= ?maxX? && X >= ?minX? && Y <= ?maxY? && Y >= ?minY?)
      /* This line is the important one!. Here, is where you change those numbers, by the ones
      you get from the /pos command. As you can see, those coordinates, are only the X and Y ones, the Z
      doesn't matter*/

      {
      MoveObject(maingate, 222.00, 1875.53, 13.80, 1); // MoveObject(ObjectID, X, Y, Z, speed); - Object id is the "New"
      }
now there is a problem. When we go inside the area, it opens like normal but it doesn't close.

To solve this we do this:


PAWN Code:

Код:
public isPlayerInArea()
  {
    new Float:X, Float:Y, Float:Z; //We use this to store player position
    for(new i=0; i < MAX_PLAYERS; i++) //This line defines a name for all player, the name is "i"
    {
      GetPlayerPos(i, X, Y, Z); //Here we are storing the player position on the variables X, Y, and Z defined previously
      if (X <= ?maxX? && X >= ?minX? && Y <= ?maxY? && Y >= ?minY?)
      /* This line is the important one!. Here, is where you change those numbers, by the ones
      you get from the /pos command. As you can see, those coordinates, are only the X and Y ones, the Z
      doesn't matter*/

      {
      MoveObject(maingate, 222.00, 1875.53, 13.80, 1); // MoveObject(ObjectID, X, Y, Z, speed); - Object id is the "New"
      }
      else // else means that if nothing is in it, perform this action:
      {
      MoveObject(maingate, 214.45, 1875.53, 13.80, 1); // This will close the gate
      }
   }
  return 1;
}
There we go, automatic gates.

But....gates are there for a reason right?

To let certain people in or out.

To make it so that only a Team Member can open the gate is:

PAWN Code:

Код:
if( GetPlayerTeam(i) == TEAM_NAME )
we put this like so:

PAWN Code:

Код:
public isPlayerInArea()
  {
    new Float:X, Float:Y, Float:Z; //We use this to store player position
    for(new i=0; i < MAX_PLAYERS; i++) //This line defines a name for all player, the name is "i"
    {
      GetPlayerPos(i, X, Y, Z); //Here we are storing the player position on the variables X, Y, and Z defined previously
      if (X <= ?maxX? && X >= ?minX? && Y <= ?maxY? && Y >= ?minY?)
      /* This line is the important one!. Here, is where you change those numbers, by the ones
      you get from the /pos command. As you can see, those coordinates, are only the X and Y ones, the Z
      doesn't matter*/

      {
      if( GetPlayerTeam(i) == TEAM_DEFENSE) // tells the script to open the gate to Team Defense only.
      {
      MoveObject(maingate, 222.00, 1875.53, 13.80, 1); // MoveObject(ObjectID, X, Y, Z, speed); - Object id is the "New"
      }
      else // else means that if nothing is in it, perform this action:
      {
      MoveObject(maingate, 214.45, 1875.53, 13.80, 1); // This will close the gate
      }
      }
    }
  return 1;
}
And you have an automatic gate!

Warning: The script may have loose indentations ( It's easy to fix so don't whine about it, just try to keep it in line )



THIS POST WAS NOT PRODUCED BY ME, BUT WAS CREATED BY GIACOMAND!!

THIS POST SHOULD BE STICKIED !!
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 3 Guest(s)