Scripting - Charge a player in every toll gate he enters

Started by Clucker, May 08, 2020, 10:50

Clucker

I want to fix a bug in my script.

My code charge the player when he enters / opens a toll gate at first attempt but when it comes to the second, third, and more toll gate it does not charge the player anymore.

What I want is to charge the player every time he enters a new toll gate (first, second, third, etc...). Only the charging of player is my problem not the automatic opening of the toll gate.

Here's my video of what I did:



Here's my snippet source code of the script:

https://pastebin.com/0rJd5FxA

Sjomp

Add
new open[MAX_PLAYERS];
On top and set open for the playerid you have opened the toll for.
open[playerid] = true;

I think that's your problem

Clucker

I did what you said but now it closes the toll gate even the player is still in range of the toll gate.

https://pastebin.com/99Gy8Yes

How can I make the toll act like toll gates in ct?

Sjomp

Change
if(!open[i]){
to
else if(open[i]){
I think open should be true here right?

Zeke

Try getting the range of the player before closing the gate

something like this but not exactly.
     
if(!IsPlayerInRangeOfPoint(i, 8.0, GatePos[a][3], GatePos[a][4], GatePos[a][5]))     
  {
      if(!open[i])
      {
                MoveObject(Gate[a], GatePos[a][0],GatePos[a][1],GatePos[a][2], 5.00, GatePos[a][3], GatePos[a][4], GatePos[a][5]);
                open[i] = false;
            }
}



Clucker

Quote from: Sjomp on May 09, 2020, 08:54
Change
if(!open[i]){
to
else if(open[i]){
I think open should be true here right?

tried it but still the same problem. no change.

Clucker

Quote from: Zeke on May 09, 2020, 13:30
Try getting the range of the player before closing the gate

something like this but not exactly.
     
if(!IsPlayerInRangeOfPoint(i, 8.0, GatePos[a][3], GatePos[a][4], GatePos[a][5]))     
  {
      if(!open[i])
      {
                MoveObject(Gate[a], GatePos[a][0],GatePos[a][1],GatePos[a][2], 5.00, GatePos[a][3], GatePos[a][4], GatePos[a][5]);
                open[i] = false;
            }
}


It has the same logic that Sjomp suggested the difference is this is the longer code :)

Clucker

Fixed it now by adding TollPaid[MAX_PLAYERS][MAX_TOLLGATE]! thanks guys..

Here's the youtube video:



public TollGate_Open(){

    for(new i=GetMaxPlayers(); i > -1; i--)
    {
        for(new a; a<sizeof(GatePos); a++)
        {
            //If Player is in range of toll gate AND if open is false
            if(IsPlayerInRangeOfPoint(i, 6, GatePos[a][0],GatePos[a][1],GatePos[a][2]) && GetPlayerVehicleSeat(i) == 0)
            {
                if(TollPaid[i][a] == 0)
                {
                    TollPaid[i][a] = 1;
                    MoveObject(Gate[a], GatePos[a][0], GatePos[a][1], GatePos[a][2]+0.1, 0.15, GatePos[a][3], 0.0, GatePos[a][5]);
                    GivePlayerMoney(i,-20);
                    GameTextForPlayer(i,"$20\nToll Paid",3000,4);
                }
            }
            else
            {
                //If already paid then close the gate
                if(TollPaid[i][a] == 1){
                    MoveObject(Gate[a], GatePos[a][0], GatePos[a][1], GatePos[a][2]-0.01, 0.15, GatePos[a][3], GatePos[a][4], GatePos[a][5]);
                    TollPaid[i][a] = 0;
                }
            }
        }
    }
   
    return 1;
}