Decreasing No. of timers.
#1

Hello,
I am making something which would take around +60 timers. So, any way i can reduce no. of timers or making the script more efficient ?

Regards,
Ronaldo_raul™.
Reply
#2

Ho'bout giving us some more details of what about you're trying to accomplish with that many timers ?
Reply
#3

I am just gonna create some pickups and vehicles.
Reply
#4

A single timer can do all the job actually.

Example with multiple timers and hard work to start/pause/stop..
pawn Код:
#include <a_samp>

public OnFilterScriptInit()
{
    SetTimer("MyFunction1", 200, true); //Every 200ms
    SetTimer("MyFunction2", 60 * 1000, true); //Every Minute
    SetTimer("MyFunction3", 2000, true); //Every 2 second
    return 1;
}

forward MyFunction1();
public MyFunction1() {}

forward MyFunction2();
public MyFunction2() {}

forward MyFunction3();
public MyFunction3() {}
Alternative Method to start/stop/pause and manage different stuff under a single timer:
pawn Код:
#include <a_samp>

new F1, F2, F3;
new bool:F1Enabled, bool:F2Enabled, bool:F3Enabled;

public OnFilterScriptInit()
{
    SetTimer("AllMyFunctions", 100, true);
    return 1;
}

forward AllMyFunctions();
public AllMyFunctions()
{
    F1++; F2++; F3++;

    if(F1 >= 2 && F1Enabled)
    {
        //Stuff located here will be called every 200ms (100ms ticks twice, which means 200ms has passed)
        F1 = 0;
    }
   
    if(F2 >= 60 * 10 && F2Enabled)
    {
        //Stuff located here will be called every minute (100ms ticks 600 times, i.e 1 minute has passed)
        F2 = 0;
    }

    if(F3 >= 60 * 10 && F3Enabled)
    {
        //Stuff located here will be called every 2000ms (100ms ticks 20 times, i.e 2000 ms)
        F3 = 0;
    }
}

stock StartFunction1()
{
    F1 = 0;
    F1Enabled = true;
}

stock PauseFunction1() F1Enabled = false;

stock ResumeFunction1() F1Enabled = true;

stock StopFunction1()
{
    F1Enabled = false;
    F1 = 0;
}
Untested, but this should probably work.
Reply
#5

Quote:
Originally Posted by iPLEOMAX
Посмотреть сообщение
A single timer can do all the job actually.

Example with multiple timers and hard work to start/pause/stop..
pawn Код:
#include <a_samp>

public OnFilterScriptInit()
{
    SetTimer("MyFunction1", 200, true); //Every 200ms
    SetTimer("MyFunction2", 60 * 1000, true); //Every Minute
    SetTimer("MyFunction3", 2000, true); //Every 2 second
    return 1;
}

forward MyFunction1();
public MyFunction1() {}

forward MyFunction2();
public MyFunction2() {}

forward MyFunction3();
public MyFunction3() {}
Alternative Method to start/stop/pause and manage different stuff under a single timer:
pawn Код:
#include <a_samp>

new F1, F2, F3;
new bool:F1Enabled, bool:F2Enabled, bool:F3Enabled;

public OnFilterScriptInit()
{
    SetTimer("AllMyFunctions", 100, true);
    return 1;
}

forward AllMyFunctions();
public AllMyFunctions()
{
    F1++; F2++; F3++;

    if(F1 >= 2 && F1Enabled)
    {
        //Stuff located here will be called every 200ms (100ms ticks twice, which means 200ms has passed)
        F1 = 0;
    }
   
    if(F2 >= 60 * 10 && F2Enabled)
    {
        //Stuff located here will be called every minute (100ms ticks 600 times, i.e 1 minute has passed)
        F2 = 0;
    }

    if(F3 >= 60 * 10 && F3Enabled)
    {
        //Stuff located here will be called every 2000ms (100ms ticks 20 times, i.e 2000 ms)
        F3 = 0;
    }
}

stock StartFunction1()
{
    F1 = 0;
    F1Enabled = true;
}

stock PauseFunction1() F1Enabled = false;

stock ResumeFunction1() F1Enabled = true;

stock StopFunction1()
{
    F1Enabled = false;
    F1 = 0;
}
Untested, but this should probably work.
WOW!

Thank you. I would try this out.
Reply
#6

I can't see how calling a timer every 100 MS to only do a function every minute (59900 calls wasted) is more efficient..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)