Raised This Month: $ Target: $400
 0% 

Set_Task Question


Post New Thread Reply   
 
Thread Tools Display Modes
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 05-05-2016 , 07:09   Re: Set_Task Question
Reply With Quote #11

Quote:
Originally Posted by Bugsy View Post
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.
You most certainly can check and remove the task since the id is set by default to 0.
task_exists() and remove_task() will do the job just fine.

Code:
public plugin_init() {     register_plugin("Test Plugin 5", "", "[ --{-@ ]");         set_task(0.1, "task1");     set_task(0.2, "task2", 1);     server_print("task1: %s", task_exists() ? "true" : "false");     remove_task();     server_print("task1: %s", task_exists() ? "true" : "false"); } public task1()     server_print("task1"); public task2()     server_print("task2");

Code:
task1: true
task1: false
task2
__________________

Last edited by Black Rose; 05-05-2016 at 07:12.
Black Rose is offline
Artifact
Veteran Member
Join Date: Jul 2010
Old 05-06-2016 , 00:23   Re: Set_Task Question
Reply With Quote #12

Quote:
Originally Posted by Bugsy View Post
Read and understand this:
Code:
native set_task(Float:time, const function[], id = 0, const any:parameter[] = "", len = 0, const flags[] = "", repeat = 0);
Thanks all for ur time, but I anyway don't get it.

If ID is player id, why to use it on task?
PHP Code:
public somethingid )
       
set_task(timetask
This will work anyway on single player, without using some id and random numbers right?

And why someone call task if they want that task? :O
PHP Code:
    server_print("task1: %s"task_exists() ? "true" "false");
    
remove_task(); 
__________________
Artifact is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-06-2016 , 03:16   Re: Set_Task Question
Reply With Quote #13

Let's say for example you have a shop plugin and the item invisibility. When the player buys invisibility, you want it to last for only 15 seconds. To do that, you need to set a task on 15 seconds which will execute a function that removes the player's invisibility. You will need to use function(id) , therefore you must use id in set_task, otherwise you won't be able to pass the parameter in the function itself. If the function doesn't require player id, you don't use it in the task.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-06-2016 , 19:34   Re: Set_Task Question
Reply With Quote #14

Here's a demo plugin that should hopefully clear things up.
  • Unique task-id's for each command type are used to differentiate them from one another.
  • This task-id is used to remove each of the tasks that could be running when a player disconnects. Without doing this, you would get the below error if a player disconnected while he has either of the items (gravity, godmode,noclip).
Code:
L 05/06/2016 - 19:29:38: [FUN] Invalid player 9
L 05/06/2016 - 19:29:38: [AMXX] Displaying debug trace (plugin "untitled.amxx", version "0.1")
L 05/06/2016 - 19:29:38: [AMXX] Run time error 10: native error (native "set_user_noclip")
L 05/06/2016 - 19:29:38: [AMXX]    [0] Untitled.sma::RemoveNoClip (line 100)
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fun>

new const Version[] = "0.1";

const 
Task_Gravity 445566;
const 
Task_GodMode 556677;
const 
Task_NoClip 1234;

public 
plugin_init() 
{
    
register_plugin"Set Task" Version "0.1" );
    
    
register_clcmd"give_gravity" "GiveGravity" );
    
register_clcmd"give_godmode" "GiveGodMode" );
    
register_clcmd"give_noclip" "GiveNoClip" );
}

public 
client_disconnectid )
{
    
remove_taskid Task_Gravity );
    
remove_taskid Task_GodMode );
    
remove_taskid Task_NoClip );
}

public 
GiveGravityid )
{
    new 
szArgs33 ] , iPlayer;
    new 
arrData[] = "Gravity removed!";
    
    
read_argvszArgs charsmaxszArgs ) );
    
    
iPlayer cmd_targetid szArgs );
    
    if ( 
iPlayer )
    {
        
set_user_gravityiPlayer 0.1 );
        
client_printiPlayer print_chat "* You have Gravity for 10 seconds!" );
        
set_task10.0 "RemoveGravity" iPlayer Task_Gravity arrData sizeofarrData ) );
    }
}

public 
RemoveGravityarrData[] , iTaskID )
{
    new 
iPlayer iTaskID Task_Gravity;
    
    
set_user_gravityiPlayer 1.0 );
    
client_printiPlayer print_chat "* %s" arrData );
}

public 
GiveGodModeid )
{
    new 
szArgs33 ] , iPlayer;
    new 
arrData[] = "God Mode removed!";
    
    
read_argvszArgs charsmaxszArgs ) );
    
    
iPlayer cmd_targetid szArgs );
    
    if ( 
iPlayer )
    {
        
set_user_godmodeiPlayer );
        
client_printiPlayer print_chat "* You have God Mode for 10 seconds!" );
        
set_task10.0 "RemoveGodMode" iPlayer Task_GodMode arrData sizeofarrData ) );
    }
}

public 
RemoveGodModearrData[] , iTaskID )
{
    new 
iPlayer iTaskID Task_GodMode;
    
    
set_user_godmodeiPlayer );
    
    
client_printiPlayer print_chat "* %s" arrData );
}

public 
GiveNoClipid )
{
    new 
szArgs33 ] , iPlayer;
    new 
arrData[] = "No Clip removed!";
    
    
read_argvszArgs charsmaxszArgs ) );
    
    
iPlayer cmd_targetid szArgs );
    
    if ( 
iPlayer )
    {
        
set_user_noclipiPlayer );
        
client_printiPlayer print_chat "* You have No Clip for 10 seconds!" );
        
set_task10.0 "RemoveNoClip" iPlayer Task_Gravity arrData sizeofarrData ) );
    }
}

public 
RemoveNoCliparrData[] , iTaskID )
{
    new 
iPlayer iTaskID Task_Gravity;
    
    
set_user_noclipiPlayer 0);
    
client_printiPlayer print_chat "* %s" arrData );

__________________
Bugsy is offline
Artifact
Veteran Member
Join Date: Jul 2010
Old 05-08-2016 , 03:30   Re: Set_Task Question
Reply With Quote #15

Thanks you two, now I get it
__________________
Artifact is offline
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