TheXYZNetwork / xAdmin

A free and basic administration system for Garry's Mod.
The Unlicense
28 stars 6 forks source link

Add hooks on commands #15

Closed clear-dev closed 5 years ago

clear-dev commented 5 years ago

Adds hooks to all commands dynamically

0wain commented 5 years ago

Would this not be better placed inside xadmin/core/sv_commands, on the concommand.Add and PlayerSay?

That way instead of hijacking the function command you can block it from running altogether.

clear-dev commented 5 years ago

Yeah, it does make more sense there. I had just created this after doing a few jobs for somebody to swap ULX to xAdmin (primarily logs). I made it like that so I didn't have to touch xAdmin at all :)

Creekie1337 commented 5 years ago

Perhaps something like bc6bdda9f57f05e9da8c48b7ff31836eaf9f699f? It only gets called whenever the player has permissions to use the command, but it allows you to (for example) limit commands to chat only:

hook.Add( "xAdminCommandRun", "xAdminTest", function( ply, args, console )
    if console == true then
        return false
    end
end )

Or only allow the 'sid' command to be ran via chat commands (fixed in 3555a4049dd698b487f2aa33ff3c1f7038642716):

hook.Add( "xAdminCommandRun", "xAdminTest", function( ply, args, console )
    if console == true and args[1] == "sid" then
        return false
    end
end )
0wain commented 5 years ago

Ye, I think to run it through the concommand/hook is the better method. I understand why you originally hijacked the function tho, given you didn't want to mess with the core functionality itself, it makes sense.

@MilkGames gives a better method, although personally, I'd supply the command and args as 2 separate arguments in the function, having the command arg be the command string and then the args being a table of args (or nil).

None the less, the original idea is a very valid one and I should have added it when I released it. Props on this, and shame on me for not doing it myself.

0wain commented 5 years ago

I added it to the command handlers themselves. Credited you on readme too. Gj with the concept <3 Commit: af55d3148394586ded5d1db3fe154aff3c0420dc