Author Topic: LuaDev with ULX!  (Read 6986 times)

0 Members and 1 Guest are viewing this topic.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
LuaDev with ULX!
« on: July 08, 2016, 08:53:09 PM »
Ever wanted to run the popular addon called LuaDev ( https://github.com/Metastruct/luadev )?

Hated not being able to use its chat commands?

Well fear no more, because I am here with an addon that will allow LuaDev to plugin to ULX!

Code: [Select]
local cmds = {}

if ulx and ulx.cmdsByCategory and not aowl then
aowl = {}

function aowl.cmdExsits(cmd)
local t = ulx.cmdsByCategory['Luadev Commands'] or {}
if t and #t >= 1 then
for i=1,#t do
if t[i].cmd == cmd then return true end
end
end
return false
end

function aowl.AddCommand(cmd, callback, group)
if istable(cmd) then
for k,v in pairs(cmd) do
aowl.AddCommand(v,callback,group)
end
return
end
cmds = cmds or {}
cmds[cmd] = {callback = callback, group = group or "players", cmd = cmd}

for _,v in next, cmds do
local concmd = "ulx ld"..v.cmd
ulx.luadev = ulx.luadev or {}
ulx.luadev[v.cmd] = v.callback

if not aowl.cmdExsits(concmd) then
local com = ulx.command( "Luadev Commands", concmd, ulx.luadev[v.cmd], "!"..v.cmd )
com:addParam{ type=ULib.cmds.StringArg, hint="script", ULib.cmds.takeRestOfLine }
com:defaultAccess( v.group == "developers" and ULib.ACCESS_SUPERADMIN or ULib.ACCESS_ALL )
end
end
end

function aowl.TargetNotFound(trg)
local trg = tostring(trg)
if trg == "notarget" then
return "No target found or target was invalid."
else
return "The target <"..tostring(trg).."> was not found or was invalid."
end
end
end

if SERVER then include("autorun/server/luadev_chatcmds.lua") end

How to use this code? Pretend your making a new ULX command. addons/ulxluadev/lua/ulx/modules/sh/luadevplugin.lua
( I was too lazy to put it in a nice zip. :( )( More server plugins will be available soon! )
« Last Edit: July 09, 2016, 10:50:46 AM by LuaTenshi »
I cry every time I see that I am not a respected member of this community.

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: LuaDev with ULX!
« Reply #1 on: July 09, 2016, 05:39:37 AM »
Modifying the ulx addon itself is usually a bad idea, because you'll have to copy the changed and added files when you want to update ULX. Instead, you should create a separate addon if you want to modify or extend ULX functionality.

I've attached a zip file that contains an addon named "ulx_luadev". This can be extracted directly into the garrysmod/addons/ folder. It contains the code in the above post, in the correct location as to be loaded by ULX.
« Last Edit: July 09, 2016, 05:41:54 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.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: LuaDev with ULX!
« Reply #2 on: July 09, 2016, 07:19:38 AM »
Thank you roastchicken.
All, even when you just want to post a bit of code, please instruct readers to create a new/thier own addon folder, not add files/code to our base.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: LuaDev with ULX!
« Reply #3 on: July 09, 2016, 10:51:06 AM »
Thank you roastchicken.
All, even when you just want to post a bit of code, please instruct readers to create a new/thier own addon folder, not add files/code to our base.

Fixed, in the main post.
I cry every time I see that I am not a respected member of this community.

Offline Marz

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: LuaDev with ULX!
« Reply #4 on: August 07, 2016, 05:30:18 PM »
Can I use EasyLua with this and import my own aowl commands?

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: LuaDev with ULX!
« Reply #5 on: August 08, 2016, 11:27:54 AM »
Can I use EasyLua with this and import my own aowl commands?

Not exactly sure what you're asking. But if you're asking about converting other custom aowl commands into ulx commands using the code above, that should work too.
Just make sure this runs first then add your aowl commands like you normally would. Also you may want to change the "ulx ld" prefix on like line 27.

Adding commands live should work as well as this mimics the aowl globals for adding commands.
I cry every time I see that I am not a respected member of this community.

Offline Marz

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: LuaDev with ULX!
« Reply #6 on: August 08, 2016, 09:05:44 PM »
Not exactly sure what you're asking. But if you're asking about converting other custom aowl commands into ulx commands using the code above, that should work too.
Just make sure this runs first then add your aowl commands like you normally would. Also you may want to change the "ulx ld" prefix on like line 27.

Adding commands live should work as well as this mimics the aowl globals for adding commands.

Okay cheers, I just have an older version of aowl with some commands that I added and if I can use this to convert them to ULX with out having to rewrite them I'd be happy as.