ConnorMcLeod
12-05-2010, 07:10
auto_exec_config(const szFileName[], bool:bAutoCreate=true))
Executes config file from a plugin, file has to be in configs folder.
If the file doesn't exist and autocreate set to 1 (default value),
a file is created with all commands listed (commented for obvious reasons) and all cvars.
auto_exec_config(const szName[], bool:bAutoCreate=true)
{
new szFileName[32]
new iLen = copy(szFileName, charsmax(szFileName), szName)
if( iLen <= 4 || !equal(szFileName[iLen-4], ".cfg") )
{
add(szFileName, charsmax(szFileName), ".cfg")
}
new szConfigPath[96]
get_localinfo("amxx_configsdir", szConfigPath, charsmax(szConfigPath))
format(szConfigPath, charsmax(szConfigPath), "%s/%s", szConfigPath, szFileName)
if( file_exists(szConfigPath) )
{
server_cmd("exec %s", szConfigPath)
server_exec()
return 1
}
else if( bAutoCreate )
{
new fp = fopen(szConfigPath, "wt")
if( !fp )
{
return -1
}
new szPluginFileName[96], szPluginName[64], szAuthor[32], szVersion[32], szStatus[2]
new iPlugin = get_plugin(-1,
szPluginFileName, charsmax(szPluginFileName),
szPluginName, charsmax(szPluginName),
szVersion, charsmax(szVersion),
szAuthor, charsmax(szAuthor),
szStatus, charsmax(szStatus) )
server_print("Plugin id is %d", iPlugin)
fprintf(fp, "; ^"%s^" configuration file^n", szPluginName)
fprintf(fp, "; Author : ^"%s^"^n", szAuthor)
fprintf(fp, "; Version : ^"%s^"^n", szVersion)
fprintf(fp, "; File : ^"%s^"^n", szPluginFileName)
new iMax, i, szCommand[64], iCommandAccess, szCmdInfo[128], szFlags[32]
iMax = get_concmdsnum(-1, -1)
fprintf(fp, "^n; Console Commands :^n")
for(i=0; i<iMax; i++)
{
if( get_concmd_plid(i, -1, -1) == iPlugin )
{
get_concmd(i,
szCommand, charsmax(szCommand),
iCommandAccess,
szCmdInfo, charsmax(szCmdInfo),
-1, -1)
get_flags(iCommandAccess, szFlags, charsmax(szFlags))
fprintf(fp, "; %s | Access:^"%s^" | ^"%s^"^n", szCommand, szFlags, szCmdInfo)
}
}
iMax = get_plugins_cvarsnum()
new iTempId, iPcvar, szCvarName[256], szCvarValue[128]
fprintf(fp, "^n; Cvars :^n")
for(new i; i<iMax; i++)
{
get_plugins_cvar(i, szCvarName, charsmax(szCvarName), _, iTempId, iPcvar)
if( iTempId == iPlugin )
{
get_pcvar_string(iPcvar, szCvarValue, charsmax(szCvarValue))
fprintf(fp, "%s ^"%s^"^n", szCvarName, szCvarValue)
}
}
fclose(fp)
}
return 0
}
Plugin usage example :
/* Formatright © 2010, ConnorMcLeod
This plugin is free software;
you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this plugin; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <amxmodx>
#include <autoexecconfig>
#define VERSION "0.0.1"
#define PLUGIN "auto config test"
public plugin_init()
{
register_plugin(PLUGIN, VERSION, "ConnorMcLeod")
register_cvar("osefblabla", "1")
register_cvar("osefblabla1", "2.050")
register_cvar("osefblabla2", "You Failed !!")
register_clcmd("my_clcmd", "my_clcmd", _, "my clcmd comment")
register_concmd("my_concmd", "my_concmd", ADMIN_CFG|ADMIN_KICK, "my cocmd comment")
register_srvcmd("my_srvcmd", "my_srvcmd", ADMIN_CFG, "my servcmd comment")
}
public my_clcmd() {}
public my_concmd() {}
public my_srvcmd() {}
public plugin_cfg()
{
auto_exec_config("test")
}
Auto created configs/test.cfg if file doesn't exists :
; "auto config test" configuration file
; Author : "ConnorMcLeod"
; Version : "0.0.1"
; File : "auto_test.amxx"
; Console Commands :
; my_concmd | Access:"ch" | "my cocmd comment"
; my_srvcmd | Access:"h" | "my servcmd comment"
; Cvars :
osefblabla "0"
osefblabla1 "2.050"
osefblabla2 "You Failed !!"
Executes config file from a plugin, file has to be in configs folder.
If the file doesn't exist and autocreate set to 1 (default value),
a file is created with all commands listed (commented for obvious reasons) and all cvars.
auto_exec_config(const szName[], bool:bAutoCreate=true)
{
new szFileName[32]
new iLen = copy(szFileName, charsmax(szFileName), szName)
if( iLen <= 4 || !equal(szFileName[iLen-4], ".cfg") )
{
add(szFileName, charsmax(szFileName), ".cfg")
}
new szConfigPath[96]
get_localinfo("amxx_configsdir", szConfigPath, charsmax(szConfigPath))
format(szConfigPath, charsmax(szConfigPath), "%s/%s", szConfigPath, szFileName)
if( file_exists(szConfigPath) )
{
server_cmd("exec %s", szConfigPath)
server_exec()
return 1
}
else if( bAutoCreate )
{
new fp = fopen(szConfigPath, "wt")
if( !fp )
{
return -1
}
new szPluginFileName[96], szPluginName[64], szAuthor[32], szVersion[32], szStatus[2]
new iPlugin = get_plugin(-1,
szPluginFileName, charsmax(szPluginFileName),
szPluginName, charsmax(szPluginName),
szVersion, charsmax(szVersion),
szAuthor, charsmax(szAuthor),
szStatus, charsmax(szStatus) )
server_print("Plugin id is %d", iPlugin)
fprintf(fp, "; ^"%s^" configuration file^n", szPluginName)
fprintf(fp, "; Author : ^"%s^"^n", szAuthor)
fprintf(fp, "; Version : ^"%s^"^n", szVersion)
fprintf(fp, "; File : ^"%s^"^n", szPluginFileName)
new iMax, i, szCommand[64], iCommandAccess, szCmdInfo[128], szFlags[32]
iMax = get_concmdsnum(-1, -1)
fprintf(fp, "^n; Console Commands :^n")
for(i=0; i<iMax; i++)
{
if( get_concmd_plid(i, -1, -1) == iPlugin )
{
get_concmd(i,
szCommand, charsmax(szCommand),
iCommandAccess,
szCmdInfo, charsmax(szCmdInfo),
-1, -1)
get_flags(iCommandAccess, szFlags, charsmax(szFlags))
fprintf(fp, "; %s | Access:^"%s^" | ^"%s^"^n", szCommand, szFlags, szCmdInfo)
}
}
iMax = get_plugins_cvarsnum()
new iTempId, iPcvar, szCvarName[256], szCvarValue[128]
fprintf(fp, "^n; Cvars :^n")
for(new i; i<iMax; i++)
{
get_plugins_cvar(i, szCvarName, charsmax(szCvarName), _, iTempId, iPcvar)
if( iTempId == iPlugin )
{
get_pcvar_string(iPcvar, szCvarValue, charsmax(szCvarValue))
fprintf(fp, "%s ^"%s^"^n", szCvarName, szCvarValue)
}
}
fclose(fp)
}
return 0
}
Plugin usage example :
/* Formatright © 2010, ConnorMcLeod
This plugin is free software;
you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this plugin; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <amxmodx>
#include <autoexecconfig>
#define VERSION "0.0.1"
#define PLUGIN "auto config test"
public plugin_init()
{
register_plugin(PLUGIN, VERSION, "ConnorMcLeod")
register_cvar("osefblabla", "1")
register_cvar("osefblabla1", "2.050")
register_cvar("osefblabla2", "You Failed !!")
register_clcmd("my_clcmd", "my_clcmd", _, "my clcmd comment")
register_concmd("my_concmd", "my_concmd", ADMIN_CFG|ADMIN_KICK, "my cocmd comment")
register_srvcmd("my_srvcmd", "my_srvcmd", ADMIN_CFG, "my servcmd comment")
}
public my_clcmd() {}
public my_concmd() {}
public my_srvcmd() {}
public plugin_cfg()
{
auto_exec_config("test")
}
Auto created configs/test.cfg if file doesn't exists :
; "auto config test" configuration file
; Author : "ConnorMcLeod"
; Version : "0.0.1"
; File : "auto_test.amxx"
; Console Commands :
; my_concmd | Access:"ch" | "my cocmd comment"
; my_srvcmd | Access:"h" | "my servcmd comment"
; Cvars :
osefblabla "0"
osefblabla1 "2.050"
osefblabla2 "You Failed !!"