Raised This Month: $ Target: $400
 0% 

Solved Hooking Buy Command


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Depresie
Veteran Member
Join Date: Nov 2013
Old 04-07-2017 , 10:37   Re: Hooking Buy Command
Reply With Quote #1

Well, the problem is that it will open the menu automatically when touching the buy zone...

I tried like this, but there are two problems, the vgui menu appears for 1 second and the buy zone is everywhere..

Also, this command --> "buy" is it even called? and if so when ? is it before client_buy_open ? and how can we hook it ?

PHP Code:
public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
register_message(get_user_msgid("StatusIcon"), "en_msg_buy_zone")
    
register_clcmd("client_buy_open""hookacmd")


}

public 
hookacmd(id)
{
    
client_print(0print_chat"FML FML FML FML ")
}

    
// Block buy zone
public en_msg_buy_zone(msg_idmsg_destmsg_entity)
{
    static 
szIcon[8];
    
get_msg_arg_string(2szIcon7);

    if(
equal(szIcon"buyzone") && get_msg_arg_int(1))
    {
        
set_pdata_int(msg_entity235get_pdata_int(msg_entity235) & ~(1<<0));
        
//client_print(0, print_chat, "blabla 1")
        //return PLUGIN_HANDLED;
    
}
    return 
PLUGIN_CONTINUE;

__________________

Last edited by Depresie; 04-07-2017 at 10:55.
Depresie is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-07-2017 , 13:54   Re: Hooking Buy Command
Reply With Quote #2

Quote:
Well, the problem is that it will open the menu automatically when touching the buy zone...
Easy fix, register a command(or even the original one - "buy") for your custom buy menu and set a bool to true here. In StatusIcon, open the menu only if this bool is true.

The buy command can be hooked with register_clcmd, but IIRC it's not enough to prevent buy. You have to pair that with buy zone removal, but this is not what you want because if you do it like that, you would have to create a custom buy zone entity in the place of original one, which after all is not that hard. Just copy the origin and stuff from the buy zone entity to your custom one.

Anyway, if you only care about VGUIMenu, you could simply hook it(https://wiki.alliedmods.net/index.ph...ct=no#VGUIMenu) with register_message and block the original menu, then do your stuff.

There are many solutions, choose the one that looks better for you and do some tests. I no longer have CS installed so I don't feel like writting the code.
__________________

Last edited by HamletEagle; 04-07-2017 at 13:54.
HamletEagle is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 04-07-2017 , 14:25   Re: Hooking Buy Command
Reply With Quote #3

I tried hooking the buy command with register_clcmd like in the first post... but the client print wasn't displayed...

Also, hooking VGUIMenu isn't just for team menu ?

PHP Code:
register_message(get_user_msgid("VGUIMenu"), "en_msg_team_menu"
__________________

Last edited by Depresie; 04-07-2017 at 14:30.
Depresie is offline
NiHiLaNTh
Way Past Expiration
Join Date: May 2009
Location: Latvia
Old 04-08-2017 , 08:39   Re: Hooking Buy Command
Reply With Quote #4

VGUI menu has a parameter - menuID. Filter out all the uneeded menus.
__________________

NiHiLaNTh is offline
Send a message via Skype™ to NiHiLaNTh
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 18:03.


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