AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] Set_Task question (https://forums.alliedmods.net/showthread.php?t=278891)

Depresie 02-10-2016 08:01

[HELP] Set_Task question
 
So let's say we have this, is there any good way to execute a code in the burning_flame function every two seconds?

PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "White"

#define TASK_BURN 304943
#define ID_BURN (taskid - TASK_BURN)


public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
client_cmd("command""function")
    
    
// Add your code here...
}

public function(
id)
{
    
set_task(0.2"burning_flame"victim+TASK_BURN__"b")
}

public 
burning_flame(taskid)
{
    



klippy 02-10-2016 08:19

Re: [HELP] Set_Task question
 
Use 2.0 instead of 0.2 as the first argument in set_task()? Your example is not good enough if that's not what you want, give us more info.

Depresie 02-10-2016 08:33

Re: [HELP] Set_Task question
 
Well, i want to do something like this
Without the need to set one more task

PHP Code:

public function(id)
{
    
set_task(0.2"burning_flame"victim+TASK_BURN__"b")
}

public 
burning_flame(taskid)
{
    
every 2 seconds
    
{
        
execute and this code
    
}
    
    
execute this code



NiHiLaNTh 02-10-2016 08:37

Re: [HELP] Set_Task question
 
well you can create a var that holds next burn sound time like:

Code:

new Float:g_flNextBurnSound[33];

....

public burning_flame(taskid)
{
.....

if (g_flNextBurnSound[ID_BURN] <= get_gametime())
{
      ///emit sound here
      g_flNextBurnSound[ID_BURN] = get_gametime() + 2.0;
}
...
}


wickedd 02-10-2016 08:41

Re: [HELP] Set_Task question
 
You can use a thinking entity, read this.

Depresie 02-10-2016 08:49

Re: [HELP] Set_Task question
 
any other ideea without the need of an array or thinking entities?
maybe with switch and cases? i know how to do it using a random num, but i want exactly at 2.0 seconds

klippy 02-10-2016 08:59

Re: [HELP] Set_Task question
 
Just use two tasks? Or just use what has been already suggested by others.

fysiks 02-10-2016 09:00

Re: [HELP] Set_Task question
 
Quote:

Originally Posted by Depresie (Post 2391720)
any other ideea without the need of an array or thinking entities?
maybe with switch and cases? i know how to do it using a random num, but i want exactly at 2.0 seconds

What in the world does a random number have anything to do with it?

If you want something to execute every two seconds, set the time for your tast to 2.0 seconds. If you want it to be called immediately, in addition to the task, call the function directly before setting the task.

siriusmd99 02-10-2016 09:38

Re: [HELP] Set_Task question
 
2/0.2 =10 so:

PHP Code:


new count[33]

public 
burning_flame(taskid)
{
    if(
count[taskid]==10)
    {
       
// yourcode for 2 sec
       
count[taskid]=//reseting counter
    
}
   
//yourcode for 0.2 sec
    
count[taskid]++     //adding +1 every 0.2 seconds


And don't forget do add count[id]=0 when player executes the command and starts the task.

Depresie 02-10-2016 15:57

Re: [HELP] Set_Task question
 
done, thanks, i tought there is a better method, but, i went with the array and counter


All times are GMT -4. The time now is 09:34.

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