Taxi Fare Meter
#1

Dear Members,

I've been working for some new clients of mine. They have a Roleplay server which i am developing currently. I need to code a Taxi Fare Meters but am having certain issues with it. The Fare meter will run for 60 seconds each.

Every minute it will increase
pawn Код:
playerVariables[playerid][pMyFare] =  playerVariables[playerid][pMyFare] + playerVariables[playerid][pTaxiFare]
Lets Consider an example:

A person hops into the taxi. The Fare meter will start. The fare is 6 USD. So every minute his fare is incremented to 6 USD.

What am having issues is with the callback to be called with SetTimerEx. if i call the Callback each second and increment an integer every time it is called. Then how can i check that this integer is 60 or its 60*2 or something? I need a simple if clause to check every time. I dont want to mess the codes with 100 if clauses.

If you can help it will be highly appreciated. If you need to know more about it. Please post.

Regards,
Ballu Miaa
Reply
#2

Well, here it is:

pawn Код:
playerVariables[ playerid ][ pMyFare ] += playerVariables[ playerid ][ pTaxiFare ]; // same thing


// well you can do this, I am not sure if this is the MOST efficient way to do but here it is:

// if you want to check 60 or 60*2 or 60*3 and so on you may do this

new pSeconds[ playerid ],
    pMinutes[ playerid ]; // this is not really needed but yea O_O
   

public YourTimer( playerid )
{
    pSeconds[ playerid ]++; // increments (adds by one)
   
    switch( pSeconds[ playerid ] )
    {
        case 60: // 1 minute
        {
            pSeconds[ playerid ] = 0; // making it zero for the next minute
           
            pMinutes[ playerid ]++; // counts how many minutes it has been (not really needed or maybe? just incase)
           
            // here you can now do the rest of your code according to each minute O_O
        }
    }
   
}
This was just an example, you may replace the variables with your own. If this is not what you mean, please explain

Regards FalconX
Reply
#3

This is exactly what am saying Falcon. I mean see your switch statement. I need to add a case statement to check for each minute every time. Cant that happen automatically? Or shall we divide it by 60? Like this:

If CurrentSecs%60 == 0 Then it should increment the fare? Is the logic right now?

Also your way is right and correct. I will set it to 0 always and start again. Thanks a lot Falcon. I'm glad i found you on ********. Rep+4
Reply
#4

Quote:
Originally Posted by Ballu Miaa
Посмотреть сообщение
This is exactly what am saying Falcon. I mean see your switch statement. I need to add a case statement to check for each minute every time. Cant that happen automatically? Or shall we divide it by 60? Like this:

If CurrentSecs%60 == 0 Then it should increment the fare? Is the logic right now?

Also your way is right and correct. I will set it to 0 always and start again. Thanks a lot Falcon. I'm glad i found you on ********. Rep+4
You don't really need to check for each minute in this case because

pawn Код:
public YourTimer( playerid )
{
    pSeconds[ playerid ]++;
   
    switch( pSeconds[ playerid ] )
    {
        case 60: // 1 minute
        {
            pSeconds[ playerid ] = 0;
           
            pMinutes[ playerid ]++;
           
            // here every minute is get called which means 60 seconds are completed here. So there is no need to
            // check if one minute has been completed, now here you can add the REST of the code and test it, it'll work every minute ;-)
            // just incase you want to choose 5 minutes, you may do the switch function or if clause itself
            // if( pMinutes[ playerid ] == 5 ){}// 5 minutes or
            // if( pMinutes[ playerid ] == 2 ){}// 2 minutes  and etc
        }
    }
   
}
Thanks mate, glad that I tried to help you
Reply
#5

Yeah man i got your point. I dont need to check it for each minute. I can reset it all the time and keep the loop running. You really helped me alot. Fuck yeah. Thanks man Thanks again.
Reply
#6

Quote:
Originally Posted by Ballu Miaa
Посмотреть сообщение
Yeah man i got your point. I dont need to check it for each minute. I can reset it all the time and keep the loop running. You really helped me alot. Fuck yeah. Thanks man Thanks again.
No problem mate

------------------------

Or instead of making timer for each player you can make one, and loop all the players.

pawn Код:
public GlobalTaxiTimer( )
{
    foreach( Player, i )
    {
        if( IS_PLAYER_IN_TAXI_FARE_SHIZ[ i ] ) // replace it with your vars
        {
            pSeconds[ i ]++;

            switch( pSeconds[ playerid ] )
            {
                case 60: // 1 minute
                {
                    pSeconds[ i ] = 0;

                    pMinutes[ i ]++;


                    // rest of your code in minutes
                }
            }
        }
    }
}
or if you're using timer for each player you can kill it when the fare finishes

Regards FalconX
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)