Best way to override clientside commands

So I’ve seen many arguments on this, and done some searching, but haven’t been able to determine what the best method is for overriding clientside console commands.

I’ve seen many people recommend using the clientside bindpress hook, and calling a custom concommand, but to my knowledge that doesn’t prevent manually typing in the command, only bind presses as the hook name implies.

So, what is the best way to completely override a clientside console command such as +jump?

[lua]

local block = {“crash”};

function engineConsoleCommand(ply,cmd,arg)
for a,b in pairs(block) do
if(b==cmd) then
ply:Kick(“Hacking Attempt…”);
return;
end
end
return concommand.Run( ply, cmd, arg )
end
[/lua]

I’m assuming that’s clientside. What does it hook into, or override?

snip

Commands ran in console.

Ah, I didn’t realize that engineConsoleCommand was a function used by gmod. I thought it was a custom function you wrote. So we are overriding that. Thanks a lot!

After trying the code you posted, it doesn’t appear to even get called… I put a MsgN inside it, and it never prints anything.

Anyone else know of a better way?

[lua]

local block = {“crash”};

function engineConsoleCommand(ply,cmd,arg)
for a,b in pairs(block) do
if(b==cmd) then
print(“I can break these checks.”);
return;
end
end
return concommand.Run( ply, cmd, arg )
end

concommand.Add(“crash”,function()
print(“You cant break those checks!”);
end)

concommand.Add(“crash2”,function()
print(“You cant break those checks!”);
end)
[/lua]



] crash
I can break these checks.
] crash2
You cant break those checks!


[editline]21st June 2011[/editline]

The code needs to be on the corresponding user.

So if you want to catch it on the client all the code must be on the client.

[lua]
function engineConsoleCommand(ply,cmd,arg)
MsgN( 'Called: ', cmd )
return concommand.Run( ply, cmd, arg )
end
[/lua]



] +jump
(nothing)

You can only use it on commands that are not registered by the engine.

I specifically WANT to override commands registered by the engine, as specified by my example in the OP about +jump…

[editline]21st June 2011[/editline]

Is there any way to do that?

gm_concommandhook?

Preferably without modules, since this is a gamemode, I’d like to not have requirements like that.

I’m currently using PlayerBindPress, which works fine, but if people manually enter in a command (such as +jump) then it doesn’t trigger, and the default action takes place. Is there a way to intercept clients manually entering such commands, or should I just stick to bindpress and allow people to enter manual commands?

[editline]21st June 2011[/editline]

Long Story:
For my gamemode HAVOC, I am overriding the built in vehicle brake to be a powerslide instead. When the player presses the spacebar, then it checks their angular velocity and if it is above a threshold, it initiates a powerslide and gives them some boost energy while they are sliding. It also plays a sound, does decals, all that jazz. It works GREAT using PlayerBindPress. However, if a player were to manually type ‘+jump’ into the console, then the powerslide code never runs, and they just brake normally like in HL2.

The powerslide isn’t as much of a problem, but I am also overriding the vehicle sprint, only allowing it if they have enough boost energy. So when they press shift, it checks for boost energy, and then initiates a custom boost, chewing boost energy. If they were to manually type in +speed however, then it does the default vehicle sprint, which is a BIG problem, since it allows them to boost when they don’t have energy to.

[editline]21st June 2011[/editline]

So I need to override the function when they manually type the command, not just on bindpress

How about using **[Gamemode.KeyPress

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.KeyPress)** and KeyRelease, and check for IN_JUMP and IN_SPEED?

How does that override when people from manually type commands? I have them overridden for any bind or keypress. It is manually entering the command in the console I’m trying to override.

Uh, why?

Did you even read my previous posts? Post #13 in this thread?

http://www.facepunch.com/threads/1093396-Best-way-to-override-clientside-commands?p=30615884&viewfull=1#post30615884

You should disable this on the server using one of the Move hooks, otherwise it would be bypassable.

As Chris said; move hook is easier and securer.

How might I go about doing that? Can I detect if the +speed command has been entered serverside? Even so, I’m not sure how to disable the vehicle sprint serverside. If I could detect +speed, then I could apply a force against them, or kill them for trying to cheat or something. But I’d have to detect the command.

[editline]22nd June 2011[/editline]

I guess I’ll have to check their velocity and cap it unless my custom boost command has been called? UGH this is so hacky. We need a sure fire way of detecting or overriding engine commands…