• Print

Author Topic: How to override ULX commands  (Read 5257 times)

0 Members and 1 Guest are viewing this topic.

Offline StaTiiKxKALEB

  • Newbie
  • *
  • Posts: 17
  • Karma: 2
How to override ULX commands
« on: June 24, 2016, 06:03:25 pm »
Is there a way to override the ULX commands/remove ULX commands without overriding the ulx core folder. We want to make sure we can easily update ULX. Right now, me and my friend are making a folder and just trying to overriding it and it's not working out so good. Any ideas?

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: How to override ULX commands
« Reply #1 on: June 24, 2016, 06:41:55 pm »
Are you trying to override (change the function of existing commands) or remove them?

If you want to remove them, just don't give permissions to anyone.

The only way to remove them (literally) is to remove the files, but this will have to be done each time you update.

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: How to override ULX commands
« Reply #2 on: June 25, 2016, 01:58:16 am »
In case you want to override the commands, here's how:

    Step 1 - Creating a new addon:
    • Create a new folder in garrysmod/addons/. Name it whatever you want, but lowercase alphanumeric works best.
    Step 2 - Mimicing ULX file structure:
    • Create new folders as necessary to create this structure: garrysmod/addons/<myaddon>/lua/ulx/modules/sh/.
    Step 3 - Overriding the file:
    • Create a new file with the same name as the file containing the command you wish to override. For example, if you wish to override !slap (a 'Fun' command) create a file named fun.lua in garrysmod/addons/<myaddon>/lua/ulx/modules/sh/.
    Step 4 - Overriding the command:
    • Open the file you just created in your code editor of choice. Make sure not to use a Rich Text editor (e.g. Word). If you're unsure what to use, Notepad is a good choice on Windows and Text Edit is a good choice on OSX (you'll have to disable rich text in Text Edit via the menu bar).

Now just write the code to create a ULX command, making sure that the console command, function, and chat command are all identical to the default command you want to override. The basic structure of a ULX command is as such:

Code: Lua
  1. function ulx.cmd( calling_ply )
  2.   -- do stuff
  3. end
  4. local cmd = ulx.command( "My Category", "ulx cmd", ulx.cmd )
« Last Edit: June 25, 2016, 02:03:56 am 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.

  • Print