• 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
Custom chat command aliases for console commands
« on: June 10, 2016, 11:00:22 am »
So I just added Enhanced PlayerModel Selector to a few servers, but on gamemodes other than Sandbox the player must send a console command: 'playermodel_selector' to open the playermodel selector.

Is there a quick, easy and customizable code that I can use to create aliases for console command that can be executed in the chat.

Ex: A player typing !model or !playermodel will in turn send the console command: 'playermodel_selector' causing the menu to open without having to know what the console is.

Code: [Select]
CATEGORY_NAME = "Aliases"
 
// Enhanced PlayerModel Selector
function ulx.something(ply)
        something
end
local donate = ulx.command( CATEGORY_NAME, "ulx playermodel", ulx.playermodel, "!playermodel",  "!model" )
playermodel:defaultAccess( ULib.ACCESS_ALL )
playermodel:help( "Description" )

Something like that?

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Custom chat command aliases for console commands
« Reply #1 on: June 10, 2016, 11:13:30 am »
Make it a table
Code: Lua
  1. { "!playermodel", "!model" }

I believe that's how it works.
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 #2 on: June 10, 2016, 11:14:48 am »
But how would I connect it to the console command, the !playermodel command doesn't exist until I create it.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Custom chat command aliases for console commands
« Reply #3 on: June 10, 2016, 11:18:18 am »
Probably the same thing, just with "ulx playermodel" and "ulx model"
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 #4 on: June 10, 2016, 11:22:38 am »
I believe there is a misunderstanding. !playermodel and !model are not existing chat commands. Right now typing them in the chat does absolutely nothing. There is however a console command: 'playermodel_selector' that I want to be able to trigger with a chat command that I create. I don't know how to create chat commands though and I thought there would be an easy way to do it with ULX. This is what I'm asking. What code could I use to achieve this effect and where do I put it?

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Custom chat command aliases for console commands
« Reply #5 on: June 10, 2016, 11:25:58 am »
Oh I'm sorry.

You could likely do it with a ulx function, something like:

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:help( "Opens the player model selector" )
  8.  

Try this out.
If you don't understand, the function Player:ConCommand can be used to allow a console command to be used on a player, in this case, the calling_player.
« Last Edit: June 10, 2016, 11:27:59 am by iViscosity »
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: Custom chat command aliases for console commands
« Reply #6 on: June 10, 2016, 11:48:54 am »
It's a bit overkill to make an entire ULX command just to use the chat commands. Use this (via ULib) instead:
http://ulyssesmod.net/docs/files/lua/ulib/server/concommand-lua.html#addSayCommand

Since you want it to call an existing console command, your supplied function (fn_call) can just call ply:ConCommand("playermodel_selector"), and it should run the command. Alternately, you could just call the lua function directly if you have access to it. Here's an example that should work:

Code: Lua
  1. ULib.addSayCommand( "!playermodel", function(ply, func, args) ply:ConCommand("playermodel_selector") end, "" )
  2.  
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Custom chat command aliases for console commands
« Reply #7 on: June 10, 2016, 11:55:06 am »
Ah, yeah that would be a lot easier. Didn't know addSayCommand was a thing.
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 #8 on: June 10, 2016, 12:08:44 pm »
It's a bit overkill to make an entire ULX command just to use the chat commands. Use this (via ULib) instead:
http://ulyssesmod.net/docs/files/lua/ulib/server/concommand-lua.html#addSayCommand

Since you want it to call an existing console command, your supplied function (fn_call) can just call ply:ConCommand("playermodel_selector"), and it should run the command. Alternately, you could just call the lua function directly if you have access to it. Here's an example that should work:

Code: Lua
  1. ULib.addSayCommand( "!playermodel", function(ply, func, args) ply:ConCommand("playermodel_selector") end, "" )
  2.  

So this and lines for other commands would go in a lua file in lua\autorun?

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: Custom chat command aliases for console commands
« Reply #9 on: June 10, 2016, 12:22:15 pm »
So this and lines for other commands would go in a lua file in lua\autorun?

It would have to go in a place that gets loaded AFTER ULib is loaded. Ideally, in your own addon's or Garry's Mod's lua directory:
Code: [Select]
<your addon>/lua/ulib/modules/<yourfile>.lua
OR
garrysmod/lua/ulib/modules/<yourfile>.lua

Keep in mind that I haven't tested that code, but I'm 80% sure it will work as-is.  :P
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Custom chat command aliases for console commands
« Reply #10 on: June 10, 2016, 12:24:10 pm »
You'd think a member of the staff would be confident :O

:)
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 #11 on: June 10, 2016, 12:25:01 pm »
Thanks so much regardless. This will definitely help make the front-end more user-friendly.

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 #12 on: June 10, 2016, 12:47:43 pm »
Okay I have everything in the right locations and when I execute the chat command it responds with: "You do not have access to this command, ???Chiller252."
I'm not entirely sure how to change this so that it is allowed for all players.

Also, do I have to create another instance of the line of code for more aliases for the same command, or can I do this:?

Code: [Select]
ULib.addSayCommand( "!playermodel", "!model", function(ply, func, args) ply:ConCommand("playermodel_selector") end, "" )
I don't imagine this works when looking at the syntax on .addSayCommand
« Last Edit: June 10, 2016, 12:49:26 pm by Chiller252 »

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Custom chat command aliases for console commands
« Reply #13 on: June 10, 2016, 12:49:21 pm »
Which code did you use? Mine or Stickly Man!'s?
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 #14 on: June 10, 2016, 12:50:13 pm »
I just updated my last post, I am attempting to use something similar to  Stickly Man!'s

  • Print