rendered paste body#include <a_samp>
#define SLOTS 4
forward AreaProcess();
forward KeyPress();
#define KEYPRESS_INTERVAL 200
#define MOVE_SPEED 2.0
#define MINX -100.0 // area where you can use the keys
#define MINY 1600.0
#define MAXX 400.0
#define MAXY 2200.0
new Float:doors[2][3] = {
{215.941, 1875.5, 13.903},
{211.842, 1875.5, 13.903}
};
new objects[2];
new doors_open[2];
new last_keys[SLOTS];
public OnFilterScriptInit() {
print(" ");
print(" Gates Script by mabako");
print(" ");
SetTimer("AreaProcess",1000,1);
objects[0] = CreateObject(2927, doors[0][0], doors[0][1], doors[0][2],0.0,0.0,0.0); // Coords taken from main.scm,
objects[1] = CreateObject(2929, doors[1][0], doors[1][1], doors[1][2],0.0,0.0,0.0); // modelid from MTA's all.models
SetTimer("KeyPress",KEYPRESS_INTERVAL,1);
}
public OnFilterScriptExit() {
DestroyObject(objects[0]);
DestroyObject(objects[1]);
}
public AreaProcess() {
new people_in_area;
for(new i; i<SLOTS;i++) {
if(IsPlayerConnected(i)) {
new Float:x, Float:y, Float:z;
GetPlayerPos(i, x, y, z);
if(x >= MINX && x <= MAXX && y >= MINY && y <= MAXY) {
people_in_area++;
}
}
}
if(people_in_area == 0) { // Noone's there, yet we can close the door
MoveObject(objects[0],doors[0][0],doors[0][1],doors[0][2],MOVE_SPEED);
MoveObject(objects[1],doors[1][0],doors[1][1],doors[1][2],MOVE_SPEED);
doors_open[0] = -2;
doors_open[1] = -2;
}
}
public OnObjectMoved(objectid) {
if(objects[0] == objectid) {
if(doors_open[0] == -1) {
SetObjectPos(objectid,doors[0][0]+5.0,doors[0][1],doors[0][2]);
// those setobjectpos is just because of a bug with MoveObject, if a player joins while the object is
// moving, it's frozen for him.
doors_open[0] = 1;
} else if(doors_open[0] == -2) {
SetObjectPos(objectid,doors[0][0],doors[0][1],doors[0][2]);
doors_open[0] = 0;
}
} else if(objects[1] == objectid) {
if(doors_open[1] == -1) {
SetObjectPos(objectid,doors[1][0]-5.0,doors[1][1],doors[1][2]);
doors_open[1] = 1;
} else if(doors_open[1] == -2) {
SetObjectPos(objectid,doors[1][0],doors[1][1],doors[1][2]);
doors_open[1] = 0;
}
}
}
public KeyPress() {
for(new i; i<SLOTS;i++) {
if(IsPlayerConnected(i)) {
if(IsPlayerAdmin(i)) {
new Float:x, Float:y, Float:z;
GetPlayerPos(i, x, y, z);
if(x >= MINX && x <= MAXX && y >= MINY && y < MAXY) {
new Keys[3];
GetPlayerKeys(i, Keys[0], Keys[1], Keys[2]);
if(Keys[0] != last_keys[i] && Keys[0] & KEY_LOOK_BEHIND) { // usually NUM1 on foot, 2 in car
if(doors_open[0] == 1 || doors_open[0] == -1) { // Doors are open or going to open
MoveObject(objects[0],doors[0][0],doors[0][1],doors[0][2],MOVE_SPEED);
MoveObject(objects[1],doors[1][0],doors[1][1],doors[1][2],MOVE_SPEED);
doors_open[0] = -2;
doors_open[1] = -2;
} else { // Closed, open them
MoveObject(objects[0],doors[0][0]+5.0,doors[0][1],doors[0][2],MOVE_SPEED);
MoveObject(objects[1],doors[1][0]-5.0,doors[1][1],doors[1][2],MOVE_SPEED);
doors_open[0] = -1;
doors_open[1] = -1;
}
}
last_keys[i] = Keys[0];
}
}
}
}
}