toll gate problem...
#1

hey guys,

i have this toll made but now i have problem..
when a player passes the toll it should only reduce the players money with $30 once... but it does alot of times... can pls anyone tell me whats wrong with this code and how to fix it?
pawn Код:
if(IsPlayerInRangeOfPoint(playerid, 10.0,3321.10009766,-2070.80004883,20.10000038))
    {
        for (new i = 0; i < MAX_PLAYERS; i++)
        {
            if (IsPlayerConnected(i) && !IsPlayerNPC(i))
            {
                GivePlayerMoney(playerid, -30);
                SendClientMessage(playerid, COLOR_GREEN, "You have paid $30 To pass the Toll");
            }
        }
        return 1;
    }
greets niels
Reply
#2

anyone? i waited 1 day already still no replies?! pls help...
Reply
#3

Why are you using a loop? This loop went through all players and took -30 bucks 500 times.
pawn Код:
if( IsPlayerInRangeOfPoint( playerid, 10.0,3321.10009766, -2070.80004883, 20.10000038 ) )
{
    GivePlayerMoney( playerid, -30 );
    SendClientMessage( playerid, COLOR_GREEN, "You have paid $30 To pass the Toll" );

     return 1;
}
Reply
#4

I think his trying to make the gate automatic, the above code would only work in a command like /paytoll
Reply
#5

yes and no XD,
that thing that you tried toreno i already have tried too XD but that aint working too then its also reducing the money for lots of times XD

and yes im trying to make auto gates but not with a command but just automatic when a player drives through the toll XD there arent objects which stops them and only opesn when doing paytoll but just automatic reduces the money with $30 once... not more then 1 but it is reducing lotso f times now... pls help...
Reply
#6

@Hoborific, All I did was repairing his mistakes, because I'm not aware of where he plants code.

@niels, Where do you plant this code? in what public.
Reply
#7

im placing it under OnPlayerUpdate...
Reply
#8

Well, not only you do a loop but plants it under OnPlayerUpdate? That is the reason why it keeps taking cash a lot of times. Do this;
pawn Код:
public OnGameModeInit()
{
    SetTimer( "TollTimer", 500, true );

    return 1;
}
pawn Код:
forward TollTimer();
public TollTimer()
{
    for( new a; a < MAX_PLAYERS; a++ )
    {
        if( IsPlayerInRangeOfPoint( a, 0.0, 0.0, 0.0, 10.0 ) )
        {
            // Open the gate and take money.
        }
       
        return;
    }
}
This part was taken from Hiddos' tutorial; https://sampforum.blast.hk/showthread.php?tid=279757
Reply
#9

Loops are the worse if you got to pay money -- Are these toll's for RP // Trucking GM? Whats it going to be used for?
Reply
#10

just tested toreno but still does very much times repeating.. i changed your code a little bit XD becuz it gave some errors but eehm this is what i havethe timer under ongamemodeinit is still same)
pawn Код:
forward TollTimer();
public TollTimer()
{
    for(new i; i < MAX_PLAYERS; i ++)
    {
        if(IsPlayerInRangeOfPoint(i, 10.0,3321.10009766,-2070.80004883,20.10000038))
        {
            GivePlayerMoney(i, -30);
            SendClientMessage(i, COLOR_GREEN, "You have paid $30 To pass the Toll");
            return 1;
        }
        else if(IsPlayerInRangeOfPoint(i, 10.0,3312.19995117,-2074.00000000,20.10000038))
        {
            GivePlayerMoney(i, -30);
            SendClientMessage(i, COLOR_GREEN, "You have paid $30 To pass the Toll");
            return 1;
        }
        else if(IsPlayerInRangeOfPoint(i, 10.0,3304.39990234,-2076.80004883,20.10000038))
        {
            GivePlayerMoney(i, -30);
            SendClientMessage(i, COLOR_GREEN, "You have paid $30 To pass the Toll");
            return 1;
        }
        else if(IsPlayerInRangeOfPoint(i, 10.0,3295.80004883,-2080.19995117,20.10000038))
        {
            GivePlayerMoney(i, -30);
            SendClientMessage(i, COLOR_GREEN, "You have paid $30 To pass the Toll");
            return 1;
        }
    }
    return 1;
}
pls help...

EDIT: its for my stunt server, i have a island but i want people to pay toll evey time they go over the bridge XD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)