AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   remove_task doesn't remove task (https://forums.alliedmods.net/showthread.php?t=163850)

m0skVi4a 08-04-2011 05:00

remove_task doesn't remove task
 
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?

ConnorMcLeod 08-04-2011 05:05

Re: remove_task doesn't remove task
 
Because you don't set tasks indexes in set_task natives in StartTimer function.

m0skVi4a 08-04-2011 07:28

Re: remove_task doesn't remove task
 
It again don't work. It start hud message that write 0 seconds

Hunter-Digital 08-04-2011 07:32

Re: remove_task doesn't remove task
 
Add "id" to all tasks, ofc it gives out wrong results if it inputes 0 as id.

m0skVi4a 08-04-2011 11:55

Re: remove_task doesn't remove task
 
I don't get it. Can you make it for me

avril-lavigne 08-04-2011 12:05

Re: remove_task doesn't remove task
 
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")



Hunter-Digital 08-04-2011 15:38

Re: remove_task doesn't remove task
 
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)


avril-lavigne 09-03-2011 15:04

Re: remove_task doesn't remove task
 
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...


All times are GMT -4. The time now is 01:30.

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