AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Pausing/unpausing a plugin (https://forums.alliedmods.net/showthread.php?t=242692)

EpicKiller 06-23-2014 06:32

Pausing/unpausing a plugin
 
Hey there. I am trying to pause a plugin. And by trying, I mean having no idea how to do that. I'm guessing the plugin_pause and plugin_unpause functions must be involved. But still, I do not know how to do it. Please, could you give me a hand? I'm a begginer in scripting, so I don't feel really handy with some things. I usually search tutorials or explanations on what I can't manage to figure out myself, but I was not able to find any documentation about this, except, ofcourse, the amxmodx functions list, which did not help me. So... what I basically want to learn is how can I pause a plugin for "x" seconds/minutes, and then unpause it.

Thank you for taking the time to read my issue and thank you for the future helping.

Best regards to you all, AMs.

Nextra 06-23-2014 09:25

Re: Pausing/unpausing a plugin
 
What exactly are you trying to achieve?

... 06-23-2014 13:11

Re: Pausing/unpausing a plugin
 
You need to use natives :- pause and unpause
Pause :-
PHP Code:

pause flag[], const param1[]= ) 

Usage :

Quote:

param2 name of plugin (all depends on flags).
Flags:
"a" - pause whole plugin.
"b" - pause function.
"c" - look outside the plugin (by given plugin name).
"d" - set "stopped" status when pausing whole plugin.
"e" - set "locked" status when pausing whole plugin.
In this status plugin is unpauseable.
Example: pause("ac","myplugin.amxx")
pause("bc","myfunc","myplugin.amxx")


Unpause :-
PHP Code:

unpause flag[], const param1[]= ) 

Quote:

Flags:
"a" - unpause whole plugin.
"b" - unpause function.
"c" - look outside the plugin (by given plugin name).
Example
PHP Code:


#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "..."

#define TASK_TIME 444645

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("/pause","pause_plugin",ADMIN_BAN,"<pluginname> <float:seconds>")
}


public 
pause_plugin(id,level ,cid)
{
    if(!
cmd_access(id,level,cid,2))
        return 
PLUGIN_HANDLED
    
new pluginname[64] , seconds[10]
    
read_argv(1,pluginname,charsmax(pluginname)) 
    
read_argv(2,seconds,charsmax(seconds))
    
trim(pluginname); trim(seconds); remove_quotes(pluginname); remove_quotes(seconds)
    new 
num str_to_float(seconds)

    if(
seconds[0] == EOS || num <= 0)
    {
        
        
client_cmd(id,"echo [ Plugin Pause ] : Invalid seconds , it should be number !")
        return 
PLUGIN_HANDLED
        
    
}
    
    if(
task_exists(TASK_TIME))
    {
        
        
client_cmd(id,"echo [ Plugin Pause ] : Another plugin is already paused.")
        return 
PLUGIN_HANDLED
        
    
}
    
    if(
is_plugin_loaded(pluginname,true) != -1)
    {
        
        
pause("ac",pluginname)
        
set_task(num,"unpause_plugin",TASK_TIME,pluginname,strlen(pluginname))
        
client_print(0,3,"[ Plugin Pause ] : Plugin ^"%s^" is now paused and will be unpaused after %f seconds.",pluginname,num)
        
client_cmd(id,"echo [ Plugin Pause ] : Plugin ^"%s^" successfully paused for %f seconds",pluginname,num)
        
    }
    else
        
client_cmd(id,"echo [ Plugin Pause ] : Plugin ^"%s^" not found",pluginname)
}

public 
unpause_plugin(plugin[])
{
    
client_print(0,3,"[ Plugin Pause ] : Plugin ^"%s^" is now unpaused.",plugin)
    
unpause("ac",plugin)



EpicKiller 06-23-2014 17:00

Re: Pausing/unpausing a plugin
 
Quote:

Originally Posted by Nextra (Post 2156079)
What exactly are you trying to achieve?

By this thread, knowledge. With the achieved knowledge, I intend to achieve succes in writing my plugin.

Quote:

Originally Posted by ... (Post 2156177)
You need to use natives :- pause and unpause
Pause :-
PHP Code:

pause flag[], const param1[]= ) 

Usage :



Unpause :-
PHP Code:

unpause flag[], const param1[]= ) 


Example
PHP Code:


#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "..."

#define TASK_TIME 444645

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("/pause","pause_plugin",ADMIN_BAN,"<pluginname> <float:seconds>")
}


public 
pause_plugin(id,level ,cid)
{
    if(!
cmd_access(id,level,cid,2))
        return 
PLUGIN_HANDLED
    
new pluginname[64] , seconds[10]
    
read_argv(1,pluginname,charsmax(pluginname)) 
    
read_argv(2,seconds,charsmax(seconds))
    
trim(pluginname); trim(seconds); remove_quotes(pluginname); remove_quotes(seconds)
    new 
num str_to_float(seconds)

    if(
seconds[0] == EOS || num <= 0)
    {
        
        
client_cmd(id,"echo [ Plugin Pause ] : Invalid seconds , it should be number !")
        return 
PLUGIN_HANDLED
        
    
}
    
    if(
task_exists(TASK_TIME))
    {
        
        
client_cmd(id,"echo [ Plugin Pause ] : Another plugin is already paused.")
        return 
PLUGIN_HANDLED
        
    
}
    
    if(
is_plugin_loaded(pluginname,true) != -1)
    {
        
        
pause("ac",pluginname)
        
set_task(num,"unpause_plugin",TASK_TIME,pluginname,strlen(pluginname))
        
client_print(0,3,"[ Plugin Pause ] : Plugin ^"%s^" is now paused and will be unpaused after %f seconds.",pluginname,num)
        
client_cmd(id,"echo [ Plugin Pause ] : Plugin ^"%s^" successfully paused for %f seconds",pluginname,num)
        
    }
    else
        
client_cmd(id,"echo [ Plugin Pause ] : Plugin ^"%s^" not found",pluginname)
}

public 
unpause_plugin(plugin[])
{
    
client_print(0,3,"[ Plugin Pause ] : Plugin ^"%s^" is now unpaused.",plugin)
    
unpause("ac",plugin)



Thank you so much! The details on theese two natives helped me a lot. Also, by writing this plugin, you helped me understand it's use even better! Thanks again! Owe you one!


All times are GMT -4. The time now is 21:06.

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