[How-To] Make an Automatic Gate
#1

How-To make an Actual Automatic Gate

( 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 )
Reply
#2

Very nice :P
Reply
#3

*bump*
Reply
#4

Hmm wont this just keep the gate closed all of the time because someone in the server is not going to be in that area, so the gate will close.
Reply
#5

sorry for the bump.
but i get an error:
Код:
C:\SERVER SAMP\gamemodes\lvdmYossI.pwn(1385) : error 029: invalid expression, assumed zero
C:\SERVER SAMP\gamemodes\lvdmYossI.pwn(1385) : error 017: undefined symbol "maxX"
C:\SERVER SAMP\gamemodes\lvdmYossI.pwn(1385) : error 017: undefined symbol "minX"
C:\SERVER SAMP\gamemodes\lvdmYossI.pwn(1385) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
Reply
#6

nah Juicys is bettah
Reply
#7

Quote:
Originally Posted by Farly
Hmm wont this just keep the gate closed all of the time because someone in the server is not going to be in that area, so the gate will close.
yes, i have written a clan script and if someone of the clan is connected an not in the area, the gate won't open.
i have done this:

Код:
if((X <= 1541.5036 && X >= 1530.1136 && Y <= -1436.6630 && Y >= -1464.1524) || (X <= 1561.2152 && X >= 1504.2138 && Y <= -1430.9941 && Y >= -1450.5169))
{
    {
       MoveObject(GPRHQTor,1534.51,-1451.48,20,3);
    }
}
    else if((!(X <= 1541.5036 && X >= 1530.1136 && Y <= -1436.6630 && Y >= -1464.1524)) || (!(X <= 1561.2152 && X >= 1504.2138 && Y <= -1430.9941 && Y >= -1450.5169)))
    {
       MoveObject(GPRHQTor,1534.51,-1451.48,14.7531,3);
    }
this works

the first if checks if the player is in the area
and the else if checks if he is not in the area

the two if's has two area checks, cause my script checks an area like this:

__________
|____ __|
| |
|__|
Reply
#8

i have penls and i want to do these gates but i dont kno where to find OnGameModeInit can u plz tell me where it is plz
Reply
#9

lol go on find and write " OnGameModeINT "
Reply
#10

no this is going to work:[/sarcasm]
pawn Код:
public isPlayerInArea()
 {
   new Float:X, Float:Y, Float:Z;
   for(new i=0; i < MAX_PLAYERS; i++)
   {
     GetPlayerPos(i, X, Y, Z);
     if (X <= ?maxX? && X >= ?minX? && Y <= ?maxY? && Y >= ?minY?)
removed the comments.. look closely and you will see you are missing something you are missing A LOT! about.. erm.. half of the function?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)