AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Check if() Task done . (https://forums.alliedmods.net/showthread.php?t=173096)

Stressful 11-30-2011 03:53

Check if() Task done .
 
How to check if a "task" is done ? And when its done , The "task" would stop what its doing .

Devil259 11-30-2011 06:27

Re: Check if() Task done .
 
Code:
new bool:taskDone set_task( time , "function" ) public function( ) {     taskDone = true } public checkTaskDone( ) {     if( taskDone )     {         // ...     } }

fl0werD 11-30-2011 06:35

Re: Check if() Task done .
 
PHP Code:

new Float:g_flTask[33];
new 
bool:g_bTask[33];

public function(
id)
{
    
g_bTask[id] = true;
    
g_flTask[id] = get_gametime() + 5.0;
}

public 
client_PreThink(id)
{
    if(!
g_bTask[id])
        return;

    if(
g_flTask[id] <= get_gametime())
    {
        
g_bTask[id] = false;

        
// task done;
    
}



Snaker beatter 11-30-2011 06:38

Re: Check if() Task done .
 
Just add g_task = true on the task's function

fl0werD 11-30-2011 06:59

Re: Check if() Task done .
 
Quote:

Originally Posted by Snaker beatter (Post 1605137)
Just add g_task = true on the task's function

Edited.

drekes 11-30-2011 07:09

Re: Check if() Task done .
 
task_exists
When it returns 0, the task finished.

Stressful 12-01-2011 22:01

Re: Check if() Task done .
 
I tried that but the plugin just skip the task . And when I swap their places , The task just keep repeating and repeating the same thing .
PHP Code:



    if(
g_flTask[id] <= get_gametime()) 
    { 
        
g_bTask[id] = false

        
// task done; 
    

    
if(!
g_bTask[id]) 
        return; 



ConnorMcLeod 12-01-2011 23:41

Re: Check if() Task done .
 
Quote:

Originally Posted by Stressful (Post 1606092)
I tried that but the plugin just skip the task . And when I swap their places , The task just keep repeating and repeating the same thing .
PHP Code:



    if(
g_flTask[id] <= get_gametime()) 
    { 
        
g_bTask[id] = false

        
// task done; 
    

    
if(!
g_bTask[id]) 
        return; 



You have tried the worst code that has been given.

drekes code will telle you if a task is finished or hasn't been launched yet.
Devil259 code is little better.
If you understand both codes, you can do something ok.

fl0werD's code is the exact example of what you must NOT do.

fysiks 12-02-2011 00:10

Re: Check if() Task done .
 
Quote:

Originally Posted by Stressful (Post 1605086)
And when its done , The "task" would stop what its doing .

When the task is done it stops what it's doing. That is the way it's designed to work. Therefore, this part of your request means nothing.

I would suggest you tell us what you are ACTUALLY trying to do as you are likely asking the wrong questions.

Devil259 12-02-2011 01:03

Re: Check if() Task done .
 
Quote:

Originally Posted by ConnorMcLeod (Post 1606111)
fl0werD's code is the exact example of what you must NOT do.

Because of using client_PreThink :3


All times are GMT -4. The time now is 08:28.

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