Raised This Month: $51 Target: $400
 12% 

Create timer with 'random' duration?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Js41637
Member
Join Date: May 2013
Location: Australia, NSW
Old 01-10-2014 , 07:09   Create timer with 'random' duration?
Reply With Quote #1

I want to create a timer that will have a random duration.
I already have a basic number generator
PHP Code:
new RandomNumbersArray[9] = {4,5,6,7,8,9,10,11,12};
    new 
randomnum GetRandomInt(08);
    new 
duration RandomNumbersArray[randomnum]; 
Although I don't know how or if it is even possible to use the random number that got generated (duration) in a CreateTimer.
Js41637 is offline
Send a message via Skype™ to Js41637
xf117
Senior Member
Join Date: Mar 2010
Location: Russia
Old 01-10-2014 , 07:35   Re: Create timer with 'random' duration?
Reply With Quote #2

PHP Code:
new RandomNumbersArray[9] = {4,5,6,7,8,9,10,11,12}; 
new 
randomnum GetRandomInt(08); 
new 
duration RandomNumbersArray[randomnum];
// --------------------------------------------------------------
CreateTimer(durationTimer_Callback); 
You mean like this?

Or you can do something like this:
PHP Code:
new Float:duration GetRandomFloat(4.012.0);
CreateTimer(durationTimer_Callback); 

Last edited by xf117; 01-10-2014 at 07:36.
xf117 is offline
Send a message via ICQ to xf117
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 01-10-2014 , 10:42   Re: Create timer with 'random' duration?
Reply With Quote #3

static const Float:array[] = {4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0};
CreateTimer(array[GetRandomInt(0, sizeof(array) - 1)], Timer_Callback);

or cast the float and use an integer array
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.

Last edited by friagram; 01-10-2014 at 10:43.
friagram is offline
Marcus_Brown001
AlliedModders Donor
Join Date: Nov 2012
Location: Illinois, United States
Old 01-10-2014 , 16:35   Re: Create timer with 'random' duration?
Reply With Quote #4

Quote:
Originally Posted by xf117 View Post
PHP Code:
new RandomNumbersArray[9] = {4,5,6,7,8,9,10,11,12}; 
new 
randomnum GetRandomInt(08); 
new 
duration RandomNumbersArray[randomnum];
// --------------------------------------------------------------
CreateTimer(durationTimer_Callback); 
The first parameter for the CreateTimer native is a float. If you supply something other than a float, you will get a tag mismatch warning on compile.
Marcus_Brown001 is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 01-10-2014 , 20:42   Re: Create timer with 'random' duration?
Reply With Quote #5

solution 1:
PHP Code:
new RandomNumbersArray[9] = {4,5,6,7,8,9,10,11,12};  
new 
Float:duration float(RandomNumbersArray[GetRandomInt(0sizeof(RandomNumbersArray)-1)]); 
// -------------------------------------------------------------- 
CreateTimer(durationTimer_Callback); 
solution 2:
PHP Code:
new Float:RandomNumbersArray[9] = {4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0};  
new 
Float:duration RandomNumbersArray[GetRandomInt(0sizeof(RandomNumbersArray)-1)]; 
// -------------------------------------------------------------- 
CreateTimer(durationTimer_Callback); 
solution 3:
PHP Code:
CreateTimer(GetRandomFloat(4.012.0), Timer_Callback); 
solution 4:
PHP Code:
CreateTimer(float(GetRandomInt(412)), Timer_Callback); 

Last edited by Mathias.; 01-10-2014 at 20:43.
Mathias. is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 01-11-2014 , 22:06   Re: Create timer with 'random' duration?
Reply With Quote #6

Why do you guys declare new variables before passing them to one-time use things?
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:45.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode