Raised This Month: $ Target: $400
 0% 

Why does the menu chose action by itself


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 06-14-2012 , 13:17   Why does the menu chose action by itself
Reply With Quote #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_Selected33 ]

new 
Handle:g_SqlTupleg_SqlCache[512]

new 
g_StepMsg[2][] =
{
    
"Krestni jmeno",
    
"prijmeni"
}

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)    
    
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_Selectedid ] = 0
    
    
new authid[36]
    
get_user_authid(idauthid35)
    
    new 
Data[1]
    
Data[0] = id
    
    format
(g_SqlCache511"SELECT * FROM arp_names WHERE steamid='%s'"authid)
    
SQL_ThreadQuery(g_SqlTuple"LoadHandle"g_SqlCacheData1)
}

public 
CheckHandle(FailStateHandle:QueryError[], ErrcodeData[], 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(idauthid35)
        
        new 
firstname[16], surname[16]
        
        
strtok(g_PlayerName[id], firstname15surname15' ')
        
        
format(g_SqlCache511"INSERT INTO arp_names VALUES('%s', '%s', '%s') ON DUPLICATE KEY UPDATE firstname='%s', surname='%s'"authidfirstnamesurnamefirstnamesurname)
        
SQL_ThreadQuery(g_SqlTuple"IgnoreHandle"g_SqlCache)
        
        
//client_print(id, print_chat, "[ARP] Tvoje jmeno je nyni %s.", g_PlayerName[id])
        
        
client_print_color(idDontChange"^4[ARP]^1 Tvoje jmeno je nyni ^4%s^1."g_PlayerName[id])
        
        
g_Selectedid ] = 1
        
        ExecuteHam
(Ham_CS_RoundRespawnid)
        
        
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(idRed"[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(Query1firstname15)
        
SQL_ReadResult(Query2surname15)
        
        
format(g_PlayerName[id], 31"%s%s%s"firstnamesurname[0] ? " """surname[0] ? surname "")
        
        
set_user_info(id"name"g_PlayerName[id])
        
        
g_Selectedid ] = 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_Selectedid ])
    {
        
        
set_pev(idpev_effectsEF_NODRAW)
        
set_pev(idpev_deadflagDEAD_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], Left15Right15' ')
    
        
format(szName24"Jmeno: %s"Left)
        
format(szSurname24"Prijmeni: %s"Right)
    }
    
    else
    {
        
format(szName24"Jmeno: Nezadano")
        
format(szSurname24"Prijmeni: Nezadano")
    }
    
    
menu_additem(menuszName"1"_, .callback menu_makecallback("BlockMenuItem"))
    
menu_additem(menuszSurname"2"_, .callback menu_makecallback("BlockMenuItem"))
    
menu_addblankmenu)
    
menu_additem(menu"Zmenit""0"_, .callback menu_makecallback("CheckAllowed"))
    
    
menu_setprop(menuMPROP_EXITMEXIT_NEVER)
    
menu_display(idmenu)
}

public 
BlockMenuItemidmenuitem )
    return 
ITEM_DISABLED

public CheckAllowed(idmenuitem)
{
    if(
g_CurrentStep[id] == STEP_ALLOWED)
        return 
ITEM_ENABLED
    
    
return ITEM_DISABLED
}


public 
ChangeHandler(idmenuitem)
{
    new 
data[2], trash
    menu_item_getinfo
(menuitemtrashdata2__trash)
    
    if( 
str_to_num(data) == && g_CurrentStepid ] == STEP_ALLOWED )
    {
        
g_CurrentStep[id] = FIRSTNAME
        client_cmd
(id"messagemode changename")
        
        
client_print_color(idBlue"[ARP] Vlozte jmeno. Jmeno nesmi mit vice nez 15 znaku a musi se skladat pouze z normalnich pismen.")
        
client_print_color(idBlue"[ARP] Nevhodne jmeno muze vyvrcholit v ban!")
        
    }
    
}
    

public 
cmdName(id)
{
    if(
g_CurrentStep[id] == STEP_INVALID)
    {
        
client_print_color(idRed"[ARP] Zmena jmena pro tebe neni v tuto chvili povolena.")
        return 
PLUGIN_HANDLED
    
}
    
    
//ShowChangeMenu(id)
    
    
new args[30]
    
read_args(args29)
    
    
remove_quotes(args)
    
trim(args)
    
    if(
g_CurrentStep[id] == LASTNAME && !args[0])
    {
        
client_print_color(idBlue"[ARP] Rozhodl jsi se nemit zadne prijmeni.")
        
        goto 
NameChange
    
}
    
    if(
strlen(args) < 3)
    {
        
client_print_color(idRed"[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(idRed"[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 numerror[128]
    new 
Regex:re regex_match(argspatternnumerror127)
 
    
//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], 30args)
    }
    else
    {
        
client_print_color(idRed"[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
(idBlue"[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], Left15Right15' ')
    
    
remove_quotes(Left)
    
remove_quotes(Right)
    
trim(Left)
    
trim(Right)
    
    new 
menu menu_create("Potvrdit udaje""Agree")
    
    new 
firstname[26], surname[26]
    
format(firstname25"Jmeno: %s"Left)
    
format(surname25"Prijmeni: %s"Right[0] ? Right "Nevyplneno")
    
    
menu_additem(menufirstname"1"_, .callback menu_makecallback"BlockMenuItem" ) )
    
menu_additem(menusurname"2"_, .callback menu_makecallback"BlockMenuItem" ) )

    
menu_addblank(menu0)
    
    
menu_additem(menu"Potvrzuji""3")
    
menu_additem(menu"Znovu""4")
    
    
menu_setprop(menuMPROP_EXITMEXIT_NEVER)
    
menu_display(idmenu)
    
    return 
PLUGIN_HANDLED
}

public 
Agree(idmenuitem)
{
    new 
trashdata[3]
    
menu_item_getinfo(menuitemtrashdata2_trashtrash)
    
    new 
Left[16], Right[16]
    
strtok(g_PlayerName[id], Left15Right15' ')
    
    
remove_quotes(Left)
    
remove_quotes(Right)
    
trim(Left)
    
trim(Right)
    
    if(
str_to_num(data) == 3)
    {
        
        new 
Data[1]
        
Data[0] = id
        
        format
(g_SqlCache511"SELECT * FROM arp_names WHERE firstname='%s' AND surname='%s'"LeftRight)
        
SQL_ThreadQuery(g_SqlTuple"CheckHandle"g_SqlCacheData1)
    
        
client_print_color(idDontChange,  "^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.
Backstabnoob is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-14-2012 , 13:23   Re: Why does the menu chose action by itself
Reply With Quote #2

Don't know about the code, but you can highlight lines in [pawn] and [small] tags by prefixing the whole line with @@.

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!")             }     }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 06-14-2012 , 13:25   Re: Why does the menu chose action by itself
Reply With Quote #3

I did that and it did nothing but show the @'s there :/
Backstabnoob is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-14-2012 , 13:31   Re: Why does the menu chose action by itself
Reply With Quote #4

Did you do it like this:
Code:
@@		client_cmd(id, "messagemode changename")
or like this:
Code:
		@@client_cmd(id, "messagemode changename")
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 06-14-2012 , 13:32   Re: Why does the menu chose action by itself
Reply With Quote #5

Thanks
Backstabnoob is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 06-14-2012 , 16:03   Re: Why does the menu chose action by itself
Reply With Quote #6

I would guess that the menu is being closed (possibly by another plugin). You should check if the item == MENU_EXIT, but it should be giving you an error at menu_item_getinfo.

Try printing out which item is selected to verify that MENU_EXIT is being called. Otherwise, it would seem that the menu is working fine.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Reply


Thread Tools
Display Modes

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 06:17.


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