AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Set_Task Question (https://forums.alliedmods.net/showthread.php?t=282333)

Artifact 05-04-2016 15:47

Set_Task Question
 
+All right, I see many of plugin for now and I don't know why people set tasks with:
1.

2.

3.

4.

skz 05-04-2016 16:44

Re: Set_Task Question
 
2- Because if you want to make a task just for one player (or players that are assigned in the variable "id"), you have to make that way
3- I've never seen something like that, so I don't know
4- I always do that but I can't explain why too

OciXCrom 05-04-2016 16:52

Re: Set_Task Question
 
1 - used for simple functions and tasks.
2 - used if you want to use the task on a certain player (id).
3 - a more reliable way of using it on a certain player (id). This way it won't get mixed up with other tasks. Let's say for example you have multiple set_task functions and all of them use "id". If you use remove_task(id), it will remove all of them, but instead you want to remove only one, so that's way you mix the id with a random number and you set different numbers on different tasks, and then you substracts that number from the id, so it will remove that task only.
4 - what kind of a loop are you talking about? If the task is set on 5 seconds for example and you use remove_task within those seconds, it will remove the task?

EFFx 05-04-2016 17:05

Re: Set_Task Question
 
1. if have (id) after the function, you need id+TaskRandom
in the function you need to add:

PHP Code:

public function(id)
{
    
id -= TaskRandom// ( if inst enum )


Example for a set_task with enum:

PHP Code:

enum(+= 1000)
{
     
RandomTask


If inst enum
Will be

PHP Code:

new TaskRandom 13313510

public function(id)
{
   
id -= TaskRandom


If have not (id) in the function, you can add set_task(time,function), just it.

set_task(time,function,id) is a bad way because will cause conflits.

Have this format for set_task:

PHP Code:

enum(+= 1000)
{
      
TaskRandom
}

set_task(3.0,"Function",id+TaskRandom,_,_,"b")

public Function(
id)
{
      
remove_task(id+TaskRandom)
      
//code


But i dont like it


Correct me if i'm not right.

OciXCrom 05-04-2016 17:32

Re: Set_Task Question
 
Please ignore the post above if you don't want to get totally confused. The examples shown in it are totally incorrect.

EFFx 05-04-2016 17:37

Re: Set_Task Question
 
Quote:

Originally Posted by OciXCrom (Post 2416705)
Please ignore the post above if you don't want to get totally confused. The examples shown in it are totally incorrect.

Dont talk with me, i dont call for you posts, i'm just trying to help a member, can you accept it ? Thank you

Bugsy 05-04-2016 18:54

Re: Set_Task Question
 
Read and understand this:
Code:

native set_task(Float:time, const function[], id = 0, const any:parameter[] = "", len = 0, const flags[] = "", repeat = 0);
  • time = Time interval to assign. Interval is in seconds (float: 1.0, 2.5, etc)
  • function = Function to execute. This function must be defined as public.
  • id = Task id to assign. This is a unique identifier number that you can use to check if the task exists or remove the task.
  • parameter = Data to pass through to callback. You can pass an array of data to the called function if you want to. If you pass a 'data' parameter, setup your called function as public TheFunction( TheArray[] , TaskID ). If 'data' is not used, it is public TheFunction( TaskID )
  • len = Size of data. Size of data array in previous parameter.
  • flags = Optional set of flags: If you use "a", set the number of times to repeat in the next param.
    • "a" - repeat timer a set amount of times
    • "b" - loop indefinitely until timer is stopped
    • "c" - time interval is treated as absolute time after
      map start
    • "d" - time interval is treated as absolute time before
      map change
  • repeat = If the "a" flag is set, the task will be repeated this
    many times

PHP Code:

set_task(timetask// this is right for me 

This is creating a task in its simplest form, with an interval of time and calling a function. You cannot check if the task exists or remove it.

PHP Code:

set_task(timetaskid// Why ID? O.o wtf? 

This is creating a task and assigning an identifier using the player id. This allows you to check if the task exists and/or remove it. Using the player id as the identifier is common in plugins where set_task is only used for one purpose--in this case it is ok to just use the player id. If you have multiple uses for set_task in a plugin and you need to possibly remove or check if the task exists, you then need to add something to make the identifier unique for each task type. eg. id + 2313 for task to kick, id + 2500 for ban, id + 3000 for gravity, etc. It's best to define a constant so you know what each is for: const TaskA = 43443, const TasbB = 999 then do id + TaskA when creating the task.

PHP Code:

set_task(timetaskid random number// So why????
// Every player got uniqe ID right? for what he need random num? 

I don't understand what use this has since the task has an identifier, but there's know way to know what it is until the function is called, and you have no way to determine the player id (or whatever id) it was called upon.

PHP Code:

set_task(timetasksome task id something
remove_task
(task id something// Why you remove task if there is no loop? :O 

Here when the task is created, it is done using the player id (say 13) and something as the identifier, say 3333. When 'task' function is called, 13 + 3333 is passed to it (3346), to get the player id you take 3346 - 3333 = 13 and you can act on that player. remove_task() is commonly called on client_disconnect() because if a task is set on a player for say 10 seconds but he disconnects after 5 seconds, you may want to remove the task to prevent functions (get_user_name(), etc) from being called because you will get an error for calling functions on a disconnected player. In the case of functions that repeat, you can understand without me telling you why you would need to use remove_task.

OciXCrom 05-04-2016 20:19

Re: Set_Task Question
 
Quote:

Originally Posted by EFFx (Post 2416707)
Dont talk with me, i dont call for you posts, i'm just trying to help a member, can you accept it ? Thank you

What are you yelling about? You can't help him by teaching him incorrect nonsense.

EFFx 05-04-2016 20:25

Re: Set_Task Question
 
Quote:

Originally Posted by OciXCrom (Post 2416742)
What are you yelling about? You can't help him by teaching him incorrect nonsense.

Stop reply that reason now, ok? Lets go learn how to help a member, bugsy has made a new tutorial, we can finish? Lets go finish that for we not get a ban from here. I dont want it.

OciXCrom 05-05-2016 06:04

Re: Set_Task Question
 
Exactly. Learn how to help him.


All times are GMT -4. The time now is 18:39.

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