Raised This Month: $ Target: $400
 0% 

Set_Task Question


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Artifact
Veteran Member
Join Date: Jul 2010
Old 05-04-2016 , 15:47   Set_Task Question
Reply With Quote #1

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

2.

3.

4.
__________________

Last edited by Artifact; 05-04-2016 at 15:50.
Artifact is offline
skz
Senior Member
Join Date: Jul 2014
Location: Portugal
Old 05-04-2016 , 16:44   Re: Set_Task Question
Reply With Quote #2

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
__________________
skz is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-04-2016 , 16:52   Re: Set_Task Question
Reply With Quote #3

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?
OciXCrom is offline
Send a message via Skype™ to OciXCrom
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 05-04-2016 , 17:05   Re: Set_Task Question
Reply With Quote #4

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.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 05-04-2016 at 17:06.
EFFx is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-04-2016 , 17:32   Re: Set_Task Question
Reply With Quote #5

Please ignore the post above if you don't want to get totally confused. The examples shown in it are totally incorrect.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 05-04-2016 , 17:37   Re: Set_Task Question
Reply With Quote #6

Quote:
Originally Posted by OciXCrom View Post
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
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-04-2016 , 18:54   Re: Set_Task Question
Reply With Quote #7

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.
__________________

Last edited by Bugsy; 05-04-2016 at 18:55.
Bugsy is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-04-2016 , 20:19   Re: Set_Task Question
Reply With Quote #8

Quote:
Originally Posted by EFFx View Post
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.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 05-04-2016 , 20:25   Re: Set_Task Question
Reply With Quote #9

Quote:
Originally Posted by OciXCrom View Post
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.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 05-04-2016 at 20:25.
EFFx is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-05-2016 , 06:04   Re: Set_Task Question
Reply With Quote #10

Exactly. Learn how to help him.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
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 18:39.


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