ULX

Author Topic: Creating a Chat Command  (Read 2095 times)

0 Members and 1 Guest are viewing this topic.

Offline CrazyCallum113

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Creating a Chat Command
« on: September 30, 2013, 04:17:59 PM »
Hey I'm just here to ask about create your own command for ULX. I want to know how to create a chat command to point to a workshop page. For example this would be like typing "!content" and it'd take you to a workshop page to download content - or any desired webpage for that matter. Thanks in advance :)

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Creating a Chat Command
« Reply #1 on: September 30, 2013, 07:25:09 PM »
Best place to start looking/review how would be to look at the code for ULX's motd.
The code is shared between client and server, since server has to send a html text, or a url to have displayed by the client.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline CrazyCallum113

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Re: Creating a Chat Command
« Reply #2 on: September 30, 2013, 11:39:10 PM »
I've tried looking into this and haven't found much luck.
I stumbled across a custom !stopsound command for the chat and I've had a look at the code. I can't figure how to alter it or create a new one that would point to the workshop or a webpage

Code: [Select]
function ulx.stopsounds( calling_ply )
    for _, pl in ipairs( player.GetAll() ) do pl:ConCommand("stopsound") end
end
local stopsound = ulx.command( CATEGORY_NAME, "ulx stopsound", ulx.stopsounds, "!stopsound", true )
stopsound:defaultAccess( ULib.ACCESS_ADMIN )
stopsound:help( "Stops all sounds." )

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Creating a Chat Command
« Reply #3 on: October 01, 2013, 09:31:51 AM »
Look within ULX files themselves.
The client side MOTD section you'd need to study/review from is addons/ulx/lua/ulx/modules/cl/motdmenu.lua
It uses a custom usermessage to receive info from the server to display, either a URL or html text file sent from the server at connect.

The server(shared actually) side code to send the html or url to the client is addons/ulx/lua/ulx/modules/sh/menus.lua

It will all seem a bit complex at first, but it can be pruned down considerably for just a URL and your own command.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming