ULX

Author Topic: Command redirection  (Read 318 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: 111
  • Karma: 12
  • 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: 7998
  • Karma: 375
  • 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 »
The price one pays for pursuing any profession or calling is an intimate knowledge of its ugly side. - James Baldwin

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.

Offline BlueNova

  • Full Member
  • ***
  • Posts: 111
  • Karma: 12
  • The most powerful force in the universe.
Re: Command redirection
« Reply #4 on: January 22, 2019, 08:58:53 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.

Well unless TEAM_MODERATOR is a table full of teams that would classify them as staff then probably not. You'd be better off by something closer to this...
Code: Lua
  1. if ply:Team() == TEAM_MODERATOR or ply:IsSuperAdmin() then
  2.      -- blah blah blah
  3. end

Offline Zealot

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Re: Command redirection
« Reply #5 on: January 22, 2019, 11:20:32 AM »
Well unless TEAM_MODERATOR is a table full of teams that would classify them as staff then probably not. You'd be better off by something closer to this...
Code: Lua
  1. if ply:Team() == TEAM_MODERATOR or ply:IsSuperAdmin() then
  2.      -- blah blah blah
  3. end

You misinterpret my table check.
But regardless, I think I have a final version for the script.
Code: [Select]
hook.Add("PlayerNoClip", "PreventTheNoclip", function(ply, isallowed)
if !isallowed then
if table.HasValue({TEAM_MODERATOR}, ply:Team()) or ply:IsSuperAdmin then
                ply:ConCommand("ulx noclip")
end
end
if isallowed then return end
end)

I have not tested this at a computer yet.  I am on a work laptop.
First, there was the problem with the hook.  PlayerNoClip definitely looked like the hook I was looking for, so thank you for pointing me towards that.  Second, the way I was addressing the function would not work with the PlayerNoClip hook.  That has two identifiers:
player, and IsNoclipAllowed.  Therefore, I changed it so that if noclip is NOT allowed then we initiate the script.  However, if it is allowed, we return the script.
Again, I have not tested this out.  I will test it when I get home.