Ulysses Stuff > Releases

LuaDev with ULX!

(1/2) > >>

LuaTenshi:
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: ---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

--- End code ---

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! )

roastchicken:
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.

JamminR:
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.

LuaTenshi:

--- Quote from: JamminR 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.

--- End quote ---

Fixed, in the main post.

Marz:
Can I use EasyLua with this and import my own aowl commands?

Navigation

[0] Message Index

[#] Next page

Go to full version