AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   detecting if a player presses a key (https://forums.alliedmods.net/showthread.php?t=184743)

striker07 05-08-2012 12:40

detecting if a player presses a key
 
Is there any way we can detect if a player has pressed a key (for example f) without slowhacking?


fyi, just curious: why is that slowhacking? if we can detect if a player has pushed tab or use then why would detecting a random key (eg: f) be slowhacking?

what if we would check first if a key (eg: f) has been binded to something by the player. if he has binded something to that we do not continue with linking a function to it.
but if he hasnt binded something to that key then we continue linking a function to the key (in the plugin only) so that the server never binds something to that key for that player so if he leaves nothing has been changed in his keyboard settings.

would that still be slowhacking?

Napoleon_be 05-08-2012 12:57

Re: detecting if a player presses a key
 
no it wont.

PHP Code:

register_forward(FM_CmdStart"CmdStart"

PHP Code:

public CmdStart(idHandle) {
    if(
iNoscope[id] == && is_user_alive(id)) {
        static 
button
        button 
get_uc(HandleUC_Buttons)
    
        if (
button IN_SCORE) {
            
button &= ~IN_SCORE
        
}
    
        
set_uc(HandleUC_Buttonsbutton)
    }


this blocks the client going into the scoreboard as far as i know.

<VeCo> 05-08-2012 12:59

Re: detecting if a player presses a key
 
You can't check if the user has binded a command to a key and you can't restore his bind after changing it, so it's slowhacking, unless you don't do it with the user's agreement (like menu asking if he wants it to be changed).

fysiks 05-08-2012 13:04

Re: detecting if a player presses a key
 
Quote:

Originally Posted by striker07 (Post 1704930)
if we can detect if a player has pushed tab or use then why would detecting a random key (eg: f) be slowhacking?

That's not true, we never know if a player has pushed the tab key. We only detect the command sent to the server for the scoreboard, "+showscores". Also, we don't detect the "use key" we detect the command sent to the server, "+use".

This has been asked a million times and the answer hasn't changed.

striker07 05-08-2012 14:02

Re: detecting if a player presses a key
 
Quote:

Originally Posted by fysiks (Post 1704955)
That's not true, we never know if a player has pushed the tab key. We only detect the command sent to the server for the scoreboard, "+showscores". Also, we don't detect the "use key" we detect the command sent to the server, "+use".

This has been asked a million times and the answer hasn't changed.

yes thats what i ment, just a poor explenation, had to retype my entire post becous i accidently pressed return..


Quote:

Originally Posted by <VeCo> (Post 1704950)
You can't check if the user has binded a command to a key and you can't restore his bind after changing it, so it's slowhacking, unless you do it with the user's agreement (like menu asking if he wants it to be changed).

yes ok that's what i need, but then how can I bind an action to the players key if the player choosed yes and agreed with the quick bind?

Quote:

Originally Posted by Napoleon_be (Post 1704946)
PHP Code:

register_forward(FM_CmdStart"CmdStart"

PHP Code:

public CmdStart(idHandle) {
    if(
iNoscope[id] == && is_user_alive(id)) {
        static 
button
        button 
get_uc(HandleUC_Buttons)
 
        if (
button IN_SCORE) {
            
button &= ~IN_SCORE
        
}
 
        
set_uc(HandleUC_Buttonsbutton)
    }


this blocks the client going into the scoreboard as far as i know.

Ok, so what is the meaning of the static button in this block? the key that sends a command to the server? (if so wich command?) or the command itself? (if so wich command?)
could you explain the get_uc and set_uc native a lil better via this block? the info in the funcwiki is everything but usefull

fysiks 05-08-2012 14:23

Re: detecting if a player presses a key
 
static is irrelevant to how the code works. There are posts that explain static vs new. In this case, it is mostly an efficiency thing.

buttons contains a bitwise list of the commands that are active basically.

You should explain exactly what you are trying to do because your suggestion in your first post is not possible.

mottzi 05-08-2012 14:27

Re: detecting if a player presses a key
 
A question: where can I find these defines: IN_SCORE, IN_ATTACK elc..?
Edit: Found it. ITs in hlsdk_const.inc

striker07 05-09-2012 10:51

Re: detecting if a player presses a key
 
Quote:

Originally Posted by fysiks (Post 1705012)
static is irrelevant to how the code works. There are posts that explain static vs new. In this case, it is mostly an efficiency thing.

buttons contains a bitwise list of the commands that are active basically.

You should explain exactly what you are trying to do because your suggestion in your first post is not possible.

ok,
how I want to use this:

In the nightcrawler mod from nikhilgupta345,
Players have to bind a key to "item" first before they can use items and teleport as NC.
I want to ask the player when they join to let the server do it for them.
If they choose yes the server has to bind it for the player. if they choose no then they have to bind it themselves to a key of their choice.

do you think it can be done without slowhacking?

if anyone know a better nightcrawler mod i'd love to take a peek.
This one is hard to read and not very user friendly, but im not complaining, its a good mod :)

ConnorMcLeod 05-09-2012 11:49

Re: detecting if a player presses a key
 
Use autobind plugin.

striker07 05-09-2012 12:44

Re: detecting if a player presses a key
 
wow would you look a that, never expected that that would have an approved plugin, awesome.
thanks for pointing that out connor :up:


All times are GMT -4. The time now is 00:21.

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