Automatic gates - bugged and taking much ressources
#1

Hi there. Automatic gates are epic - as long as theyґre working. But mine are not.

Код:
public boobsgatetimer()
{
  for(new i=0; i<MAX_PLAYERS; i++)
  {
    if(boobsmember[i] == 1 || IsPlayerAdmin(i))
    {
//----------------------------------------------------------------------------
    if(IsPlayerInRangeOfPoint(i,20,-545.30004882813, 1251.1568603516, 1.5))
    {
    MoveObject(boobsgate,-545.30004882813, 1249.1568603516, 9.5, 2);
    }
    else
    {
    MoveObject(boobsgate,-545.30004882813, 1251.1568603516, 1.5, 2);
    }
//----------------------------------------------------------------------------BOOBSDOOR1
    if(IsPlayerInRangeOfPoint(i,5,-540.58142089844, 1329.7946777344, 3.2876319885254))
    {
    MoveObject(boobsdoor1,-540.58142089844, 1329.7946777344, 6.2876319885254, 2);
    }
    else
    {
    MoveObject(boobsdoor1,-540.58142089844, 1329.7946777344, 3.2876319885254, 2);
    }
//----------------------------------------------------------------------------BOOBSDOOR2
    if(IsPlayerInRangeOfPoint(i,5,-543.65942382813, 1355.6201171875, 11.836064338684))
    {
    MoveObject(boobsdoor2,-543.65942382813, 1355.6201171875, 14.836064338684, 2);
    }
    else
    {
    MoveObject(boobsdoor2,-543.65942382813, 1355.6201171875, 11.836064338684, 2);
    }
//----------------------------------------------------------------------------BOOBSDOOR3
    if(IsPlayerInRangeOfPoint(i,5,-542.75897216797, 1376.6665039063, 11.807936668396))
    {
    MoveObject(boobsdoor3,-542.75897216797, 1376.6665039063, 14.807936668396, 2);
    }
    else
    {
    MoveObject(boobsdoor3,-542.75897216797, 1376.6665039063, 11.807936668396, 2);
    }
//----------------------------------------------------------------------------BOOBSDOOR4
    if(IsPlayerInRangeOfPoint(i,5,-543.65338134766, 1366.5200195313, 11.790085792542))
    {
    MoveObject(boobsdoor4,-543.65338134766, 1366.5200195313, 14.790085792542, 2);
    }
    else
    {
    MoveObject(boobsdoor4,-543.65338134766, 1366.5200195313, 11.790085792542, 2);
    }
//----------------------------------------------------------------------------BOOBSDOOR5
    if(IsPlayerInRangeOfPoint(i,5,-535.11450195313, 1419.3912353516, 12.049313545227))
    {
    MoveObject(boobsdoor5,-535.11450195313, 1419.3912353516, 15.049313545227, 2);
    }
    else
    {
    MoveObject(boobsdoor5,-535.11450195313, 1419.3912353516, 12.049313545227, 2);
    }
//----------------------------------------------------------------------------BOOBSDOOR6
    if(IsPlayerInRangeOfPoint(i,5,-543.28619384766, 1370, 19.033756256104))
    {
    MoveObject(boobsdoor6,-543.28619384766, 1370, 22.033756256104, 2);
    }
    else
    {
    MoveObject(boobsdoor6,-543.28619384766, 1370, 19.033756256104, 2);
    }

		}
  }
}
Hereґs my code. If more people run around at the doors, the door gets bugged and dont open any more. Anyone knows why?
Reply
#2

Oh for crying out loud, did you use Search? Or did you even bother to look on the first page of this board?

http://forum.sa-mp.com/index.php?top...8575#msg828575

Also, make your timer in the 2 to 5 seconds range.
Reply
#3

No, as my code is working perfectly and just bugging when a lot of people run around infront of it.
Reply
#4

Let's think the logic behind it:

Let's say you have, for example, 3 players connected to the server, ids 0, 1 and 2. ID 1 moves towards a gate. What does the timer do:

It goes player by player, checks their position and moves the gate. So what would it exactly do?

Checks ID 0 position -> it's away from the gate -> it gets closed.
Checks ID 1 position -> it's near the gate -> it gets opened.
Checks ID 2 position -> it's away from the gate -> it gets closed.

So, what basicly happens here, is that it closes automatly after it starts to get opened, and that happens every time the timer function is executed, so you'll be seeing it as if it was "stuck" or something. To solve this you could have a variable, and set it to 1 if there is someone near the door. Then, if the variable is not 1, you can check the position of the rest of the players. If it's 1, just skip them. Once he went away from the door, set it back at 0, so it will check for every player.
Reply
#5

Okay Iґve got it. Could you give me a example on how to do that?
Reply
#6

Quote:
Originally Posted by Mo3
Okay Iґve got it. Could you give me a example on how to do that?
flags?
Reply
#7

Let's see..

Код:
new boobsgateOpened;

public boobsgatetimer()
{
  new boobsgateNearCount; // No need to make it = 0, it is by default.
  new boobsdoor1NearCount;

  for(new i=0; i<MAX_PLAYERS; i++)
  {
    if(boobsmember[i] == 1 || IsPlayerAdmin(i))
    {
//----------------------------------------------------------------------------
      if(IsPlayerInRangeOfPoint(i,20,-545.30004882813, 1251.1568603516, 1.5))
      {
        boobsgateNearCount ++;
      }
//----------------------------------------------------------------------------
      if(IsPlayerInRangeOfPoint(i,20,-545.30004882813, 1251.1568603516, 1.5))
      {
        boobsdoor1NearCount ++;
      }
//----------------------------------------------------------------------------
    }
  }
//----------------------------------------------------------------------------
// Make the doors move:
//----------------------------------------------------------------------------
  if(boobsgateNearCount > 0)
  {
    MoveObject(boobsgate,-545.30004882813, 1249.1568603516, 9.5, 2);
   }
   else
   {
    MoveObject(boobsgate,-545.30004882813, 1251.1568603516, 1.5, 2); 
   }
//------------------------------
  if(boobsdoor1NearCount > 0)
  {
    MoveObject(boobsdoor1,-540.58142089844, 1329.7946777344, 6.2876319885254, 2);
   }
   else
   {
    MoveObject(boobsdoor1,-540.58142089844, 1329.7946777344, 3.2876319885254, 2);
   }
}
I didn't test it, but I think that should be working. You would have to do the same for every door/gate in the server. Try it and tell me
Reply
#8

Holy crap, Iґll need a bit to re-code all doors like that. Thank you!
Reply
#9

I would suggest this way, its quite similar but a bit better cuz it uses bools and has an extra check in it

pawn Код:
public boobsgatetimer()
{
    new i = -1, bool:open[7];
    while(++i < MAX_PLAYERS)
    {
        if(boobsmember[i] == 1 || IsPlayerAdmin(i))
        {
            if(   !open[0] && IsPlayerInRangeOfPoint(i, 20, -545.30004882, 1251.15686035, 1.5))
                open[0] = true;
            else if(!open[1] && IsPlayerInRangeOfPoint(i, 5, -540.58142089, 1329.79467773, 3.28763198))
                open[1] = true;
        }
    }
    if(open[0])     MoveObject(boobsgate, -545.30004882, 1249.15686035, 9.5, 2);
    else            MoveObject(boobsgate, -545.30004882, 1251.15686035, 1.5, 2);
    if(open[1])     MoveObject(boobsdoor1, -540.58142089, 1329.79467773, 6.28763198, 2);
    else            MoveObject(boobsdoor1, -540.58142089, 1329.79467773, 3.28763198, 2);
}
Zamaroht, did you get active again ? Or missed I all your posts ?
Reply
#10

Quote:
Originally Posted by ♣ ⓐⓢⓢ
I would suggest this way, its quite similar but a bit better cuz it uses bools and has an extra check in it

pawn Код:
public boobsgatetimer()
{
    new i = -1, bool:open[7];
    while(++i < MAX_PLAYERS)
    {
        if(boobsmember[i] == 1 || IsPlayerAdmin(i))
        {
            if(   !open[0] && IsPlayerInRangeOfPoint(i, 20, -545.30004882, 1251.15686035, 1.5))
                open[0] = true;
            else if(!open[1] && IsPlayerInRangeOfPoint(i, 5, -540.58142089, 1329.79467773, 3.28763198))
                open[1] = true;
        }
    }
    if(open[0])     MoveObject(boobsgate, -545.30004882, 1249.15686035, 9.5, 2);
    else            MoveObject(boobsgate, -545.30004882, 1251.15686035, 1.5, 2);
    if(open[1])     MoveObject(boobsdoor1, -540.58142089, 1329.79467773, 6.28763198, 2);
    else            MoveObject(boobsdoor1, -540.58142089, 1329.79467773, 3.28763198, 2);
}
Zamaroht, did you get active again ? Or missed I all your posts ?
The problem with this is that it will close regardless if the player is still standing near the gate, and wait a few seconds before opening again. So you'll end up with a opening/closing freaking once a player is nearby.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)