Problem with foreach?
#10

It really depends on what you're trying to do.

You're trying to make a speedometer so instead of using a timer, use the OnPlayerUpdate callback. It gets called around 30 times a sec, and it has a playerid parameter so you can avoid issues with foreach.

But if you actually need a timer use y_timers.
pawn Код:
task Timer[1000]()
{
    foreach(Player, i)
    {
        // if the player is in a vehicle
        if(IsPlayerInAnyVehicle(i))
        {
            // math code here
            // textdraw code here
        }
    }
    return 1;
}
With y_timers, you don't have to use SetTimer, you don't have to forward any timers. The number between the [ ] is the tick rate, put in how often in milliseconds you want the function to be called.
Reply


Messages In This Thread
Problem with foreach? - by Tee - 26.06.2012, 04:29
Re: Problem with foreach? - by ViniBorn - 26.06.2012, 04:38
Re: Problem with foreach? - by Tee - 26.06.2012, 04:46
Re: Problem with foreach? - by ViniBorn - 26.06.2012, 04:57
Re: Problem with foreach? - by Tee - 26.06.2012, 05:00
Re: Problem with foreach? - by ViniBorn - 26.06.2012, 05:05
Re: Problem with foreach? - by Tee - 26.06.2012, 05:41
Re: Problem with foreach? - by ReneG - 26.06.2012, 05:43
Re: Problem with foreach? - by Tee - 26.06.2012, 05:50
Re: Problem with foreach? - by ReneG - 26.06.2012, 06:26

Forum Jump:


Users browsing this thread: 1 Guest(s)