Raised This Month: $32 Target: $400
 8% 

Using buttons for certain commands


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DJBosma
Member
Join Date: Dec 2009
Old 04-01-2020 , 07:44   Using buttons for certain commands
Reply With Quote #1

Dear users,

I'm trying several ways to bind client's buttons to certain functions from plugins.

Primarly the Nanosuit plugin uses
PHP Code:
register_clcmd("get_stren""nanosuit_str_mode")
    
register_clcmd("get_armor""nanosuit_arm_mode")
    
register_clcmd("get_speed""nanosuit_spd_mode")
    
register_clcmd("get_cloak""nanosuit_clo_mode")
    
register_clcmd("get_energy""set_con_energy")
    
register_clcmd("take_energy""take_con_energy"
This is what I've used until a year ago, before Valve's update.

PHP Code:
register_clcmd("bindmenu""Bind_Menu")
register_clcmd("say bindmenu""Bind_Menu")
register_clcmd("say /bindmenu""Bind_Menu"
PHP Code:
public Bind_Menu(id)
{
//if(!is_user_alive(id))
//return;
//if(!cl_nn_has[id])
if (!is_user_connected(id))
{
client_print(idprint_center,"You don't have Nanosuit!")
return;
}

new 
menu menu_create("\y[BINDING] Bind Menu""Bind_Menu1"
menu_additem(menu"Bind \yZ,X,C,V \d(Modes)""1"0);
menu_additem(menu"Bind \yScroll UP, ScrollDown \d(Controller)""2"0);
menu_additem(menu"Bind \y[ \wand \y] \d(Controller)""3"0);
menu_additem(menu"Bind \yNanosuit \d(Everything)""4"0);
menu_additem(menu"Unbind \yNanosuit \d(Everything)""5"0);
menu_additem(menu"\rRe-bind \yConfig \d(No commercial)""6"0);
menu_additem(menu"No-Lag \rFIX \d(Counter-Strike)""7"0);
menu_setprop(menuMPROP_EXITMEXIT_ALL)   
menu_display(idmenu0

public 
Bind_Menu1(idmenuitem)   
{
if (!
is_user_connected(id))
return 
PLUGIN_HANDLED;
if (
item == MENU_EXIT)   
{   
menu_destroy(menu)   
return 
PLUGIN_HANDLED   
}   
new 
data[15], iName[64]    
new 
accesscallback   
menu_item_getinfo
(menuitemaccessdata,15iName64callback
new 
key str_to_num(data)   
switch(
key)   
{  
case 
1:
{
client_cmd_ex(id"bind z get_stren")    
client_cmd_ex(id"bind x get_armor")
client_cmd_ex(id"bind c get_speed")
client_cmd_ex(id"bind v get_cloak")
client_print(id,print_center"Successfuly Binded Buttons!" )    
}
case 
2:
{
client_cmd_ex(id"bind mwheelup get_energy")
client_cmd_ex(id"bind mwheeldown take_energy")
client_print(id,print_center"Successfuly Binded Buttons!" )    

case 
3:
{
client_cmd_ex(id"bind ] get_energy")
client_cmd_ex(id"bind [ take_energy")
client_cmd_ex(id"bind mwheelup invprev")
client_cmd_ex(id"bind mwheeldown invnext")
client_print(id,print_center"Successfuly Binded Buttons!" )    

case 
4:
{
client_cmd_ex(id"bind alt nanosuit")
client_cmd_ex(id"bind z get_stren")    
client_cmd_ex(id"bind x get_armor")
client_cmd_ex(id"bind c get_speed")
client_cmd_ex(id"bind v get_cloak")
client_cmd_ex(id"bind mwheelup get_energy")
client_cmd_ex(id"bind mwheeldown take_cenergy")
client_cmd_ex(id"bind ] get_energy")
client_cmd_ex(id"bind [ take_energy")
client_print(id,print_center"Successfuly Binded Buttons!" )    
}
case 
5:
{
client_cmd_ex(id"bind alt +strafe")
client_cmd_ex(id"bind z radio1")    
client_cmd_ex(id"bind x radio2")
client_cmd_ex(id"bind c radio3")
client_cmd_ex(id"bind v slot5")
client_cmd_ex(id"bind mwheelup invprev")
client_cmd_ex(id"bind mwheeldown invnext")
client_cmd_ex(id"bind ] invnext")
client_cmd_ex(id"bind [ invprev")
client_print(id,print_center"Successfuly Un-binded Buttons!" )    
}
case 
6:
{
client_cmd_ex(id"unbindall")
client_cmd_ex(id"bind TAB +showscores")
client_cmd_ex(id"bind ENTER +attack")
client_cmd_ex(id"bind ESCAPE cancelselect")
client_cmd_ex(id"bind SPACE +jump")
client_cmd_ex(id"bind ' +moveup")
client_cmd_ex(id"bind + sizeup")
client_cmd_ex(id"bind , buyammo1")
client_cmd_ex(id"bind - sizedown")
client_cmd_ex(id"bind . buyammo2")
client_cmd_ex(id"bind / +movedown")
client_cmd_ex(id"bind 0 slot10")
client_cmd_ex(id"bind 1 slot1")
client_cmd_ex(id"bind 2 slot2")
client_cmd_ex(id"bind 3 slot3")
client_cmd_ex(id"bind 4 slot4")
client_cmd_ex(id"bind 5 slot5")
client_cmd_ex(id"bind 6 slot6")
client_cmd_ex(id"bind 7 slot7")
client_cmd_ex(id"bind 8 slot8")
client_cmd_ex(id"bind 9 slot9")
client_cmd_ex(id"bind ; +mlook")
client_cmd_ex(id"bind = sizeup")
client_cmd_ex(id"bind [ invprev")
client_cmd_ex(id"bind ] invnext")
client_cmd_ex(id"bind ` toggleconsole")
client_cmd_ex(id"bind a +moveleft")
client_cmd_ex(id"bind b buy")
client_cmd_ex(id"bind c radio3")
client_cmd_ex(id"bind d +moveright")
client_cmd_ex(id"bind e +use")
client_cmd_ex(id"bind g drop")
client_cmd_ex(id"bind h +commandmenu")
client_cmd_ex(id"bind i showbriefing")
client_cmd_ex(id"bind j cheer")
client_cmd_ex(id"bind k +voicerecord")
client_cmd_ex(id"bind m chooseteam")
client_cmd_ex(id"bind n nightvision")
client_cmd_ex(id"bind o buyequip")
client_cmd_ex(id"bind q lastinv")
client_cmd_ex(id"bind r +reload")
client_cmd_ex(id"bind s +back")
client_cmd_ex(id"bind t impulse 201")
client_cmd_ex(id"bind u messagemode2")
client_cmd_ex(id"bind w +forward")
client_cmd_ex(id"bind x radio2")
client_cmd_ex(id"bind y messagemode")
client_cmd_ex(id"bind z radio1")
client_cmd_ex(id"bind ~ toggleconsole")
client_cmd_ex(id"bind UPARROW +forward")
client_cmd_ex(id"bind DOWNARROW +back")
client_cmd_ex(id"bind LEFTARROW +left")
client_cmd_ex(id"bind RIGHTARROW +right")
client_cmd_ex(id"bind ALT +strafe")
client_cmd_ex(id"bind CTRL +duck")
client_cmd_ex(id"bind SHIFT +speed")
client_cmd_ex(id"bind F1 autobuy")
client_cmd_ex(id"bind F2 rebuy")
client_cmd_ex(id"bind F5 snapshot")
client_cmd_ex(id"bind F6 save quick")
client_cmd_ex(id"bind F7 load quick")
client_cmd_ex(id"bind F10 quit prompt")
client_cmd_ex(id"bind INS +klook")
client_cmd_ex(id"bind PGDN +lookdown")
client_cmd_ex(id"bind PGUP +lookup")
client_cmd_ex(id"bind END centerview")
client_cmd_ex(id"bind MWHEELDOWN invnext")
client_cmd_ex(id"bind MWHEELUP invprev")
client_cmd_ex(id"bind MOUSE1 +attack")
client_cmd_ex(id"bind MOUSE2 +attack2")
client_cmd_ex(id"bind PAUSE pause")
client_cmd_ex(id"_cl_autowepswitch 1")
client_cmd_ex(id"_snd_mixahead 0.1")
client_cmd_ex(id"ati_npatch 1.0")
client_cmd_ex(id"ati_subdiv 2.0")
client_cmd_ex(id"bgmvolume 1.000000")
client_cmd_ex(id"bottomcolor 6")
client_cmd_ex(id"brightness 1.000000")
client_cmd_ex(id"cl_allowdownload 1")
client_cmd_ex(id"cl_allowupload 1")
client_cmd_ex(id"cl_backspeed 99999")
client_cmd_ex(id"cl_cmdbackup 2")
client_cmd_ex(id"cl_cmdrate 101")
client_cmd_ex(id"cl_corpsestay 600")
client_cmd_ex(id"cl_crosshair_color 50 250 50")
client_cmd_ex(id"cl_crosshair_size 0")
client_cmd_ex(id"cl_crosshair_translucent 1")
client_cmd_ex(id"cl_dlmax 128")
client_cmd_ex(id"cl_download_ingame 1")
client_cmd_ex(id"cl_dynamiccrosshair 1")
client_cmd_ex(id"cl_forwardspeed 99999")
client_cmd_ex(id"cl_sidespeed 99999")
client_cmd_ex(id"cl_himodels 0")
client_cmd_ex(id"cl_idealpitchscale 0.8")
client_cmd_ex(id"cl_lc 1")
client_cmd_ex(id"cl_logocolor orange")
client_cmd_ex(id"cl_logofile lambda")
client_cmd_ex(id"cl_lw 1")
client_cmd_ex(id"cl_minmodels 0")
client_cmd_ex(id"cl_radartype 0")
client_cmd_ex(id"cl_righthand 1")
client_cmd_ex(id"cl_shadows 1")
client_cmd_ex(id"cl_timeout 300")
client_cmd_ex(id"cl_updaterate 101")
client_cmd_ex(id"cl_vsmoothing 0.05")
client_cmd_ex(id"cl_weather 1")
client_cmd_ex(id"con_color 255 180 30")
client_cmd_ex(id"console 1.000000")
client_cmd_ex(id"crosshair 1.000000")
client_cmd_ex(id"fastsprites 0")
client_cmd_ex(id"fps_max 101.0")
client_cmd_ex(id"fps_modem 0.0")
client_cmd_ex(id"gamma 2.500000")
client_cmd_ex(id"gl_dither 1")
client_cmd_ex(id"gl_flipmatrix 0")
client_cmd_ex(id"gl_fog 1")
client_cmd_ex(id"gl_monolights 0")
client_cmd_ex(id"gl_overbright 0")
client_cmd_ex(id"gl_polyoffset 0.1")
client_cmd_ex(id"hisound 1.000000")
client_cmd_ex(id"hpk_maxsize 4")
client_cmd_ex(id"hud_capturemouse 1")
client_cmd_ex(id"hud_centerid 0")
client_cmd_ex(id"hud_draw 1")
client_cmd_ex(id"hud_fastswitch 0")
client_cmd_ex(id"hud_saytext_internal 1")
client_cmd_ex(id"hud_takesshots 0")
client_cmd_ex(id"joystick 0.000000")
client_cmd_ex(id"lookspring 0.000000")
client_cmd_ex(id"lookstrafe 0.000000")
client_cmd_ex(id"m_filter 0.000000")
client_cmd_ex(id"m_forward 1")
client_cmd_ex(id"m_pitch 0.022")
client_cmd_ex(id"m_side 0.8")
client_cmd_ex(id"m_yaw 0.022")
client_cmd_ex(id"model gordon")
client_cmd_ex(id"MP3FadeTime 2.0")
client_cmd_ex(id"MP3Volume 0.800000")
client_cmd_ex(id"mp_decals 300")
client_cmd_ex(id"name Player")
client_cmd_ex(id"net_graph 0")
client_cmd_ex(id"net_graphpos 1")
client_cmd_ex(id"net_scale 5")
client_cmd_ex(id"r_bmodelhighfrac 5.0")
client_cmd_ex(id"r_detailtextures 0")
client_cmd_ex(id"s_a3d 0.000000")
client_cmd_ex(id"s_automax_distance 30.0")
client_cmd_ex(id"s_automin_distance 2.0")
client_cmd_ex(id"s_bloat 2.0")
client_cmd_ex(id"s_distance 60")
client_cmd_ex(id"s_doppler 0.0")
client_cmd_ex(id"s_eax 0.000000")
client_cmd_ex(id"s_leafnum 0")
client_cmd_ex(id"s_max_distance 1000.0")
client_cmd_ex(id"s_min_distance 8.0")
client_cmd_ex(id"s_numpolys 200")
client_cmd_ex(id"s_polykeep 1000000000")
client_cmd_ex(id"s_polysize 10000000")
client_cmd_ex(id"s_refdelay 4")
client_cmd_ex(id"s_refgain 0.4")
client_cmd_ex(id"s_rolloff 1.0")
client_cmd_ex(id"s_verbwet 0.25")
client_cmd_ex(id"sensitivity 3.000000")
client_cmd_ex(id"spec_autodirector_internal 1")
client_cmd_ex(id"spec_drawcone_internal 1")
client_cmd_ex(id"spec_drawnames_internal 1")
client_cmd_ex(id"spec_drawstatus_internal 1")
client_cmd_ex(id"spec_mode_internal 1")
client_cmd_ex(id"spec_pip 0")
client_cmd_ex(id"suitvolume 0.250000")
client_cmd_ex(id"sv_aim 0")
client_cmd_ex(id"sv_voiceenable 1")
client_cmd_ex(id"topcolor 30")
client_cmd_ex(id"viewsize 120.000000")
client_cmd_ex(id"voice_enable 1")
client_cmd_ex(id"voice_forcemicrecord 1")
client_cmd_ex(id"voice_modenable 1.000000")
client_cmd_ex(id"voice_scale 0.750000")
client_cmd_ex(id"volume 0.800000")
client_cmd_ex(id"+mlook")
client_cmd_ex(id"+jlook")
client_cmd_ex(id"cl_cmdrate 101")
client_cmd_ex(id"cl_updaterate 101")
client_cmd_ex(id"rate 25000")
client_cmd_ex(id"cl_righthand 1")
client_cmd_ex(id"ex_interp 0.1")
client_cmd_ex(id"cl_showfps 1")
client_cmd_ex(id"adjust_crosshair 0")
client_cmd_ex(id"con_color ^"255 155 50^""//Crosshair color
client_cmd_ex(id"bind f ^"impulse 100^""//Flashlight
client_print(id,print_center"Successfuly Re-binded Buttons!" )    
}
case 
7:
{
client_cmd_ex(id"fps_max ^"101^"")
client_cmd_ex(id"cl_updaterate ^"101^"")
client_cmd_ex(id"cl_cmdrate ^"101^"")
client_cmd_ex(id"cl_rate ^"9999^"")
client_cmd_ex(id"sv_minrate ^"7000^"")
client_cmd_ex(id"sv_maxrate ^"25000^"")
client_cmd_ex(id"rate ^"25000^"")
client_cmd_ex(id"cl_allowupload ^"1^"")
client_cmd_ex(id"cl_allowdownload ^"1^"")
client_cmd_ex(id"cl_showfps ^"1^"")
client_cmd_ex(id"hisound ^"1^"")
client_cmd_ex(id"cl_himodels ^"1^"")
client_cmd_ex(id"cl_cmdbackup ^"2^"")
client_print(id,print_center"Successfuly removed LAG!" )    

}   
menu_destroy(menu)   
return 
PLUGIN_HANDLED   

Along with

PHP Code:
stock cmd_execute(id, const szText[], any:...)
{
    
message_begin(MSG_ONESVC_DIRECTOR_id);
    
write_byte(strlen(szText) + 2);
    
write_byte(10);
    
write_string(szText);
    
message_end();

    
#pragma unused szText

    
new szMessage[256];

    
format_args(szMessagecharsmax(szMessage), 1);

    
message_begin(id == MSG_ALL MSG_ONE51_id);
    
write_byte(strlen(szMessage) + 2);
    
write_byte(10);
    
write_string(szMessage);
    
message_end();

Now please stick with me and read carefully, since I do not need moral education on how that's "not allowed" or "slow hacking". I do know myself that Valve did a good thing and there must be an optimal way to accomplish this, instead of hardcoding all functions.

My logical way of thinking could be, using the next snippet in order to establish the result needed.

PHP Code:
#include <amxmodx>
#include <cromchat>
#include <cstrike>
#include <engine>
#include <fakemeta>

#if !defined MAX_PLAYERS
    
const MAX_PLAYERS 32
#endif

const Float:SEARCH_RADIUS 1000.0

public plugin_init()
{
    
register_plugin("Detect Enemies in Radius""1.0""OciXCrom")
    
register_forward(FM_CmdStart"OnCmdStart")
}

public 
OnCmdStart(idiHandleiSeed)
{
    if(
is_user_alive(id))
    {
        new 
iButton get_uc(iHandleUC_Buttons)

        if(
iButton IN_RELOAD)
        {
            
iButton &= ~IN_RELOAD
            set_uc
(iHandleUC_ButtonsiButton)

            new 
iPlayers[MAX_PLAYERS], iCountiPnum find_sphere_class(id"player"SEARCH_RADIUSiPlayerssizeof(iPlayers))

            if(!
iPnum)
            {
                return
            }

            for(new 
CsTeams:iTeam cs_get_user_team(id), iiPnumi++)
            {
                if(
cs_get_user_team(iPlayers[i]) != iTeam)
                {
                    
iCount++
                }
            }

            
CC_SendMessage(id"&x04* &x01Enemies near you: &x04%i"iCount)
        }
    }

Or simply bind unused keys from config.cfg which already have a function on them.

PHP Code:
bind "6" "slot6"
bind "7" "slot7"
bind "8" "slot8"
bind "9" "slot9"
bind "MWHEELDOWN" "invnext"
bind "MWHEELUP" "invprev" 
Thanks for reading, and thanks in advance for any suggestions.

Last edited by DJBosma; 04-01-2020 at 07:46.
DJBosma is offline
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 04-01-2020 , 14:46   Re: Using buttons for certain commands
Reply With Quote #2

The server should never be able to bind the user's keys because there's no way to differentiate a benign slowhack to a malicious slowhack.

The best practice is to use commands on already bindable keys so the user may rebind the keys as they want.
__________________

Last edited by gabuch2; 04-01-2020 at 14:47.
gabuch2 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-01-2020 , 22:49   Re: Using buttons for certain commands
Reply With Quote #3

IIRC, the bind command was blocked on the client (rightfully so). Either create new commands and people can bind their own unused keys or be annoying and link it to existing commands.
__________________
fysiks is offline
DJBosma
Member
Join Date: Dec 2009
Old 04-02-2020 , 07:41   Re: Using buttons for certain commands
Reply With Quote #4

Quote:
Originally Posted by fysiks View Post
be annoying and link it to existing commands.
That was the answer I was looking for, especially the being annoying part. Anyway I would like to offer the players a choice and do it thru a menu. I've tried register_clcmd("radio1","function") which does not work. could you set an example for me @fysiks ?
DJBosma is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-02-2020 , 22:29   Re: Using buttons for certain commands
Reply With Quote #5

Not everything can be hooked with register_clcmd(), there are different ways to hook different commands. This has been asked several times on this forum and there are explanations for how to hook various commands. The question is usually asking about hooking specific commands or specific types of commands. I'd recommend searching for "hook" and your desired function.

Edit: I found a few posts that say hooking radio1, radio2, and radio3 with register_clcmd() works just fine. For example: https://forums.alliedmods.net/showth...k+radio&page=2
__________________

Last edited by fysiks; 04-02-2020 at 22:43.
fysiks is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 04-03-2020 , 07:21   Re: Using buttons for certain commands
Reply With Quote #6

The radio commands work just fine with register_clcmd, I use them all the time. It's more likely that your function doesn't work instead.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
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 22:54.


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