|
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
|

06-14-2012
, 13:17
Why does the menu chose action by itself
|
#1
|
I'm hopeless. Simply, whenever I spawn, the spawn gets blocked and that's okay. But after some time, the menu automatically choses an option and proceeds to this (yes, the menu gets closed):
Code:
public ChangeHandler(id, menu, item)
{
new data[2], trash
menu_item_getinfo(menu, item, trash, data, 2, _, _, trash)
if( str_to_num(data) == 0 && g_CurrentStep[ id ] == STEP_ALLOWED )
{
g_CurrentStep[id] = FIRSTNAME
client_cmd(id, "messagemode changename")
client_print_color(id, Blue, "[ARP] Vlozte jmeno. Jmeno nesmi mit vice nez 15 znaku a musi se skladat pouze z normalnich pismen.")
client_print_color(id, Blue, "[ARP] Nevhodne jmeno muze vyvrcholit v ban!")
}
}
I don't call the handler anywhere. It just gets done. I have no idea.
I wrote this plugin a year ago or so thus it probably has a few mistakes, but none of these should break the plugin functionality. All it does is when a player connects, it blocks his spawn and shows a menu to change his name. When he's chosen a first name and a surname( optional ), these gets sent to the database and player is allowed to be spawned.
Full code:
PHP Code:
/* Plugin generated by AMXX-Studio */
#include <amxmodx> #include <regex> #include <ApolloRP> #include <ApolloRP_SQL> #include <cstrike> #include <HamSandwich> #include <ChatColor> #include <fakemeta>
#define PLUGIN "ARP - Real Names" #define VERSION "1.0" #define AUTHOR "IdiotStrike"
#define STEP_INVALID -1 #define FIRSTNAME 0 #define LASTNAME 1 #define STEP_ALLOWED 11515
new g_CurrentStep[33] new g_PlayerName[33][32]
new g_Selected[ 33 ]
new Handle:g_SqlTuple, g_SqlCache[512]
new g_StepMsg[2][] = { "Krestni jmeno", "prijmeni" }
public plugin_init() { register_plugin(PLUGIN, VERSION, AUTHOR) register_clcmd("changename", "cmdName") g_SqlTuple = ARP_SqlHandle() RegisterHam(Ham_Spawn, "player", "Spawn", 0) set_msg_block(get_user_msgid("ClCorpse"), BLOCK_SET) }
public client_connect(id) { g_Selected[ id ] = 0 new authid[36] get_user_authid(id, authid, 35) new Data[1] Data[0] = id format(g_SqlCache, 511, "SELECT * FROM arp_names WHERE steamid='%s'", authid) SQL_ThreadQuery(g_SqlTuple, "LoadHandle", g_SqlCache, Data, 1) }
public CheckHandle(FailState, Handle:Query, Error[], Errcode, Data[], DataSize) { if(FailState == TQUERY_CONNECT_FAILED) return set_fail_state("Could not connect to SQL database.") else if(FailState == TQUERY_QUERY_FAILED) return set_fail_state("Internal error: consult developer.") if(Errcode) return log_amx("Error on query: %s",Error) new id = Data[0] if(SQL_NumResults(Query) < 1) { new authid[36] get_user_authid(id, authid, 35) new firstname[16], surname[16] strtok(g_PlayerName[id], firstname, 15, surname, 15, ' ') format(g_SqlCache, 511, "INSERT INTO arp_names VALUES('%s', '%s', '%s') ON DUPLICATE KEY UPDATE firstname='%s', surname='%s'", authid, firstname, surname, firstname, surname) SQL_ThreadQuery(g_SqlTuple, "IgnoreHandle", g_SqlCache) //client_print(id, print_chat, "[ARP] Tvoje jmeno je nyni %s.", g_PlayerName[id]) client_print_color(id, DontChange, "^4[ARP]^1 Tvoje jmeno je nyni ^4%s^1.", g_PlayerName[id]) g_Selected[ id ] = 1 ExecuteHam(Ham_CS_RoundRespawn, id) set_user_info(id, "name", g_PlayerName[id]) g_CurrentStep[id] = STEP_INVALID } else { g_CurrentStep[id] = STEP_ALLOWED //client_print(id, print_chat, "[ARP] Toto jmeno jiz existuje. Prosim, zvol si jine.") arrayset(g_PlayerName[id], '^0', 30) client_print_color(id, Red, "[ARP] Toto jmeno jiz existuje. Prosim, zvol jine jmeno.") ShowChangeMenu(id) } return PLUGIN_HANDLED } public LoadHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) { if(FailState == TQUERY_CONNECT_FAILED) return set_fail_state("Could not connect to SQL database.") else if(FailState == TQUERY_QUERY_FAILED) return set_fail_state("Internal error: consult developer.") if(Errcode) return log_amx("Error on query: %s",Error) new id = Data[0] if(SQL_NumResults(Query) > 0) { new firstname[16], surname[16] SQL_ReadResult(Query, 1, firstname, 15) SQL_ReadResult(Query, 2, surname, 15) format(g_PlayerName[id], 31, "%s%s%s", firstname, surname[0] ? " ": "", surname[0] ? surname : "") set_user_info(id, "name", g_PlayerName[id]) g_Selected[ id ] = 1 g_CurrentStep[id] = STEP_INVALID } else g_CurrentStep[id] = STEP_ALLOWED return PLUGIN_HANDLED }
public IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) { if(FailState == TQUERY_CONNECT_FAILED) return set_fail_state("Could not connect to SQL database.") else if(FailState == TQUERY_QUERY_FAILED) return set_fail_state("Internal error: consult developer.") if(Errcode) return log_amx("Error on query: %s",Error) return PLUGIN_HANDLED }
public Spawn(id) { if(!g_Selected[ id ]) { set_pev(id, pev_effects, EF_NODRAW) set_pev(id, pev_deadflag, DEAD_DISCARDBODY) ShowChangeMenu(id) return HAM_SUPERCEDE } return HAM_IGNORED
}
public ShowChangeMenu(id) { new menu = menu_create("Registrace jmena", "ChangeHandler") new szName[25], szSurname[25] if(g_PlayerName[id][0]) { new Left[16], Right[16] strtok(g_PlayerName[id], Left, 15, Right, 15, ' ') format(szName, 24, "Jmeno: %s", Left) format(szSurname, 24, "Prijmeni: %s", Right) } else { format(szName, 24, "Jmeno: Nezadano") format(szSurname, 24, "Prijmeni: Nezadano") } menu_additem(menu, szName, "1", _, .callback = menu_makecallback("BlockMenuItem")) menu_additem(menu, szSurname, "2", _, .callback = menu_makecallback("BlockMenuItem")) menu_addblank( menu, 0 ) menu_additem(menu, "Zmenit", "0", _, .callback = menu_makecallback("CheckAllowed")) menu_setprop(menu, MPROP_EXIT, MEXIT_NEVER) menu_display(id, menu) }
public BlockMenuItem( id, menu, item ) return ITEM_DISABLED
public CheckAllowed(id, menu, item) { if(g_CurrentStep[id] == STEP_ALLOWED) return ITEM_ENABLED return ITEM_DISABLED }
public ChangeHandler(id, menu, item) { new data[2], trash menu_item_getinfo(menu, item, trash, data, 2, _, _, trash) if( str_to_num(data) == 0 && g_CurrentStep[ id ] == STEP_ALLOWED ) { g_CurrentStep[id] = FIRSTNAME client_cmd(id, "messagemode changename") client_print_color(id, Blue, "[ARP] Vlozte jmeno. Jmeno nesmi mit vice nez 15 znaku a musi se skladat pouze z normalnich pismen.") client_print_color(id, Blue, "[ARP] Nevhodne jmeno muze vyvrcholit v ban!") } }
public cmdName(id) { if(g_CurrentStep[id] == STEP_INVALID) { client_print_color(id, Red, "[ARP] Zmena jmena pro tebe neni v tuto chvili povolena.") return PLUGIN_HANDLED } //ShowChangeMenu(id) new args[30] read_args(args, 29) remove_quotes(args) trim(args) if(g_CurrentStep[id] == LASTNAME && !args[0]) { client_print_color(id, Blue, "[ARP] Rozhodl jsi se nemit zadne prijmeni.") goto NameChange } if(strlen(args) < 3) { client_print_color(id, Red, "[ARP] %s musi obsahovat alespon 3 znaky!", g_StepMsg[g_CurrentStep[id]]) client_cmd(id, "messagemode changename") return PLUGIN_HANDLED } else if (strlen(args) > 15) { client_print_color(id, Red, "[ARP] %s musi mit mene nez 16 znaku!", g_StepMsg[g_CurrentStep[id]]) client_cmd(id, "messagemode changename") return PLUGIN_HANDLED } new pattern[] = "^^[a-zA-Z]+(([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)*$" new num, error[128] new Regex:re = regex_match(args, pattern, num, error, 127) //server_print("Result=%d, num=%d, error=%s", re, num, error) if (re >= REGEX_OK) { new argsb[1] argsb[0] = args[0] strtolower(args) strtoupper(argsb) args[0] = argsb[0] if(g_CurrentStep[id] == LASTNAME) add(g_PlayerName[id], 30, " ") add(g_PlayerName[id], 30, args) } else { client_print_color(id, Red, "[ARP] %s nesmi obsahovat zadne specialni znaky ani cisla!", g_StepMsg[g_CurrentStep[id]]) client_cmd(id, "messagemode changename") return PLUGIN_HANDLED } //client_print(id, print_chat, "[ARP] Tvoje %s je nyni %s.", g_StepMsg[g_CurrentStep[id]]) if(g_CurrentStep[id] == FIRSTNAME) { g_CurrentStep[id] = LASTNAME client_print_color(id, Blue, "[ARP] Prosim, zvol sve prijmeni. Jestli jej nechces, pouze stiskni Enter.") client_cmd(id, "messagemode changename") return PLUGIN_HANDLED } NameChange: new Left[16], Right[16] strtok(g_PlayerName[id], Left, 15, Right, 15, ' ') remove_quotes(Left) remove_quotes(Right) trim(Left) trim(Right) new menu = menu_create("Potvrdit udaje", "Agree") new firstname[26], surname[26] format(firstname, 25, "Jmeno: %s", Left) format(surname, 25, "Prijmeni: %s", Right[0] ? Right : "Nevyplneno") menu_additem(menu, firstname, "1", _, .callback = menu_makecallback( "BlockMenuItem" ) ) menu_additem(menu, surname, "2", _, .callback = menu_makecallback( "BlockMenuItem" ) )
menu_addblank(menu, 0) menu_additem(menu, "Potvrzuji", "3") menu_additem(menu, "Znovu", "4") menu_setprop(menu, MPROP_EXIT, MEXIT_NEVER) menu_display(id, menu) return PLUGIN_HANDLED }
public Agree(id, menu, item) { new trash, data[3] menu_item_getinfo(menu, item, trash, data, 2, _, trash, trash) new Left[16], Right[16] strtok(g_PlayerName[id], Left, 15, Right, 15, ' ') remove_quotes(Left) remove_quotes(Right) trim(Left) trim(Right) if(str_to_num(data) == 3) { new Data[1] Data[0] = id format(g_SqlCache, 511, "SELECT * FROM arp_names WHERE firstname='%s' AND surname='%s'", Left, Right) SQL_ThreadQuery(g_SqlTuple, "CheckHandle", g_SqlCache, Data, 1) client_print_color(id, DontChange, "^4[ARP] Kontroluji dostupnost jmena...") } else { arrayset(g_PlayerName[id], '^0', 30) g_CurrentStep[id] = STEP_ALLOWED ShowChangeMenu(id) } } public client_disconnect(id) { g_CurrentStep[id] = STEP_INVALID arrayset(g_PlayerName[id], '^0', 30) }
public client_infochanged(id) { if(g_PlayerName[id][0]) set_user_info(id, "name", g_PlayerName[id]) }
Last edited by Backstabnoob; 06-14-2012 at 13:32.
|
|