General > Developers Corner

Command redirection

(1/2) > >>

Zealot:
Hello.  I am trying to fix this script so that when the player uses the command "noclip" it redirects it to "ulx noclip".  I thought I had it at first, but it doesn't work.  Can anyone tell me what I may be doing wrong?


--- Code: ---hook.Add("ULibCommandCalled", "PreventTheNoclip", function(ply, cmd, args)
if cmd == "noclip" then
return ply:Team() == TEAM_MODERATOR or ply:IsSuperAdmin()
ply:ConCommand( "ulx noclip" )
end
end)
--- End code ---

Any help would be appreciated.

BlueNova:
Without doing something other than a quick read, you have it returning before you have the player run noclip. So the hook will stop. Maybe just replace the return statement with an if/else statement?

JamminR:
Will standard server/client console command "noclip" trigger ULibcommandcalled?
noclip is a standard server function, not even part of ULib.
I imagine, it's possible, since we hook into ALL hooks with a priority system, that we might see it.
I'm not sure that's intentional though, and wouldn't expect ULibcommandcalled to be called.

(Oh, and BlueNova, nice to see you here)

EDIT - In addition to BlueNova's suggestions, you may have better luck with the GM:PlayerNoClip hook.

Zealot:
Hello.  I am not currently at my computer, but do you all think this would work?


--- Code: ---hook.Add("PlayerNoClip", "PreventTheNoclip", function(ply, cmd, args)
if cmd == "noclip" then
If table.HasValue({TEAM_MODERATOR} ply:Team()) or ply:IsSuperAdmin()
ply:ConCommand( "ulx noclip" )
                end
end
end)
--- End code ---

Let me know what you think.

An Error Has Occurred!

array_keys(): Argument #1 ($array) must be of type array, null given

[0] Board index

Go to full version