SA-MP Forums Archive
Question about 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: Question about timers (/showthread.php?tid=611577)



Question about timers - MayaEU - 08.07.2016

Hello, it is possible to make a timer that is random from 20 seconds to 60 seconds?

pawn Код:
SetTimerEx("TestTimer", 30000, false, "i", playerid);



Re: Question about timers - SyS - 08.07.2016

PHP код:
SetTimerEx("TestTimer"random(60000-20000+1)+20000false"i"playerid); 



Re: Question about timers - diego200052 - 08.07.2016

Yes:

pawn Код:
SetTimerEx("TestTimer", 20000+(random(40)*1000), false, "i", playerid);



Re: Question about timers - MayaEU - 08.07.2016

Thank you


Re: Question about timers - SyS - 08.07.2016

Quote:
Originally Posted by diego200052
Посмотреть сообщение
Yes:

pawn Код:
SetTimerEx("TestTimer", 20000+(random(40)*1000), false, "i", playerid);
you know that wont work right? +1 is also required


Re: Question about timers - diego200052 - 08.07.2016

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
you know that wont work right? +1 is also required
Why?


Re: Question about timers - SyS - 08.07.2016

Quote:
Originally Posted by diego200052
Посмотреть сообщение
Why?
i can simply tell with example
random(2) gives two possible outputs 0 and 1 that means random(x) gives 0 to x-1 numbers
so to find range of random the programm should be like this
random(upperlimit-lowerlimit+1)+lowerlmit
for eg in this case for finding the random in range 20 to 60 seconds
it should be like this
random(60000-20000+1)+20000
or
random(40000+1)+20000
random(40000) will only give values up to 39 seconds and that plus 20 gives 59(maximum possible) not 60
so to get 60 we adds 1 to it
random(40001)+20000 give MAX-60000 or 60 seconds and MIN-200000 or 20 seconds


Re: Question about timers - diego200052 - 08.07.2016

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
i can simply tell with example
random(2) gives two possible outputs 0 and 1 that means random(x) gives 0 to x-1 numbers
so to find range of random the programm should be like this
random(upperlimit-lowerlimit+1)+lowerlmit
for eg in this case for finding the random in range 20 to 60 seconds
it should be like this
random(60000-20000+1)+20000
or
random(40000+1)+20000
random(40000) will only give values up to 39 seconds and that plus 20 gives 59(maximum possible) not 60
so to get 60 we adds 1 to it
random(40001)+20000 give MAX-60000 or 60 seconds and MIN-200000 or 20 seconds
Thanks, I understood perfectly


Re: Question about timers - SickAttack - 08.07.2016

pawn Код:
SetTimerEx("TestTimer", (random(40001) + 20000), false, "i", playerid);