updated to use the multi-lingual system | better code style
This commit is contained in:
@ -45,8 +45,10 @@ new g_menuPosition[33]
|
||||
new g_fileToSave[64]
|
||||
new bool:g_modified
|
||||
|
||||
public plugin_precache(){
|
||||
public plugin_precache() {
|
||||
register_clcmd("amx_statscfgmenu","cmdCfgMenu",ADMIN_CFG,"- displays stats configuration menu")
|
||||
register_dictionary("statscfg.txt")
|
||||
register_dictionary("common.txt")
|
||||
register_concmd("amx_statscfg","cmdCfg",ADMIN_CFG,"- displays help for stats configuration")
|
||||
}
|
||||
|
||||
@ -58,10 +60,10 @@ public plugin_init() {
|
||||
loadSettings(g_fileToSave)
|
||||
}
|
||||
|
||||
public cmdCfg( id,level,cid ){
|
||||
public cmdCfg( id,level,cid ) {
|
||||
if (!cmd_access(id,level,cid,1))
|
||||
return PLUGIN_HANDLED
|
||||
|
||||
|
||||
new cmds[32]
|
||||
read_argv(1,cmds,31)
|
||||
new option = equali(cmds, "on" ) ? 1 : 0
|
||||
@ -69,7 +71,7 @@ public cmdCfg( id,level,cid ){
|
||||
if ( read_argc() > 2 && option ) {
|
||||
new var[32], enabled = 0
|
||||
read_argv( 2 , var , 31 )
|
||||
for( new a = 0; a < g_menuDataNum; ++a ) {
|
||||
for ( new a = 0; a < g_menuDataNum; ++a ) {
|
||||
if ( containi( g_menuDataVar[ a ] , var ) != -1 ) {
|
||||
g_modified = true
|
||||
++enabled
|
||||
@ -84,25 +86,25 @@ public cmdCfg( id,level,cid ){
|
||||
}
|
||||
}
|
||||
if ( enabled )
|
||||
console_print(id,"Total %d", enabled )
|
||||
console_print(id,"%L", id, "TOTAL_NUM", enabled )
|
||||
else
|
||||
console_print(id,"Couldn't find option(s) with such variable (name ^"%s^")", var )
|
||||
console_print(id,"%L",id,"NO_OPTION",var )
|
||||
}
|
||||
else if ( equali(cmds, "save" ) ) {
|
||||
if ( saveSettings( g_fileToSave ) ){
|
||||
g_modified = false
|
||||
console_print(id,"Stats configuration saved successfully")
|
||||
console_print(id,"%L",id,"CONF_SAVED")
|
||||
}
|
||||
else
|
||||
console_print(id,"Failed to save stats configuration!!!")
|
||||
console_print(id,"%L",id,"CONF_FAILED")
|
||||
}
|
||||
else if ( equali(cmds, "load" ) ) {
|
||||
if ( loadSettings( g_fileToSave ) ){
|
||||
g_modified = false
|
||||
console_print(id,"Stats configuration loaded successfully")
|
||||
console_print(id,"%L",id,"CONF_LOADED")
|
||||
}
|
||||
else
|
||||
console_print(id,"Failed to load stats configuration!!!")
|
||||
console_print(id,"%L",id,"CONF_FAIL_LOAD")
|
||||
}
|
||||
else if ( equali(cmds, "list" ) ) {
|
||||
new arg1[8]
|
||||
@ -111,87 +113,94 @@ public cmdCfg( id,level,cid ){
|
||||
if (start >= g_menuDataNum) start = g_menuDataNum - 1
|
||||
new end = start + 10
|
||||
if (end > g_menuDataNum) end = g_menuDataNum
|
||||
console_print(id, "^n----- Stats Configuration: -----")
|
||||
console_print(id, " %-29.28s %-24.23s %-9.8s","name","variable","status")
|
||||
|
||||
new lName[16],lVariable[16],lStatus[16]
|
||||
format(lName,15,"%L",id,"NAME")
|
||||
format(lVariable,15,"%L",id,"VARIABLE")
|
||||
format(lStatus,15,"%L",id,"STATUS")
|
||||
console_print(id, "^n----- %L: -----",id,"STATS_CONF")
|
||||
console_print(id, " %-29.28s %-24.23s %-9.8s",lName,lVariable,lStatus)
|
||||
if ( start != -1 ) {
|
||||
for(new a = start; a < end; ++a){
|
||||
new lOnOff[16]
|
||||
for (new a = start; a < end; ++a) {
|
||||
format(lOnOff,15,"%L",id,get_xvar_num( g_menuDataId[ a ] ) ? "ON" : "OFF")
|
||||
console_print(id, "%3d: %-29.28s %-24.23s %-9.8s",a + 1,
|
||||
g_menuData[a], g_menuDataVar[a], get_xvar_num( g_menuDataId[ a ] ) ? "ON" : "OFF")
|
||||
g_menuData[a], g_menuDataVar[a], lOnOff)
|
||||
}
|
||||
}
|
||||
console_print(id,"----- Entries %i - %i of %i -----",start+1,end,g_menuDataNum)
|
||||
console_print(id,"----- %L -----",id,"ENTRIES_OF",start+1,end,g_menuDataNum)
|
||||
if (end < g_menuDataNum)
|
||||
console_print(id,"----- Use 'amx_statscfg list %i' for more -----",end+1)
|
||||
console_print(id,"----- %L -----",id,"USE_MORE",end+1)
|
||||
else
|
||||
console_print(id,"----- Use 'amx_statscfg list 1' for begin -----")
|
||||
console_print(id,"----- %L -----",id,"USE_BEGIN")
|
||||
}
|
||||
else if ( equali(cmds, "add" ) && read_argc() > 3 ) {
|
||||
if ( g_menuDataNum < MAX_MENU_DATA ) {
|
||||
read_argv(2, g_menuData[g_menuDataNum] , 31 )
|
||||
read_argv(3, g_menuDataVar[g_menuDataNum] , 31 )
|
||||
g_menuDataId[g_menuDataNum] = get_xvar_id( g_menuDataVar[g_menuDataNum] )
|
||||
++g_menuDataNum
|
||||
}
|
||||
else console_print(id, "Can't add stats to the list, limit reached!")
|
||||
if ( g_menuDataNum < MAX_MENU_DATA ) {
|
||||
read_argv(2, g_menuData[g_menuDataNum] , 31 )
|
||||
read_argv(3, g_menuDataVar[g_menuDataNum] , 31 )
|
||||
g_menuDataId[g_menuDataNum] = get_xvar_id( g_menuDataVar[g_menuDataNum] )
|
||||
++g_menuDataNum
|
||||
}
|
||||
else console_print(id, "%L",id,"CANT_ADD")
|
||||
}
|
||||
else {
|
||||
console_print(id,"Usage: amx_statscfg <command> [parameters] ...")
|
||||
console_print(id,"Commands:")
|
||||
console_print(id,"^ton <variable> - enable specified option")
|
||||
console_print(id,"^toff <variable> - disable specified option")
|
||||
console_print(id,"^tsave - save stats configuration")
|
||||
console_print(id,"^tload - load stats configuration")
|
||||
console_print(id,"^tlist [id] - list stats status")
|
||||
console_print(id,"^tadd <name> <variable> - add stats to the list")
|
||||
console_print(id,"%L",id,"COM_USAGE")
|
||||
console_print(id,"%L",id,"COM_COM")
|
||||
console_print(id,"%L",id,"COM_ON")
|
||||
console_print(id,"%L",id,"COM_OFF")
|
||||
console_print(id,"%L",id,"COM_SAVE")
|
||||
console_print(id,"%L",id,"COM_LOAD")
|
||||
console_print(id,"%L",id,"COM_LIST")
|
||||
console_print(id,"%L",id,"COM_ADD")
|
||||
}
|
||||
|
||||
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
public cmdCfgMenu(id,level,cid){
|
||||
public cmdCfgMenu(id,level,cid) {
|
||||
if (cmd_access(id,level,cid,1))
|
||||
displayCfgMenu(id,g_menuPosition[id] = 0)
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
displayCfgMenu(id,pos){
|
||||
displayCfgMenu(id,pos) {
|
||||
if (pos < 0) return
|
||||
new menu_body[512], start = pos * 7
|
||||
if (start >= g_menuDataNum) start = pos = g_menuPosition[id] = 0
|
||||
new len = format(menu_body,511,"\yStats Configuration\R%d/%d^n\w^n",
|
||||
pos + 1,((g_menuDataNum/7)+((g_menuDataNum%7)?1:0)))
|
||||
new len = format(menu_body,511,"\y%L\R%d/%d^n\w^n",
|
||||
id,"STATS_CONF",pos + 1,((g_menuDataNum/7)+((g_menuDataNum%7)?1:0)))
|
||||
new end = start + 7, keys = MENU_KEY_0|MENU_KEY_8, k = 0
|
||||
if (end > g_menuDataNum) end = g_menuDataNum
|
||||
for(new a = start; a < end; ++a){
|
||||
for (new a = start; a < end; ++a) {
|
||||
keys |= (1<<k)
|
||||
len += format(menu_body[len],511-len,"%d. %s\y\R%s^n\w",++k,
|
||||
g_menuData[a], get_xvar_num( g_menuDataId[ a ] ) ? "ON" : "OFF" )
|
||||
len += format(menu_body[len],511-len,"%d. %s\y\R%L^n\w",++k,
|
||||
g_menuData[a], id, get_xvar_num( g_menuDataId[ a ] ) ? "ON" : "OFF" )
|
||||
}
|
||||
if ( g_menuDataNum == 0 )
|
||||
len += format(menu_body[len],511-len,"\dStats plugins are not^ninstalled on this server^n\w")
|
||||
len += format(menu_body[len],511-len,"^n8. Save configuration\y\R%s^n\w",g_modified ? "*" : "")
|
||||
if (end != g_menuDataNum){
|
||||
format(menu_body[len],511-len,"^n9. More...^n0. %s", pos ? "Back" : "Exit")
|
||||
len += format(menu_body[len],511-len,"\d%L\w",id,"NO_STATS")
|
||||
len += format(menu_body[len],511-len,"^n8. %L\y\R%s^n\w",id,"SAVE_CONF",g_modified ? "*" : "")
|
||||
if (end != g_menuDataNum) {
|
||||
format(menu_body[len],511-len,"^n9. %L...^n0. %s", id, "MORE", id, pos ? "BACK" : "EXIT")
|
||||
keys |= MENU_KEY_9
|
||||
}
|
||||
else format(menu_body[len],511-len,"^n0. %s", pos ? "Back" : "Exit")
|
||||
show_menu(id,keys,menu_body)
|
||||
else format(menu_body[len],511-len,"^n0. %L", id, pos ? "BACK" : "EXIT")
|
||||
show_menu(id,keys,menu_body,-1,"Stats Configuration")
|
||||
}
|
||||
|
||||
public actionCfgMenu(id,key){
|
||||
switch(key){
|
||||
case 7:{
|
||||
if (saveSettings(g_fileToSave)){
|
||||
public actionCfgMenu(id,key) {
|
||||
switch(key) {
|
||||
case 7: {
|
||||
if (saveSettings(g_fileToSave)) {
|
||||
g_modified = false
|
||||
client_print(id,print_chat,"* Configuration saved successfully")
|
||||
client_print(id,print_chat,"* %L",id,"CONF_SAVED")
|
||||
}
|
||||
else
|
||||
client_print(id,print_chat,"* Failed to save configuration!!!")
|
||||
client_print(id,print_chat,"* %L",id,"CONF_FAILED")
|
||||
displayCfgMenu(id,g_menuPosition[id])
|
||||
}
|
||||
case 8: displayCfgMenu(id,++g_menuPosition[id])
|
||||
case 9: displayCfgMenu(id,--g_menuPosition[id])
|
||||
default:{
|
||||
case 8: displayCfgMenu(id,++g_menuPosition[id])
|
||||
case 9: displayCfgMenu(id,--g_menuPosition[id])
|
||||
default: {
|
||||
g_modified = true
|
||||
new a = g_menuPosition[id] * 7 + key
|
||||
set_xvar_num( g_menuDataId[ a ] , 1 - get_xvar_num( g_menuDataId[ a ] ) )
|
||||
@ -201,7 +210,7 @@ public actionCfgMenu(id,key){
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
saveSettings(filename[]){
|
||||
saveSettings(filename[]) {
|
||||
if (file_exists(filename))
|
||||
delete_file(filename)
|
||||
if (!write_file(filename,";Generated by Stats Configuration Plugin. Do not modify!^n;Variable Description"))
|
||||
@ -216,7 +225,7 @@ saveSettings(filename[]){
|
||||
return 1
|
||||
}
|
||||
|
||||
loadSettings(filename[]){
|
||||
loadSettings(filename[]) {
|
||||
if (!file_exists(filename))
|
||||
return 0
|
||||
new text[256], name[32]
|
||||
|
Reference in New Issue
Block a user