AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   random set_task timer. (https://forums.alliedmods.net/showthread.php?t=220937)

vamppa 07-16-2013 05:56

random set_task timer.
 
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" ); 


K1d0x 07-16-2013 06:02

Re: random set_task timer.
 
Quote:

set_task ( random_float(15, 30) , "Taskwork", 50, "", 0, "b" );

vamppa 07-16-2013 06:06

Re: random set_task timer.
 
thanks!

YamiKaitou 07-16-2013 08:08

Re: random set_task timer.
 
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

Blizzard_87 07-16-2013 08:24

Re: random set_task timer.
 
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

vamppa 07-16-2013 12:19

Re: random set_task timer.
 
hm so in the example you have given blizzard it would be possible to get it random on an repeating task?

K1d0x 07-16-2013 12:51

Re: random set_task timer.
 
Of course:
PHP Code:

    set_taskg_iTaskTimer"FunctionSetTask"id _"b" ); // set same task with NEW random number 


Blizzard_87 07-17-2013 01:28

Re: random set_task timer.
 
No.
Reason. YamiKaitou said above.

K1d0x 07-17-2013 07:30

Re: random set_task timer.
 
Quote:

Originally Posted by Blizzard_87 (Post 1992627)
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 */



YamiKaitou 07-17-2013 09:14

Re: random set_task timer.
 
Quote:

Originally Posted by K1d0x (Post 1992785)
stuff

Global variable is not needed in your example, just call random_float directly


All times are GMT -4. The time now is 06:20.

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