[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
#2

This tutorial is a nice start, but I do not think it is worthy of becoming stickied.

Firstly, tutorials go on the tutorials page of the wiki.
Secondly, some of the code is sketchy, and needs to be explained better.
Thirdly, there is already a stickied gates topic with links to tutorials.

Nice work to Giacommand, but perhaps a bit more of an explanation would be better. Keep at it, and then, by all means, produce tutorials, as they help everyone.

~Cueball~
Reply
#3

How can I script it, that ID 0 can also open the gates. When I use the script, all can open the gates, but ID 0 can't.
Reply
#4

I already put a topic about this in here :P

http://forum.sa-mp.com/index.php/topic,54676.0.html
Reply
#5

Could ya please PUT pictures of where to do this, or put the SCRIPT you made HERE ALL

without this steps, cuz iam CONFUSED!
Reply
#6

where do i find OnGameModeInit i have penls i want to make a hq with gates but i cant find OnGameModeInit can someone plz help me
Reply
#7

Press "Strg+F" and type "OnGameModeInit" ... lesser than a second later ... FOUND
Reply
#8

How to make moving gate but you must open it with command? like /opengate
(!! not that you come close and i opens !!)
Reply
#9

!!! How to make a Object that move with a command !!!
pawn Код:
//Above but out of brackets
new Object;
pawn Код:
//OnGameModeInit
Object = CreateObject(modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ);
pawn Код:
//OnPlayerCommandText
if(!strcmp("/object move1", cmdtext, true)) return MoveObject(Object, Float:X, Float:Y, Float:Z, Float:Speed);
if(!strcmp("/object move2", cmdtext, true))
{
    MoveObject(Object, Float:X, Float:Y, Float:Z, Float:Speed);
    SendClientMessage(playerid, COLOR, "Blabla Moved");
    return 1;
}
Reply
#10

I do like this:
[PAWN code]
public OnGameModeInit()
Object=CreateObject(988,2142.0913,1009.7625,10.479 2,2141.7197,1022.5601,10.4795);

[PAWN code]
public OnPlayerCommandText(playerid, cmdtext[])
{
if (!strcmp("/gate move1", cmdtext, true, 10) == 0)
{
MoveObject(988,2142.0913,1009.7625,10.4792,1.50000 0);
return 1;
}
if(!strcmp("/gate move2", cmdtext, true, 10) == 0)
{
MoveObject(988,2141.7197,1022.5601,10.4795,1.50000 0);
return 1;
}
return 0;
}

And than..
C:\Documents and Settings\Rok\Desktop\SAMP server\gamemodes\thaidk.pwn(22 : warning 213: tag mismatch
C:\Documents and Settings\Rok\Desktop\SAMP server\gamemodes\thaidk.pwn(233) : warning 213: tag mismatch
C:\Documents and Settings\Rok\Desktop\SAMP server\gamemodes\thaidk.pwn(164) : warning 204: symbol is assigned a value that is never used: "Object"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


3 Warnings.

Why?! what must i do? to fix?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)