Advertisement
Hiddos

TUT: Automatic gates

Aug 28th, 2011
1,141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.82 KB | None | 0 0
  1. #include <a_samp>
  2. new gate;
  3. new bool:gateopen;
  4.  
  5. public OnFilterScriptInit() // Alternatively, use OnGameModeInit if you implement it in your gamemode
  6. {
  7.     SetTimer("GateCheck", 800, true); //This is used to create the timer. The "GateCheck" is the callback we'll be using,
  8.     // the '800' is the amount of milliseconds between each call and the 'true' indicates that this timer is looping endlessly
  9.     gate = CreateObject(16442, 8.0, 3.0, 10.0, 0.0, 0.0, 0.0);
  10.     //'gate = CreateObject(...);' = Assigns the object id of the gate to the 'gate' variable
  11.     //16442 = object model id < change it to the model id you use for your gate
  12.     // 8.0, 3.0, 10.0 = coordinates of the gate
  13.     // 0.0, 0.0, 0.0 = Rotation of the gate. None in this case.
  14.     return 1;
  15. }
  16.  
  17. forward GateCheck();
  18. public GateCheck()
  19. {
  20.     for(new i; i < MAX_PLAYERS; i++) // Start the loop
  21.     {
  22.             if(IsPlayerInRangeOfPoint(playerid, 15.0, 8.0, 3.0, 10.0)) //Check if any player is in the area. Replace '8.0, 3.0, 10.0' with your own coordinates of your closed gate.
  23.             {
  24.                 if(gateopen == false) // If the gate isn't open...
  25.                 {
  26.                     MoveObject(gate, 32.0, 12.0, 10.0, 3.5); //Then open it! Change '32.0, 12.0, 10.0' to the coordinates of your opened gate.
  27.                     gateopen = true; // Setting this to true indicates it's open(ing)
  28.                 }
  29.             return; //This closes the callback
  30.             }
  31.     }
  32.     //This is called if nobody has been found near the gate. Obviously, because 'return' would fully close the function and this wouldn't be used then.
  33.     if(gateopen == true) //If the gate IS open, but there's no one near..
  34.     {
  35.             MoveObject(gate, 8.0, 3.0, 10.0, 3.5); // Change the '8.0, 3.0, 10.0' to the coordinates of your gate when it's closed.
  36.         gateopen = false; //This indicates the gate is closed again. Or at least, closing.
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement