Ulysses

General => Developers Corner => Topic started by: OpticPotatOS on June 08, 2016, 08:15:56 AM

Title: Where do you put Derma code?
Post by: OpticPotatOS on June 08, 2016, 08:15:56 AM
So, I'm making a small module for my server that adds one command that opens a derma panel upon execution, but there's a slight problem.

I have no idea where you put the derma code.

Anyone know where you would put the derma code to be executed after a command is run? I know VGUI and Derma are client side, and I'm 99% sure that you stick modules with commands in them in /modules/sh/ or whatever (right? Excuse my apparent noobness). So, how do you get them to work together?
Title: Re: Where do you put Derma code?
Post by: iViscosity on June 08, 2016, 08:17:39 AM
You can put it in shared but you would need to specify if CLIENT then for the vgui to work. You could also make a thing in modules/cl and you wouldn't need to specify it there.

You could probably take a look at my CheckAFK (http://forums.ulyssesmod.net/index.php/topic,9625.0.html) to see how derma would work.
Title: Re: Where do you put Derma code?
Post by: OpticPotatOS on June 08, 2016, 08:22:15 AM
Cool, thanks  :)
Title: Re: Where do you put Derma code?
Post by: iViscosity on June 08, 2016, 08:36:45 AM
No problem. Let me know if you need more info.
Title: Re: Where do you put Derma code?
Post by: roastchicken on June 08, 2016, 11:14:04 AM
VGUI/Derma execution via command is a bit more difficult than simply making a clientside file. As iViscosity pointed out, you could put the file in either lua/ulx/modules/sh or lua/ulx/modules/cl. I would recommend putting the files in lua/ulx/modules/cl unless the file contains serverside code, as there's no reason to run it on the server if you don't need to.

If you want you could instead make it completely separate from ULX by simply putting it (your clientside lua file) somewhere in the (virtual) lua folder (preferably in a custom addon - no need to clutter up garrysmod/lua). You would then need to call it via a lua file placed in lua/autorun (again, preferably in an addon).

iViscosity's CheckAFK does include some examples for how to run clientside code (VGUI/Derma in this case) from a console command. The gist is that you use ULib.clientRPC (http://ulyssesmod.net/docs/files/lua/ulib/server/util-lua.html#clientRPC) to call your clientside derma-creating function. If you really want you could use the net library to get a bit 'closer to the metal' so to speak, but I'm not sure how useful that would be.

Oh, and please don't modify the ulx addon directly. e.g. if you want a file in garrysmod/addons/ulx/lua/ulx/modules/cl, just create your own addon (just a new folder in garrysmod/addons) and replicate the file structure: place the file in garrrysmod/addons/youraddon/lua/ulx/modules/cl. This way you can modify and extend ULX while still being able to update ULX with ease.