Author Topic: Scripting - Charge a player in every toll gate he enters  (Read 374 times)

Offline Clucker

  • Sr. Member
  • ****
  • Posts: 423
  • cookies: 23
  • IG name: 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

Offline Sjomp

  • Administrator
  • Hero Member
  • ******
  • Posts: 3,120
  • cookies: 90
  • Jansie de Palingboer
  • IG name: Sjomp
Re: Scripting - Charge a player in every toll gate he enters
« Reply #1 on: May 08, 2020, 12:18 »
Add
Code: [Select]
new open[MAX_PLAYERS];On top and set open for the playerid you have opened the toll for.
Code: [Select]
open[playerid] = true;
I think that's your problem

Offline Clucker

  • Sr. Member
  • ****
  • Posts: 423
  • cookies: 23
  • IG name: Clucker
Re: Scripting - Charge a player in every toll gate he enters
« Reply #2 on: May 08, 2020, 16:14 »
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?

Offline Sjomp

  • Administrator
  • Hero Member
  • ******
  • Posts: 3,120
  • cookies: 90
  • Jansie de Palingboer
  • IG name: Sjomp
Re: Scripting - Charge a player in every toll gate he enters
« Reply #3 on: May 09, 2020, 08:54 »
Change
Code: [Select]
if(!open[i]){to
Code: [Select]
else if(open[i]){I think open should be true here right?

Offline Zeke

  • Rookie
  • *
  • Posts: 16
  • cookies: 0
  • Filipino Tycoon
  • IG name: Zeke
Re: Scripting - Charge a player in every toll gate he enters
« Reply #4 on: May 09, 2020, 13:30 »
Try getting the range of the player before closing the gate

something like this but not exactly.
Code: [Select]
     
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;
            }
}
Pawn Scripter


Offline Clucker

  • Sr. Member
  • ****
  • Posts: 423
  • cookies: 23
  • IG name: Clucker
Re: Scripting - Charge a player in every toll gate he enters
« Reply #5 on: May 09, 2020, 13:56 »
Change
Code: [Select]
if(!open[i]){to
Code: [Select]
else if(open[i]){I think open should be true here right?

tried it but still the same problem. no change.

Offline Clucker

  • Sr. Member
  • ****
  • Posts: 423
  • cookies: 23
  • IG name: Clucker
Re: Scripting - Charge a player in every toll gate he enters
« Reply #6 on: May 09, 2020, 13:57 »
Try getting the range of the player before closing the gate

something like this but not exactly.
Code: [Select]
     
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 :)

Offline Clucker

  • Sr. Member
  • ****
  • Posts: 423
  • cookies: 23
  • IG name: Clucker
Re: Scripting - Charge a player in every toll gate he enters
« Reply #7 on: May 10, 2020, 04:09 »
Fixed it now by adding TollPaid[MAX_PLAYERS][MAX_TOLLGATE]! thanks guys..

Here's the youtube video:


Code: [Select]
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;
}

 

anything