How am I able to get the used command in "OnRunCommand"?
found
local command = arg.cmd.name
somewhere in the forum, which does not work for me. It just gets hooked by every command used. So its even getting hooked if someone writes anything into the chat :c
Solved Catching console commands (Lua)
Discussion in 'Rust Development' started by LaserHydra, Apr 30, 2015.
-
Wulf Community Admin
That's for the partial name. To get the full command name, you'd need to catch arg.cmd.namefull.
-
-
Wulf Community Admin
Code:function PLUGIN:OnRunCommand(arg) local console = arg.cmd.namefull print(console) end
-
yeah right. just got another failure nothing to do with this part. ^^
[DOUBLEPOST=1430421665][/DOUBLEPOST]
:c -> Also just how I read it somewhere as I never used / detected console commands with args
Code:unformattedmsg = arg.Args[0]
-
Wulf Community Admin
-
-
Wulf Community Admin
-
-
That was one of the first things ive done when Oxide 2 came out. Make a function to make handling args in chat and console commands easier and more intuitive. You can use it if you want.
In chat commands use it like
local args = self:ArgsToTable(args, "chat")
and in console commands
local args = self:ArgsToTable(args, "console")
It returns all args as a lua table starting with index 1.
Code:-- -------------------------------- -- returns args as a table -- -------------------------------- function PLUGIN:ArgsToTable(args, src) local argsTbl = {} if src == "chat" then local length = args.Length for i = 0, length - 1, 1 do argsTbl[i + 1] = args[i] end return argsTbl end if src == "console" then local i = 1 while args:HasArgs(i) do argsTbl[i] = args:GetString(i - 1) i = i + 1 end return argsTbl end return argsTbl end
-
Code:if command == "say" then
-
Wulf Community Admin
-
-
Wulf Community Admin
-
-
Wulf Community Admin
-
Code:if not arg.connection == false then return
-
Wulf Community Admin
-
-- Anyhow -
Wulf Community Admin
If you are trying to block players, then use:
Code:if arg.connection then return end