Raised This Month: $ Target: $400
 0% 

Need help with a restart plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
faliment
New Member
Join Date: Dec 2009
Old 12-24-2009 , 11:32   Need help with a restart plugin
Reply With Quote #1

I've tried to make my own restartround + message plugin line in adminmod, but I have some problems with it.

First problem:

If I do "amx_restart 3 live hf", the plugins shows message like "ADMIN Adminname: amx_restart 3 3 live hf", but the expected message is like "ADMIN Adminname: amx_restart 3 live hf"

Second problem:

If I do "amx_restart live hf" without a number between command and message, the plugin show message like "ADMIN Adminname: amx_restart 0 life hf". I want to hide this message if there is no number specified.


Here's what i've done so far:

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

#include <amxmodx>
#include <amxmisc>

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


public plugin_init() 
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_concmd("amx_restart","admin_restart", ADMIN_CVAR,"<seconds> [optional message]");
}

public admin_restart(id,level,cid)
{
    if(!cmd_access(id,level,cid,1))
    {
        return PLUGIN_HANDLED
    }
    
    new name[32]
    new arg[32]
    new msg[64]
    
    read_argv(0,name,31)
    read_argv(1,arg,31)
    read_args(msg,63)
    remove_quotes(msg)
        
    if(equali(arg1,"") 
    || equali(arg1," "))
    {    
        console_print(id,"^"sv_restart^" is ^"%d^"",get_cvar_num("sv_restart"))
        return PLUGIN_HANDLED
    }
    
    set_cvar_num("sv_restart",str_to_num(arg))
    get_user_name(id,name,31)
    
    client_print(0,print_chat,"ADMIN %s: amx_restart %d %s",name,str_to_num(arg),msg)
    
    return PLUGIN_HANDLED
}

Last edited by faliment; 12-24-2009 at 11:38.
faliment is offline
Mxnn
Veteran Member
Join Date: Aug 2009
Location: AT MY HOME
Old 12-24-2009 , 12:55   Re: Need help with a restart plugin
Reply With Quote #2

PHP Code:
#include <amxmodx>
#include <amxmisc>

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


public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_concmd("amx_restart","admin_restart"ADMIN_CVAR,"<seconds> [optional message]");
}

public 
admin_restart(id,level,cid)
{
    if(!
cmd_access(id,level,cid,3)) //<-- Here you have to specify the number of arguments that you want to take from the command.
//In this case you want to take the command (0) , the value (1) and optional message (2) = 3 arguments.
    
{
        return 
PLUGIN_HANDLED
    
}
    
    new 
name[32]
    new 
arg[32]
    new 
msg[64]
    
    
read_argv(0,name,31//With this you are read the command, why?
    
read_argv(1,arg,31)
    
read_args(msg,63)// Here you are reading the parameter.. Why? You have read that with "read_argv(1,arg,31). This you can use to hook a say.
    
remove_quotes(msg)// With this you are removing quotes from the parameter..
    //-----------------------------------------------------------
    //Add by me
    
read_argv(2msg63)     
    if(
equali(arg1,""//arg1 ? You must changed it to arg
    
|| equali(arg1," "))
    {    
        
console_print(id,"^"sv_restart^" is ^"%d^"",get_cvar_num("sv_restart")) //get_cvar_num() is for cvars, this is a command. You must replace it by arg (in arg you have read the second argument). And you must replace %d by %s. Or you can do this:
    //console_print(id, "^"sv_restart^" is ^"%d^"", str_to_num(arg))
        
return PLUGIN_HANDLED
    
}
    
    
set_cvar_num("sv_restart",str_to_num(arg)) //Again cvars..
    
get_user_name(id,name,31)
    
    
client_print(0,print_chat,"ADMIN %s: amx_restart %d %s",name,str_to_num(arg),msg// You have to add the server_cmd() line to restart the server..
    
server_cmd("sv_restart %d"str_to_num(arg))
    
    return 
PLUGIN_HANDLED


Last edited by Mxnn; 12-27-2009 at 00:33.
Mxnn is offline
faliment
New Member
Join Date: Dec 2009
Old 12-24-2009 , 17:11   Re: Need help with a restart plugin
Reply With Quote #3

Thank you, now it works.

I found this somewhere, but when i execute any of the commands in that plugin, is says that the command is uknown, but still works.

Code:
public restartround(id,level,cid) 
{
	if (!cmd_access(id,level,cid,1))
		return PLUGIN_HANDLED
	cvar_cmd(id,"sv_restartround")
	return PLUGIN_CONTINUE
}

cvar_cmd(id,cvarname[]) 
{
	
	if (read_argc() > 1) 
	{ 
		new cmd[32], argv[32]
		read_argv(0,cmd,31)
		read_argv(1,argv,31)
		set_cvar_string(cvarname,argv)
		show_cmd(id,cmd,argv)
		return PLUGIN_HANDLED
	}
	new cmd[32], argv[32]
	read_argv(0,cmd,31)
	read_argv(1,argv,31)
	get_cvar_string(cvarname,argv,31)
	console_print(id,"^"%s^" is set to ^"%s^"",cvarname,argv)
	return PLUGIN_CONTINUE
}
show_cmd(id,cmd[],data[]) 
{
	new name[32]
	get_user_name(id,name,31)
	switch(get_cvar_num("amx_show_activity")) 
	{
		case 2:	client_print(0,print_chat,"ADMIN %s: %s %s",name,cmd,data)
		case 1:	client_print(0,print_chat,"ADMIN: %s %s",cmd,data)
	}
}
Here's what i'm saying: it works but still shows that unknown command. what can i do to fix it?

amx_restart 1
"sv_restartround" changed to "1"
Unknown command: amx_restart
The game will restart in 1 SECOND

And which method is more efficient if there is more than one command in the plugin? The first one posted, or this one?

Last edited by faliment; 12-24-2009 at 17:14.
faliment is offline
Mxnn
Veteran Member
Join Date: Aug 2009
Location: AT MY HOME
Old 12-24-2009 , 19:36   Re: Need help with a restart plugin
Reply With Quote #4

Use the first one posted.
Mxnn 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 04:06.


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