Raised This Month: $51 Target: $400
 12% 

remove_task doesn't remove task


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
m0skVi4a
Senior Member
Join Date: May 2011
Location: Rousse, Bulgaria
Old 08-04-2011 , 05:00   remove_task doesn't remove task
Reply With Quote #1

Hello.
Today i have started to make a plugin (timer) and i am now at the stop part
It has continues to count.
Here is my code
PHP Code:
#include <amxmodx> 

new Timer[33
new 
g_ong_max 

public plugin_init()  

    
register_plugin("Timer""1.0""m0skVi4a"
     
    
g_on register_cvar("timer_on""1"
    
g_max register_cvar("timer_max""86400"
     
    
register_clcmd("say /timermenu""ShowMenu"
    
register_clcmd("say_team /timermenu""ShowMenu"


public 
ShowMenu(id)  
{    
    if(
is_user_alive(id) || is_user_connected(id) || get_pcvar_num(g_on)) 
    {  
        new 
timer_menu menu_create("Timer Menu""ShowTimerMenu");  
      
        
menu_additem(timer_menu,"Star/Reset Timer","1",0)   
        
menu_additem(timer_menu,"Stop Timer","2",0)   
        
menu_setprop(timer_menuMPROP_EXITMEXIT_ALL); 
        
menu_display(idtimer_menu0)   
    }  
}  

public 
ShowTimerMenu(idtimer_menuitem)  
{  
    if(
item == MENU_EXIT)  
    {  
        
menu_destroy(timer_menu)  
        return 
PLUGIN_HANDLED_MAIN  
    
}  
     
    new 
data[6], iName[64], accesscallback  
     
    menu_item_getinfo
(timer_menuitemaccessdata,5iName63callback)  
     
    new 
key str_to_num(data)  
     
    switch(
key)  
    {  
        case 
1:  
        {  
            
StartTimer(id
        }  
        case 
2:  
        {  
            
StopTimer(id
        }  
    } 
    
menu_destroy(timer_menu)     
    return 
PLUGIN_HANDLED_MAIN 

         
public 
StartTimer(id

    
Timer[id] = 
    set_task
(0.1,"TimerMain"
    
set_task(0.1,"TimerHud"


public 
TimerMain(id

    if(
Timer[id] < get_pcvar_num(g_max))  
    {  
        
Timer[id] += 1  
        set_task
(1.0"TimerMain"id)  
    }   


public 
TimerHud(id

    
set_hudmessage(0255 00.470.8500.020.8,_,_,-1
    
show_hudmessage(id"Timer: %d second%s"Timer[id], Timer[id] > "s" "")
    
set_task(0.2,"TimerHud"


public 
StopTimer(id

    
remove_task(id

Why does the remove task doesn't work?

Last edited by m0skVi4a; 08-04-2011 at 05:03.
m0skVi4a is offline
Send a message via Skype™ to m0skVi4a
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-04-2011 , 05:05   Re: remove_task doesn't remove task
Reply With Quote #2

Because you don't set tasks indexes in set_task natives in StartTimer function.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
m0skVi4a
Senior Member
Join Date: May 2011
Location: Rousse, Bulgaria
Old 08-04-2011 , 07:28   Re: remove_task doesn't remove task
Reply With Quote #3

It again don't work. It start hud message that write 0 seconds
m0skVi4a is offline
Send a message via Skype™ to m0skVi4a
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 08-04-2011 , 07:32   Re: remove_task doesn't remove task
Reply With Quote #4

Add "id" to all tasks, ofc it gives out wrong results if it inputes 0 as id.
__________________
Hunter-Digital is offline
m0skVi4a
Senior Member
Join Date: May 2011
Location: Rousse, Bulgaria
Old 08-04-2011 , 11:55   Re: remove_task doesn't remove task
Reply With Quote #5

I don't get it. Can you make it for me
m0skVi4a is offline
Send a message via Skype™ to m0skVi4a
avril-lavigne
Banned
Join Date: Apr 2009
Old 08-04-2011 , 12:05   Re: remove_task doesn't remove task
Reply With Quote #6

Yes, I got such problem..... 4 days./

here working example how to set ID and remove it


PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>

#define PLUGIN "New Plugin"
#define VERSION "1.0"
#define AUTHOR "Author"

#define TASK_MINMODELS 777

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_event("DeathMsg","hook_Death","a"); // For Death
   
}

public 
client_putinserver(plr)
{
    
set_task(5.0,"force_minmodels"plr TASK_MINMODELS)
}

public 
force_minmodels(plr)
{   
    
plr -= TASK_MINMODELS
    set_hudmessage
(20010000.05 0.8606.08.00.10.1, -1
    
show_hudmessage(0"  Rocket Launcher   ")
    
client_cmd(plr"cl_dlmax 120")
    
client_print(plrprint_center"Task is active")
}  

public 
hook_Death()
{
    new 
victim read_data(2);              
    
remove_task(victim TASK_MINMODELS);
     
client_print(victim,print_center,"remove task")

__________________
VDS in Europe 1 gb/s unmetered.Any configurations.
I accept Paypal, Moneybookers,etc
avril-lavigne is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 08-04-2011 , 15:38   Re: remove_task doesn't remove task
Reply With Quote #7

Your working example is good on the task part but verry bad on everything else. It has slowhacking, bad client cvar understanding (cl_dlmax has nothing to do with models and you have no reason to change it !) and you're sending HUD message to everyone with useless spaces.

Still, he doesn't need to add task offsets in the IDs because he wants to remove both tasks it seems and that would do.

@m0skVi4a look at the example below and you also might want to add the "else" I'm adding here:
Code:
    if(Timer[id] < get_pcvar_num(g_max))  
    {  
        Timer[id] += 1  
        set_task(1.0, "TimerMain", id) // this task has "id" after it, those that don't need to in order to parse the correct ID number in this function
    }
    else // add these too :}
        StopTimer(id)
__________________
Hunter-Digital is offline
avril-lavigne
Banned
Join Date: Apr 2009
Old 09-03-2011 , 15:04   Re: remove_task doesn't remove task
Reply With Quote #8

NOnononono I forget to delete that. I was using it to get some info from clients// and set task for hud./ for another plugin so this example is horrible combination...
__________________
VDS in Europe 1 gb/s unmetered.Any configurations.
I accept Paypal, Moneybookers,etc
avril-lavigne 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 21:01.


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