Ulysses
Ulysses Stuff => General Chat & Help and Support => Topic started by: JackYack13 on November 11, 2011, 03:41:00 PM
-
I'm creating a gamemode for my gmod server and I'm using ULX on it. Is there anyway to add my own custom commands to ULX? If yes, could I see an example of how it's done? Thanks.
To be more specific I'd like to make commands like give <player> <weapon> or givemoney <player> <amount> and make them work like standard ulx commands (display in ulx help, show usage info, etc.)
-
Yes it is. Even the stock ULX commands are added modularly.
Take a look at any of the pre-existing ulx modules for all the examples you could want. garrysmod/garrysmod/addons/ULX/lua/ulx/modules/sh
If you are making a gamemode, I would assume you aren't a novice so you should be able to figure it out from there. If you require any more help though, let us know.
-
http://forums.ulyssesmod.net/index.php/topic,4464.msg17838.html#msg17838
See also the actual ULib docs at http://www.ulyssesmod.net/docs
-
Thanks. And is there any way to make my commands appear when I type them in the console? I added a command "ulx give" but it doesn't appear on the list when I type for example "ulx g". Do I have to do something client-side as well?
-
If you did it correctly it should be showing up. How did you add the command? Did you create your own file or append an existing ULX file? The prior is the preferred method.
function ulx.cloak( calling_ply, target_plys, amount, should_uncloak )
if not target_plys[ 1 ]:IsValid() then
Msg( "You are always invisible.\n" )
return
end
amount = 255 - amount
for _, v in ipairs( target_plys ) do
ULib.invisible( v, not should_uncloak, amount )
end
return true
end
local cloak = ulx.command( CATEGORY_NAME, "ulx cloak", ulx.cloak, "!cloak" )
cloak:addParam{ type=ULib.cmds.PlayersArg, ULib.cmds.optional }
cloak:addParam{ type=ULib.cmds.NumArg, min=0, max=255, default=255, hint="amount", ULib.cmds.round, ULib.cmds.optional }
cloak:addParam{ type=ULib.cmds.BoolArg, invisible=true }
cloak:defaultAccess( ULib.ACCESS_ADMIN )
cloak:help( "Cloaks target(s)." )
cloak:logString( "#1s cloaked #2s by amount #3i" )
cloak:setOpposite( "ulx uncloak", {_, _, _, true}, "!uncloak" )
cloak:oppositeLogString( "#1s uncloaked #2s" )
ulx.addToMenu( ulx.ID_MCLIENT, "Cloak", "ulx cloak" )
ulx.addToMenu( ulx.ID_MCLIENT, "Uncloak", "ulx uncloak" )
Above is from fun.lua
cloak:addParam{ type=ULib.cmds.PlayersArg, ULib.cmds.optional }
cloak:addParam{ type=ULib.cmds.NumArg, min=0, max=255, default=255, hint="amount", ULib.cmds.round, ULib.cmds.optional }
cloak:addParam{ type=ULib.cmds.BoolArg, invisible=true }
The above is the code that adds the auto complete options to the console I believe.
-
I have this in cmd.lua:
function ulx.give(ply, targets, weap)
local affected_plys = {}
for i = 1, #targets do
local v = targets[i]
if not v:IsValid() then
print("You can't give the server console a weapon!.")
else
v:Give(weap)
table.insert( affected_plys, v )
end
end
ulx.fancyLogAdmin( ply, "#A gave #T #s.", affected_plys, weap )
end
local give = ulx.command("Awesome Build Server", "ulx give", ulx.give, "!give", false)
give:addParam{ type = ULib.cmds.PlayersArg }
give:addParam{ type = ULib.cmds.StringArg, hint = "name of weapon / item" }
give:defaultAccess(ULib.ACCESS_ADMIN)
give:help("Give the player a weapon / item.")
And this in init.lua:
include("cmd.lua")
When I type "ulx g" in the console, commands like "ulx gimp", "ulx gag", "ulx god", "ulx goto" appear, but there's no "ulx give".
-
I know Megiddo and Stickly Man would swoop in here and push MrP and I off our feet, but, heck, let's see if we can help exercise our brains.
:)
Does the command run correctly, though not autocompleted in console? <-- big necessary answer. If ULX says "I have no idea what command that is", then ULX can't place it in autocomplete.
Where are you putting cmd.lua?
Where are you putting init.lua?
If cmd.lua is placed in the proper location (say, addons/my_addon/lua/ulx/modules/sh ), you shouldn't need an init.lua.
I have another idea, but lets see answers to those first.
-
1. The command runs exactly like it should. The autocomplete thing just doesn't work.
2. cmd.lua is in gamemodes/<gamemode name>/gamemode
3. init.lua is in that folder too
-
okay, are you sending that file to the client? The idea behind the ULX module files is that they are shared. For it to autofill it needs to be sent to the client. add that file to your init.lua the same way that you send cl_init.lua and shared.lua
If there is one thing that I could probably answer better than anyone else here is gamemode related quests. I'd like to think that is my pseudo specialty.
The best way would be to do it as JamminR suggests though. Add cmd.lua to the /sh/ folder so that way ULX takes care of making sure the client has the information it needs to populate the menus and autofills. I can understand keeping it in the gamemode if you have other NON ULX commands in that file as well, but maybe you should consider splitting your ULX from your NON ULX commands into 2 separate files.
-
To add to MrPresident's splitting of files idea, it wouldn't be difficult to place both files in addons/my_ulx_addon/lua/ulx/modules/sh .. then in the file that you only want commands to run when in a particular gamemode, then use a if/then to check the gamemode.
You could do the same all in one file of course, but you might find it more difficult to separate the two later when you want to edit only the one or other.
-
I think I got it working at last. I kept all files in the gamemode folder and I simply created another file cl_cmd.lua and included it in cl_init.lua:
local give = ulx.command("Awesome Build Server", "ulx give", nil, "!give", false)
give:addParam{ type = ULib.cmds.PlayersArg }
give:addParam{ type = ULib.cmds.StringArg, hint = "name of weapon / item" }
give:defaultAccess(ULib.ACCESS_ADMIN)
give:help("Give the player a weapon / item.")
Maybe this is not the best way to do this but for some reason I like it the most :P
Anyways thank you all for helping me :)
-
I think I got it working at last. I kept all files in the gamemode folder and I simply created another file cl_cmd.lua and included it in cl_init.lua:
local give = ulx.command("Awesome Build Server", "ulx give", nil, "!give", false)
give:addParam{ type = ULib.cmds.PlayersArg }
give:addParam{ type = ULib.cmds.StringArg, hint = "name of weapon / item" }
give:defaultAccess(ULib.ACCESS_ADMIN)
give:help("Give the player a weapon / item.")
Maybe this is not the best way to do this but for some reason I like it the most :P
Anyways thank you all for helping me :)
Your method is fine. I stuck the whole source files in the shared directories mostly out of laziness and the fact that sharing extraneous code with clients doesn't take much of a penalty hit anymore since Garry sends the files zipped.
Nice catch Mr. P, you were spot on with saying it needed to share that particular code with the client. :)
-
Hello, i notice some command's does not work?
-
Hello, i notice some command's does not work?
you should make a new post on the general chat &help and support tab. make sure to explain what commands dont work. what version of ulx and ulib you are using and what game mode your server is on.