Open and Close Gate
#1

Hello,

I did one gate and now I've made the function to open and close the gate, using the horn key (H or Caps Lock). But I just did the function to open (press one time the horn key) and what I want, it's if press again the horn key, the gate will close.

Here is my code:

Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
  if((newkeys == KEY_HORN) && (IsPlayerInAnyVehicle(playerid))){
    if(GetDistanceBetweenPlayerobj(playerid,xxxxx, xxxxx, xxxxx) < 15){
      MoveObject(gate1,xxxxx, xxxxxx, xxxxx);
      SendClientMessage(playerid, COLOR_RED, "You've opened the Gate.");
      return 1;
	} 
  } return 0;
}
This is working, I already tested. Just need to add the close inside the code!
If someone can help

Thanks!
Reply
#2

oh, i think it will be same thing.. like for example:

if(GetDistanceBetweenPlayerobj(playerid,xxxxx, xxxxx, xxxxx) < 15){ // place where to be so it can be opened

if(GetDistanceBetweenPlayerobj(playerid,xxxxx, xxxxx, xxxxx) < 15){ // place where to be so it can be closed

understand? ya know.. like:

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
  if((newkeys == KEY_HORN) && (IsPlayerInAnyVehicle(playerid))){
    if(GetDistanceBetweenPlayerobj(playerid,1234.5, 1234.5, 1234.5) < 15){ // WHERE TO BE SO IT CAN BE OPENED
      MoveObject(gate1,xxxxx, xxxxxx, xxxxx);
      SendClientMessage(playerid, COLOR_RED, "You've opened the Gate.");
      return 1;
    }
    if(GetDistanceBetweenPlayerobj(playerid,6789.10, 6789.10, 9789.10) < 15){ // WHERE TO BE SO IT CAN BE CLOSED
      MoveObject(gate1,xxxxx,xxxxx,xxxxx);
      SendClientMessage(playerid, COLOR_RED, "You've closed the Gate.");
      return 1;
    }
  } return 0;
}
I think so it is like that!
Reply
#3

Quote:
Originally Posted by Moustafa
oh, i think it will be same thing.. like for example:

if(GetDistanceBetweenPlayerobj(playerid,xxxxx, xxxxx, xxxxx) < 15){ // place where to be so it can be opened

if(GetDistanceBetweenPlayerobj(playerid,xxxxx, xxxxx, xxxxx) < 15){ // place where to be so it can be closed

understand? ya know.. like:

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
  if((newkeys == KEY_HORN) && (IsPlayerInAnyVehicle(playerid))){
    if(GetDistanceBetweenPlayerobj(playerid,1234.5, 1234.5, 1234.5) < 15){ // WHERE TO BE SO IT CAN BE OPENED
      MoveObject(gate1,xxxxx, xxxxxx, xxxxx);
      SendClientMessage(playerid, COLOR_RED, "You've opened the Gate.");
      return 1;
    }
    if(GetDistanceBetweenPlayerobj(playerid,6789.10, 6789.10, 9789.10) < 15){ // WHERE TO BE SO IT CAN BE CLOSED
      MoveObject(gate1,xxxxx,xxxxx,xxxxx);
      SendClientMessage(playerid, COLOR_RED, "You've closed the Gate.");
      return 1;
    }
  } return 0;
}
I think so it is like that!
I understand what you did, that what I did before.. but it doesn't work.
Because the horn open the gate, OK! But there's nothing inside the code that indicate IF HORN AGAIN, the gate will be closed, understand?

That what I stuck
Anyways, thanks for you help!
Reply
#4

Weird, but i tried it and it worked.. well.. good luck :P
Reply
#5

Really? OMG
I can't do this work
That's bad!

Thanks anyways!
Reply
#6

Meeh I wish i had it in a .pwn file
Reply
#7

why not use a timer :P
Reply
#8

Timer is cool, but I really want to make this work.
If doesn't, maybe I will use timer
Reply
#9

I think i got the solution, at the radi of each GetDistanceBetweenPlayerobj to 1 instead of 15, because 15 is too big..

for example; like that
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
  if((newkeys == KEY_HORN) && (IsPlayerInAnyVehicle(playerid))){
    if(GetDistanceBetweenPlayerobj(playerid,1234.5, 1234.5, 1234.5) < 1){ // WHERE TO BE SO IT CAN BE OPENED
      MoveObject(gate1,xxxxx, xxxxxx, xxxxx);
      SendClientMessage(playerid, COLOR_RED, "You've opened the Gate.");
      return 1;
    }
    if(GetDistanceBetweenPlayerobj(playerid,6789.10, 6789.10, 9789.10) < 1){ // WHERE TO BE SO IT CAN BE CLOSED
      MoveObject(gate1,xxxxx,xxxxx,xxxxx);
      SendClientMessage(playerid, COLOR_RED, "You've closed the Gate.");
      return 1;
    }
  } return 0;
}
Reply
#10

Quote:
Originally Posted by Moustafa
I think i got the solution, at the radi of each GetDistanceBetweenPlayerobj to 1 instead of 15, because 15 is too big..

for example; like that
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
  if((newkeys == KEY_HORN) && (IsPlayerInAnyVehicle(playerid))){
    if(GetDistanceBetweenPlayerobj(playerid,1234.5, 1234.5, 1234.5) < 1){ // WHERE TO BE SO IT CAN BE OPENED
      MoveObject(gate1,xxxxx, xxxxxx, xxxxx);
      SendClientMessage(playerid, COLOR_RED, "You've opened the Gate.");
      return 1;
    }
    if(GetDistanceBetweenPlayerobj(playerid,6789.10, 6789.10, 9789.10) < 1){ // WHERE TO BE SO IT CAN BE CLOSED
      MoveObject(gate1,xxxxx,xxxxx,xxxxx);
      SendClientMessage(playerid, COLOR_RED, "You've closed the Gate.");
      return 1;
    }
  } return 0;
}
I don't understand.. because if I use 1, even I near the gate, I can't open!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)