Gates aren't moving.
#1

Код:
public GroveGates() 
{
  for(new i; i< GetMaxPlayers();i++)
  {
  if(!IsPlayerConnected(i))continue;
  if(DMZone[i] == 4)
  if(IsPlayerInRangeOfPoint(i, 10.0, 2435.674561, -1656.416626, 13.420712))
  {
    MoveObject(ggate, 2435.637695, -1651.433228, 13.333119, 3.0);
  }else{
    MoveObject(ggate, 2435.674561, -1656.416626, 13.420712, 3.0);
  }
  }
}
Any idea's why they aren't moving?
Reply
#2

The problem was with IsPlayerConnected you had (!IsPlayerConnected) which checks if the player is diconnected.


pawn Код:
public GroveGates()
{
    for(new i; i< GetMaxPlayers();i++)
    {
        if(IsPlayerConnected(i) && DMZone[i] == 4)
        {
            if(IsPlayerInRangeOfPoint(i, 10.0, 2435.674561, -1656.416626, 13.420712))
            {
                MoveObject(ggate, 2435.637695, -1651.433228, 13.333119, 3.0);
            }
            else
            {
                MoveObject(ggate, 2435.674561, -1656.416626, 13.420712, 3.0);
            }
        }
    }
}
Reply
#3

Quote:
Originally Posted by [B2K
Hustler ]
The problem was with IsPlayerConnected you had (!IsPlayerConnected) which checks if the player is diconnected.
No, he checked if they were disconnected and if they were he used "continue" to skip to the next player in the loop.
The code you posted should technically work, however in the original code Chris was just missing a set of braces.
pawn Код:
public GroveGates()
{
  for(new i; i< GetMaxPlayers();i++)
  {
    if(!IsPlayerConnected(i)) continue;
    if(DMZone[i] == 4)
    {
      if(IsPlayerInRangeOfPoint(i, 10.0, 2435.674561, -1656.416626, 13.420712))
      {
        MoveObject(ggate, 2435.637695, -1651.433228, 13.333119, 3.0);
      }
      else
      {
        MoveObject(ggate, 2435.674561, -1656.416626, 13.420712, 3.0);
      }
    }
  }
}
Reply
#4

Thanks man
Reply
#5

There's a problem with your code though. If one player is close to it, the gate opens, but since other players are away from the gate, it will close. This means the gate will only open if every player is within range of the gate.

This method will fix that.
pawn Код:
public GroveGates()
{
  new opengate;
  for(new i; i< GetMaxPlayers();i++)
  {
    if(!IsPlayerConnected(i)) continue;
    if((DMZone[i] == 4)&&IsPlayerInRangeOfPoint(i, 10.0, 2435.674561, -1656.416626, 13.420712))opengate=1;
  }
  if(opengate)MoveObject(ggate, 2435.637695, -1651.433228, 13.333119, 3.0);
  else MoveObject(ggate, 2435.674561, -1656.416626, 13.420712, 3.0);
}
EDIT* I'm almost certain I've answered this before.
Reply
#6

Quote:
Originally Posted by Joe Staff
There's a problem with your code though. If one player is close to it, the gate opens, but since other players are away from the gate, it will close. This means the gate will only open if every player is within range of the gate.

This method will fix that.
pawn Код:
public GroveGates()
{
  new opengate;
  for(new i; i< GetMaxPlayers();i++)
  {
    if(!IsPlayerConnected(i)) continue;
    if((DMZone[i] == 4)&&IsPlayerInRangeOfPoint(i, 10.0, 2435.674561, -1656.416626, 13.420712))opengate=1;
  }
  if(opengate)MoveObject(ggate, 2435.637695, -1651.433228, 13.333119, 3.0);
  else MoveObject(ggate, 2435.674561, -1656.416626, 13.420712, 3.0);
}
EDIT* I'm almost certain I've answered this before.
Whats the different between this script above and this script, where you put OpenGate[MAX_PLAYERS]...
pawn Код:
new OpenGate[MAX_PLAYERS];
public CheckGate()
{
  for(new i = 0; i < GetMaxPlayers(); i++)
  {
    if(!IsPlayerConnected(i)) continue;
    if(PlayerToPoint(10.0, i, closed_X, closed_Y, closed_Z) && OpenGate[i] == 0)
    {
      MoveObject(c_gate, open_X, open_Y, open_Z);
      OpenGate[i] = 1;
    }
    else if(!PlayerToPoint(10.0, i, closed_X, closed_Y, closed_Z) && OpenGate[i] == 1)
    {
      MoveObject(c_gate, closed_X, closed_Y, closed_Z);
      OpenGate[i] = 0;
    }
  }
}
its from the wiki

Oh and i had this script in 0.2X, which causes problems in 0.3a (players didnt see object movings but i am):
pawn Код:
forward CheckGate();
public CheckGate()
{
  for(new i = 0; i < GetMaxPlayers(); i++)
  {
    if(!IsPlayerConnected(i)) continue;
    if(PlayerToPoint(10.0, i, 213.8831,1875.3693,13.1470))
    {
      MoveObject(a51_desna,207.838668,1875.358276,13.885452,1.0);
      MoveObject(a51_leva,219.970260,1875.358276,13.885452,1.0);
      return 1;
    }
  }
  MoveObject(a51_desna,211.854766,1875.358276,13.885452,1.0);
  MoveObject(a51_leva,215.952407,1875.358276,13.885452,1.0);
  return 1;
}
thank you

PS: Dont look at "PlayerToPoint". In my script i replaced it with "IsPlayerInRangeOfPoint" already.
Reply
#7

Quote:
Originally Posted by yugokoral
Whats the different between this script above and this script, where you put OpenGate[MAX_PLAYERS]...
pawn Код:
new OpenGate[MAX_PLAYERS];
public CheckGate()
{
  for(new i = 0; i < GetMaxPlayers(); i++)
  {
    if(!IsPlayerConnected(i)) continue;
    if(PlayerToPoint(10.0, i, closed_X, closed_Y, closed_Z) && OpenGate[i] == 0)
    {
      MoveObject(c_gate, open_X, open_Y, open_Z);
      OpenGate[i] = 1;
    }
    else if(!PlayerToPoint(10.0, i, closed_X, closed_Y, closed_Z) && OpenGate[i] == 1)
    {
      MoveObject(c_gate, closed_X, closed_Y, closed_Z);
      OpenGate[i] = 0;
    }
  }
}
It's different because the OpenGate[MAX_PLAYERS]; means it can be open for some players and closed for others, which makes no sense. It has to be open for all players or closed for al players. And if you go by the loop, if player 1 is next to the gate it will open, but if player 2 is away from the gate it will close. And sense the loop is going in numerical order it will run the functions like this

Код:
Player 1 - Near Gate - open
Player 2 - Near Gate - open
Player 3 - Away from gate - Close
Because close is last, it will stay closed for all players.
Reply
#8

What about this code i had:

Код:
forward CheckGate();
public CheckGate()
{
  for(new i = 0; i < GetMaxPlayers(); i++)
  {
    if(!IsPlayerConnected(i)) continue;
    if(PlayerToPoint(10.0, i, 213.8831,1875.3693,13.1470))
    {
      MoveObject(a51_desna,207.838668,1875.358276,13.885452,1.0);
      MoveObject(a51_leva,219.970260,1875.358276,13.885452,1.0);
      return 1;
    }
  }
  MoveObject(a51_desna,211.854766,1875.358276,13.885452,1.0);
  MoveObject(a51_leva,215.952407,1875.358276,13.885452,1.0);
  return 1;
}
Thank you for help!
Reply
#9

Quote:
Originally Posted by yugokoral
What about this code i had:

Код:
forward CheckGate();
public CheckGate()
{
  for(new i = 0; i < GetMaxPlayers(); i++)
  {
    if(!IsPlayerConnected(i)) continue;
    if(PlayerToPoint(10.0, i, 213.8831,1875.3693,13.1470))
    {
      MoveObject(a51_desna,207.838668,1875.358276,13.885452,1.0);
      MoveObject(a51_leva,219.970260,1875.358276,13.885452,1.0);
      return 1;
    }
  }
  MoveObject(a51_desna,211.854766,1875.358276,13.885452,1.0);
  MoveObject(a51_leva,215.952407,1875.358276,13.885452,1.0);
  return 1;
}
Thank you for help!
pawn Код:
forward CheckGate();
public CheckGate()
{
  for(new i = 0; i < GetMaxPlayers(); i++)
  {
    if(!IsPlayerConnected(i)) continue;
    if(PlayerToPoint(10.0, i, 213.8831,1875.3693,13.1470))
    {
      MoveObject(a51_desna,207.838668,1875.358276,13.885452,1.0);
      MoveObject(a51_leva,219.970260,1875.358276,13.885452,1.0);
    }
    else
    {
    MoveObject(a51_desna,211.854766,1875.358276,13.885452,1.0);
    MoveObject(a51_leva,215.952407,1875.358276,13.885452,1.0);
    }
  }
  return 1;
}
Reply
#10

Ok, i need script that will open and close gates for all players!

I do this: + playerplaysound

pawn Код:
forward CheckGate();
public CheckGate()
{
  for(new i=0; i<GetMaxPlayers(); i++)
  {
    if(!IsPlayerConnected(i)) continue;
    if(IsPlayerInRangeOfPoint(i, 12.0, 213.8831,1875.3693,13.1470) && OpenGate0 == 0)
    {
      MoveObject(a51_desna,207.838668,1875.358276,13.885452,1.0);
      MoveObject(a51_leva,219.970260,1875.358276,13.885452,1.0);
      PlayerPlaySound(i, 1165, 213.8831, 1875.3693, 13.1470);
      OpenGate0 = 1; //i cant do without this, because i cant use than sound for close  downstairs
    }
    else if(!IsPlayerInRangeOfPoint(i, 12.0, 213.8831,1875.3693,13.1470) && OpenGate0 == 1)
    {
      MoveObject(a51_desna,211.854766,1875.358276,13.885452,1.0);
      MoveObject(a51_leva,215.952407,1875.358276,13.885452,1.0);
      PlayerPlaySound(i, 1165, 213.8831, 1875.3693, 13.1470);
      OpenGate0 = 0;
    }
  }
}


public OnObjectMoved(objectid)
{
  new Float:x, Float:y, Float:z;
  GetObjectPos(objectid, x, y, z);
  for(new i=0; i<GetMaxPlayers(); i++)
  {
    if(objectid == a51_desna && x==207.838668 && y==1875.358276 && z==13.885452 && OpenGate0 == 1)
    {
        PlayerPlaySound(playerid, 1166, 213.8831, 1875.3693, 13.1470); //stop sound
    }
    if(objectid == a51_desna && x==211.854766 && y==1875.358276 && z==13.885452 && OpenGate0 == 0)
    {
        PlayerPlaySound(playerid, 1166, 213.8831, 1875.3693, 13.1470); //stop sound
    }
  }
}
I do this. Itworks all included sounds. Sounds are the same like in original gates (transfender)... And i asking... Will that object movements be seen for all players And how can i do, that this sound will be heared for all players, not only for player who enter in the range of point??

thank you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)