Raised This Month: $ Target: $400
 0% 

random set_task timer.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
vamppa
Senior Member
Join Date: Apr 2010
Location: The Netherlands
Old 07-16-2013 , 05:56   random set_task timer.
Reply With Quote #1

yellow

how would I set the timer in set_task to be random ranging between 15-30seconds?

PHP Code:
set_task 18.0"Taskwork"50""0"b" ); 
vamppa is offline
K1d0x
Senior Member
Join Date: Apr 2012
Location: Copenhagen, Denmark
Old 07-16-2013 , 06:02   Re: random set_task timer.
Reply With Quote #2

Quote:
set_task ( random_float(15, 30) , "Taskwork", 50, "", 0, "b" );
__________________
I Hate people who can hate me !
K1d0x is offline
Send a message via Yahoo to K1d0x Send a message via Skype™ to K1d0x
vamppa
Senior Member
Join Date: Apr 2010
Location: The Netherlands
Old 07-16-2013 , 06:06   Re: random set_task timer.
Reply With Quote #3

thanks!
vamppa is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 07-16-2013 , 08:08   Re: random set_task timer.
Reply With Quote #4

It will only be random the first time it is ran, not every time. If you want it random every time, you cannot use a repeating task
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Blizzard_87
Veteran Member
Join Date: Oct 2012
Old 07-16-2013 , 08:24   Re: random set_task timer.
Reply With Quote #5

this is just a quick code... im not best at explaining things but here goes
Code:
#include <amxmodx> #include <amxmisc> #define PLUGIN "Random SetTask Number" #define VERSION "1.0" #define AUTHOR "Blizzard" new Float:g_iTaskTimer; // set as global float to hold random number. public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         g_iTaskTimer = ( random_float( 15.0, 30.0 ) ); // execute random number for first time     set_task( g_iTaskTimer, "FunctionSetTask" ); // just example for calling first task. } public FunctionSetTask( id ) {     //.. commands or what ever in here             // then set task again with random number     g_iTaskTimer = ( random_float( 15.0, 30.0 ) ); // get random number before setting task.     set_task( g_iTaskTimer, "FunctionSetTask", id ); // set same task with NEW random number } /* calling random_float before set_task in the FunctionSetTask will always change the number to random
__________________
Blizzard_87 is offline
vamppa
Senior Member
Join Date: Apr 2010
Location: The Netherlands
Old 07-16-2013 , 12:19   Re: random set_task timer.
Reply With Quote #6

hm so in the example you have given blizzard it would be possible to get it random on an repeating task?
vamppa is offline
K1d0x
Senior Member
Join Date: Apr 2012
Location: Copenhagen, Denmark
Old 07-16-2013 , 12:51   Re: random set_task timer.
Reply With Quote #7

Of course:
PHP Code:
    set_taskg_iTaskTimer"FunctionSetTask"id _"b" ); // set same task with NEW random number 
__________________
I Hate people who can hate me !
K1d0x is offline
Send a message via Yahoo to K1d0x Send a message via Skype™ to K1d0x
Blizzard_87
Veteran Member
Join Date: Oct 2012
Old 07-17-2013 , 01:28   Re: random set_task timer.
Reply With Quote #8

No.
Reason. YamiKaitou said above.
__________________

Last edited by Blizzard_87; 07-17-2013 at 01:29.
Blizzard_87 is offline
Old 07-17-2013, 05:33
Dichenth
This message has been deleted by YamiKaitou. Reason: spambot
K1d0x
Senior Member
Join Date: Apr 2012
Location: Copenhagen, Denmark
Old 07-17-2013 , 07:30   Re: random set_task timer.
Reply With Quote #9

Quote:
Originally Posted by Blizzard_87 View Post
No.
Reason. YamiKaitou said above.
PHP Code:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Random SetTask Number"
#define VERSION "1.0"
#define AUTHOR "Blizzard"

new Float:g_iTaskTimer// set as global float to hold random number.

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
g_iTaskTimer = ( random_float15.030.0 ) ); // execute random number for first time
    
set_taskg_iTaskTimer"FunctionSetTask" ); // calling first task with a random time.
}

public 
FunctionSetTaskid ) {
    
//.. commands or what ever in here
    
    
    // then set task again with random number
    
g_iTaskTimer = ( random_float15.030.0 ) ); // get random number before setting task.
    
set_taskg_iTaskTimer"Function"id ); // set same task with NEW random number
}

public Function( 
id ) {
    if(
task_exists(id)) {
        
remove_task(id);
        
FunctionSetTask(id);
    }
    
    
/* Do something here */

__________________
I Hate people who can hate me !
K1d0x is offline
Send a message via Yahoo to K1d0x Send a message via Skype™ to K1d0x
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 07-17-2013 , 09:14   Re: random set_task timer.
Reply With Quote #10

Quote:
Originally Posted by K1d0x View Post
stuff
Global variable is not needed in your example, just call random_float directly
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou 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 06:20.


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