1. Check out the Store if you're looking to Buy HL2RP or other schemas for your server. You can click Buy Schemas on the very top navigation bar to visit the store.
  2. Use the Plugin Center to easily subscribe to and auto-install Clockwork plugins to your server, or submit and share plugins you have developed.
  3. Having trouble setting up or developing with Clockwork? Check out the Wiki or post in the Support Forum for advice from fellow users.
Dismiss Notice
Hi Guest, you need a Steam account to register and post on these forums. Login with Steam at the top of the forums to get started!
Dismiss Notice
Hi Guest, do you want to buy HL2RP or another Clockwork schema? Visit the Cloud Sixteen Store to get started!

Important How to Create a Plugin

Discussion in 'Plugins' started by SomeSortOfDuck, Jul 31, 2013.

  1. You should have at least basic knowledge in Lua!

    Let's start out by just creating our plugin folder. This is the actual folder that we will place in the "plugins" folder of our schema. It should be in all lowercase letters.

    [​IMG]

    Inside of that folder, we need to create another folder called "plugin". We also need to create a .ini file (that is also called plugin).

    http://i.imgur.com/4eXCAcZ.png

    Inside of the plugin.ini file, we simply put the information between the quotes.

    [​IMG]

    Here's the format.

    Code:
    [Plugin]
    name="My Plugin Name";
    author="Duck";
    description="An example plugin.";
    The name does NOT have to be the same as the name of our plugin's folder (which I named "myplugin"). Anyways, let's move on. In the folder we called "plugin", we need to create a Lua file called "sh_plugin". We won't do anything with sh_plugin just yet, so we can just leave it.

    http://i.imgur.com/sCEHaL9.png

    Here, I show you my schema's files on the left. On the right is our plugin's files. You basically want to act like your plugin is the same directory as the directory on the left. If you want to add a command in your plugin, you need to make a commands folder on the right.

    http://i.imgur.com/Xup4mho.png

    Here you can see I created an sv_hooks file. The name of the file depends on what you're trying to do, but since my plugin is using a server hook, I named the file sv_hooks.

    http://i.imgur.com/Ny3Mt1W.png

    See how I mirrored it in my plugin? Anyways, let's move on. I'm trying to make it so that when the player spawns, they'll see a message that tells them they have spawned. I go to sv_hooks in my schema's folder, and then I look for the hook that happens right after the player spawns. This is what the hook looks like.

    [​IMG]

    Now I just copy the code from there, go into the sv_hooks in MY plugin (not the schema's files), and then paste this code in there.

    [​IMG]

    All you have to do is change "Schema" or "Clockwork" into "PLUGIN". You should only do this for the function, not the code inside the function.

    Code:
    local PLUGIN = PLUGIN;
    Here's the code I used.

    Code:
    local PLUGIN = PLUGIN;
    
    -- Called just after a player spawns.
    function PLUGIN:PostPlayerSpawn(player, lightSpawn, changeClass, firstSpawn)
    	player:Notify("You just spawned!")
    end;
    So now, after the player spawns, they'll see a message. This is because I PLUGGED IN to a hook. This code does NOT replace code, it simply adds onto the code that happens in the schema's code. Now we need to go back to sh_plugin, which is also very simple.

    [​IMG]

    All you do is "include" the files you made. Just use the format below.

    Code:
    Clockwork.kernel:IncludePrefixed("sv_hooks.lua");
    Since the only file I made was "sv_hooks", I only included sv_hooks. You do NOT need to "include" commands, libraries, items, and other stuff. Those are automatically added. If you wanted to add a command, you simply MIRROR the commands folder in your plugin's folder, and then place your command there. No need to do Clockwork.kernel:IncludePrefixed("commands/blahblah.lua");

    You don't need to include those, you only need to include the files that exist in the folder called "plugin". Files only, no folders! And you also do not need to include sh_plugin

    http://i.imgur.com/aFgQa9N.png

    Now we're all done! We're ready to ship our plugin out :D

    This is the actual folder you place in the "plugins" folder.

    [​IMG]
     
  2. RJ

    RJ no pay Honorable Clockwork Customer

    +1

    Great tutorial for beginners. I think this should be stickied.
     
  3. invadingaliens

    invadingaliens Honorable

    You're gonna lose your job, RJ.
     
  4. Kezter

    Kezter Twilight Sparkle is best pony! Active Member

    RJ will never lose his job!

    But finally nubs have a place to start :)
     
  5. RJ

    RJ no pay Honorable Clockwork Customer

    Nonsense, I've taken to the field of schemas now.
     
  6. Datzy

    Datzy Guest

    But clearly, now that people know how to make plugins they'll be absolutely PUMPING out schemas!
     
  7. Faoeoa

    Faoeoa Bored as shit, will do simple devving. Active Member

    You're wrong, they're pumping out frameworks!
     
  8. Viomi

    Viomi Running #! Linux Active Member

    +1, Very helpful, thanks :>
     
  9. TheDogFather

    TheDogFather Guest

    Could we have a 'skeleton' for this? It'd be nice to have base line thingy for us to just fill in the gaps.
     
  10. I agree, this would be a nice addition.
     
  11. Daemon01

    Daemon01 I've covered in wars y'know. Active Member

    RJ already did that, lol.
     
  12. RJ

    RJ no pay Honorable Clockwork Customer

  13. Viomi

    Viomi Running #! Linux Active Member

    I'm pretty sure he meant similar to the gamemode skeleton, just a bunch of files with comments / explanations about what to do with them.
     
  14. RJ

    RJ no pay Honorable Clockwork Customer

    It's not that hard really. Anything with sv is for the server, cl for the client, sh for both client and server. Items go in items directory, entities in entities directory, etc.
     
  15. Viomi

    Viomi Running #! Linux Active Member

    Agreed, honestly you just look at the schema files and that's your structure / skeleton right there, so.
     

Previous Readers (Total: 0)