Author Topic: Command redirection  (Read 2128 times)

0 Members and 1 Guest are viewing this topic.

Offline Zealot

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Command redirection
« on: January 21, 2019, 05:02:30 PM »
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: [Select]
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)

Any help would be appreciated.

Offline BlueNova

  • Full Member
  • ***
  • Posts: 113
  • Karma: 13
  • The most powerful force in the universe.
Re: Command redirection
« Reply #1 on: January 21, 2019, 05:12:49 PM »
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?

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Command redirection
« Reply #2 on: January 21, 2019, 07:44:06 PM »
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.
« Last Edit: January 21, 2019, 07:48:58 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Zealot

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Re: Command redirection
« Reply #3 on: January 22, 2019, 07:33:23 AM »
Hello.  I am not currently at my computer, but do you all think this would work?

Code: [Select]
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)

Let me know what you think.

An Error Has Occurred!

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