Decreasing No. of timers. - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Decreasing No. of timers. (
/showthread.php?tid=330215)
Decreasing No. of timers. -
Ronaldo_raul™ - 31.03.2012
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™.
Re: Decreasing No. of timers. -
antonio112 - 31.03.2012
Ho'bout giving us some more details of what about you're trying to accomplish with that many timers ?
Re: Decreasing No. of timers. -
Ronaldo_raul™ - 31.03.2012
I am just gonna create some pickups and vehicles.
Re: Decreasing No. of timers. -
iPLEOMAX - 31.03.2012
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.
Re: Decreasing No. of timers. -
Ronaldo_raul™ - 31.03.2012
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.
Re: Decreasing No. of timers. -
MP2 - 31.03.2012
I can't see how calling a timer every 100 MS to only do a function every minute (59900 calls wasted) is more efficient..