• Print

Author Topic: Custom chat command aliases for console commands  (Read 14850 times)

0 Members and 1 Guest are viewing this topic.

Offline Chiller252

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 3
  • On a Journey to Combine Technology and Design
    • Personal Website
Re: Custom chat command aliases for console commands
« Reply #15 on: June 10, 2016, 01:01:07 pm »
Do I have to amend the command with an argument that determines the permissions required to run it? Can I just set it to all?

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Custom chat command aliases for console commands
« Reply #16 on: June 10, 2016, 01:22:27 pm »
Code: Lua
  1. ULib.addSayCommand( { "!playermodel", "!model" }, function(ply, func, args) ply:ConCommand("playermodel_selector") end, "" )

You need to add a table, first of all. If that doesn't work, then probably you'd need to add more lines, yes.


I'm not very familiar with addSayCommand... but maybe this could help you... I don't know.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline Chiller252

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 3
  • On a Journey to Combine Technology and Design
    • Personal Website
Re: Custom chat command aliases for console commands
« Reply #17 on: June 10, 2016, 02:18:30 pm »
Oh man this is tricky. I'm not familiar enough with lua and the syntax of ulx/ulib to be able to figure this out on my own. I'm doing some research, but it looks like nobody has done this before the way I'm doing it. I keep getting this message: "You do not have access to this command"

This is the line I'm currently trying to use:
Code: [Select]
ULib.addSayCommand( "!playermodel", function(ply, func, args) ply:ConCommand("playermodel_selector") end, "" )
pls halp

EDIT: Now I'm trying to use this:
Code: [Select]
ULib.addSayCommand( { "!playermodel", "!model" }, function(ply, func, args) ply:ConCommand("playermodel_selector") end, "" )
and I'm getting this error:

Code: [Select]
[ERROR] addons/aliases/lua/ulib/modules/aliases.lua:1: attempt to call field 'addSayCommand' (a nil value)
  1. unknown - addons/aliases/lua/ulib/modules/aliases.lua:1
   2. include - [C]:-1
    3. unknown - addons/ulib/lua/ulib/cl_init.lua:24
     4. include - [C]:-1
      5. unknown - addons/ulib/lua/autorun/ulib_init.lua:5
« Last Edit: June 10, 2016, 02:22:45 pm by Chiller252 »

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Custom chat command aliases for console commands
« Reply #18 on: June 10, 2016, 02:29:09 pm »
I could be wrong about the table, so you might need to make new lines for each alias.

I'll look into it more when I get home.
« Last Edit: June 10, 2016, 02:32:05 pm by iViscosity »
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline Chiller252

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 3
  • On a Journey to Combine Technology and Design
    • Personal Website
Re: Custom chat command aliases for console commands
« Reply #19 on: June 10, 2016, 02:33:50 pm »
Thank you so much.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Custom chat command aliases for console commands
« Reply #20 on: June 10, 2016, 02:46:53 pm »
By the way: You can use the [code=lua][/code] tag to highlight LUA stuff.

Also, when you were using the
Code: Lua
  1. ULib.addSayCommand( "!playermodel", function(ply, func, args) ply:ConCommand("playermodel_selector") end, "" )
line, did that give any errors or anything when you used it?
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline Chiller252

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 3
  • On a Journey to Combine Technology and Design
    • Personal Website
Re: Custom chat command aliases for console commands
« Reply #21 on: June 10, 2016, 02:52:26 pm »
By the way: You can use the [code=lua][/code] tag to highlight LUA stuff.

Also, when you were using the
Code: Lua
  1. ULib.addSayCommand( "!playermodel", function(ply, func, args) ply:ConCommand("playermodel_selector") end, "" )
line, did that give any errors or anything when you used it?

Thanks for the tip, I was wondering how to flag it as lua.
Also, I did not get any lua errors for using that snippet. I however got the "You do not have access to this command, ???Chiller252." message when trying to execute the chat command.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Custom chat command aliases for console commands
« Reply #22 on: June 10, 2016, 03:01:50 pm »
Honestly, I don't know much about the addSayCommand so really I personally would just use
Code: Lua
  1. function ulx.models( calling_ply )
  2.  
  3.   calling_ply:ConCommand( "playermodel_selector" )
  4.  
  5. end
  6. local models = ulx.command( "Aliases", "ulx models", ulx.models, { "!playermodel", "!model" } )
  7. models:defaultAccess( ULib.ACCESS_ALL )
  8. models:help( "Opens the player model selector" )
and put that in addons/<addon folder>/lua/ulx/modules/sh

I know it's a lot to make that work, but I feel like it would be easier. If you're having issues, let me know.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline Chiller252

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 3
  • On a Journey to Combine Technology and Design
    • Personal Website
Re: Custom chat command aliases for console commands
« Reply #23 on: June 10, 2016, 03:52:26 pm »
Honestly, I don't know much about the addSayCommand so really I personally would just use
Code: Lua
  1. function ulx.models( calling_ply )
  2.  
  3.   calling_ply:ConCommand( "playermodel_selector" )
  4.  
  5. end
  6. local models = ulx.command( "Aliases", "ulx models", ulx.models, { "!playermodel", "!model" } )
  7. models:defaultAccess( ULib.ACCESS_ALL )
  8. models:help( "Opens the player model selector" )
and put that in addons/<addon folder>/lua/ulx/modules/sh

I know it's a lot to make that work, but I feel like it would be easier. If you're having issues, let me know.

OMG thank you this is working perfectly. Don't worry about it being smaller, I'll take anything I can get.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Custom chat command aliases for console commands
« Reply #24 on: June 10, 2016, 04:28:24 pm »
Glad I could help.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Custom chat command aliases for console commands
« Reply #25 on: June 11, 2016, 08:36:08 am »
Code: Lua
  1. ucl.registerAccess( "playermodel_selector", ULib.ACCESS_ALL )
  2.  
  3. ULib.addSayCommand( "!playermodel", function(ply, func, args) ply:ConCommand( "playermodel_selector" ) end, "playermodel_selector" )
  4. ULib.addSayCommand( "!model", function(ply, func, args) ply:ConCommand( "playermodel_selector" ) end, "playermodel_selector" )

The third argument is the access string. Leaving this blank doesn't mean anyone can access it. I've added the access string "playermodel_selector" and given everyone access. If you want to change the default access, just switch 'ULib.ACCESS_ALL' out with one of the other access strings, or a group name.

You also can't just throw a table in there for the first argument and expect it to work. According to the documentation this must be a string, so I've gone ahead and created two.

This should go in a lua file located in either garrysmod/addons/<your addon>/lua/ulib/modules/ OR garrysmod/lua/ulib/modules/, as Stickly Man! stated.

Let me know if you have any issues with this. I've tested it on my server and it seems to work fine, but that doesn't necessarily mean it will work on yours.

edit:

For some reason this code is telling me that ULib.ucl.registerAccess is a nil value. I guess this code doesn't work after all.
« Last Edit: June 11, 2016, 12:14:29 pm by roastchicken »
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Custom chat command aliases for console commands
« Reply #26 on: June 11, 2016, 09:56:03 am »
Yeah I just assumed table because of ulx.command
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline Chiller252

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 3
  • On a Journey to Combine Technology and Design
    • Personal Website
Re: Custom chat command aliases for console commands
« Reply #27 on: June 11, 2016, 04:16:44 pm »
Code: Lua
  1. ucl.registerAccess( "playermodel_selector", ULib.ACCESS_ALL )
  2.  
  3. ULib.addSayCommand( "!playermodel", function(ply, func, args) ply:ConCommand( "playermodel_selector" ) end, "playermodel_selector" )
  4. ULib.addSayCommand( "!model", function(ply, func, args) ply:ConCommand( "playermodel_selector" ) end, "playermodel_selector" )

The third argument is the access string. Leaving this blank doesn't mean anyone can access it. I've added the access string "playermodel_selector" and given everyone access. If you want to change the default access, just switch 'ULib.ACCESS_ALL' out with one of the other access strings, or a group name.

You also can't just throw a table in there for the first argument and expect it to work. According to the documentation this must be a string, so I've gone ahead and created two.

This should go in a lua file located in either garrysmod/addons/<your addon>/lua/ulib/modules/ OR garrysmod/lua/ulib/modules/, as Stickly Man! stated.

Let me know if you have any issues with this. I've tested it on my server and it seems to work fine, but that doesn't necessarily mean it will work on yours.

edit:

For some reason this code is telling me that ULib.ucl.registerAccess is a nil value. I guess this code doesn't work after all.


Yeah I started testing with it and got the same thing:

Code: Lua
  1. [ERROR] addons/aliases/lua/ulib/modules/aliases2.lua:1: attempt to index global 'ucl' (a nil value)
  2.   1. unknown - addons/aliases/lua/ulib/modules/aliases2.lua:1
  3.    2. include - [C]:-1
  4.     3. unknown - addons/ulib/lua/ulib/init.lua:74
  5.      4. include - [C]:-1
  6.       5. unknown - addons/ulib/lua/autorun/ulib_init.lua:3

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Custom chat command aliases for console commands
« Reply #28 on: June 11, 2016, 04:18:13 pm »
It needs to be ULib.ucl.registerAccess, not ucl.registerAccess, roastchicken just mis-typed it.
« Last Edit: June 11, 2016, 04:20:12 pm by iViscosity »
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline Chiller252

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 3
  • On a Journey to Combine Technology and Design
    • Personal Website
Re: Custom chat command aliases for console commands
« Reply #29 on: June 11, 2016, 04:19:02 pm »
So just making sure:

To add another command I change out the parameters like this?:
Code: Lua
  1. function ulx.killme( calling_ply )
  2.  
  3.   calling_ply:ConCommand( "kill" )
  4.  
  5. end
  6. local killme = ulx.command( "Aliases", "ulx killme", ulx.killme, { "!kill" } )
  7. killme:defaultAccess( ULib.ACCESS_ALL )
  8. killme:help( "Causes the player to commit suicide" )

  • Print