Coding Side - IcyStarFrost/Lambda-Players GitHub Wiki

Introduction

Here you will find documentation on the coding side of Lambda Players.

Documentation here assumes you have basic GLua knowledge. If you do not know how to code or don't know lua, please go learn before you start coding for Lambda Players. https://wiki.facepunch.com/gmod/Beginner_Tutorial_Intro

Making a Basic Ranged Weapon

Creating weapons for Lambda Players is pretty simple.

Before we start, you will need to know the variables used in weapon creation. Take a look at the holster.lua weapon which has the documentation on every variable https://github.com/IcyStarFrost/Lambda-Players/blob/master/lua/lambdaplayers/lambda/weapons/holster.lua. After that, take a look at a bunch of default weapons as well and see how they are made and the difference between them. Doing so will help you learn on how to handle weapons.

If you are done reading weapon code, let's finally begin to code a weapon!

Go to Gmod's Addon folder DRIVE:\Program Files (x86)\Steam\steamapps\common\GarrysMod\garrysmod\addons and create a addon like this

image

Basically ADDONNAME/lua/lambdaplayers/lambda/weapons/( LUA Files )

For this, I name my custom weapons addon lambda_stars_customweapons and for this I will create a toolgun that will be used like a pistol. Open your new Lua file and the first thing you should do is put this in your file

image

table.Merge( _LAMBDAPLAYERSWEAPONS, {

    CLASSNAME = {
        model = "models/hunter/plates/plate.mdl",
        origin = "",
        prettyname = "",
        holdtype = "",

        islethal = false,
    }

})

This is a pretty basic template to start with but anyways let's start changing variables

image

I have changed the classname to weaponizedtoolgun, added the toolgun model, made a custom origin on where the weapon came from, set the pretty name, set the holdtype to revolver, and mark the weapon as lethal.

$\textsf{\LARGE⚠\kern{0.2cm}\Large Important}$ When making weapon classnames make sure you only use normal alphabet letters and numbers! DO NOT ADD SPACES IN CLASSNAMES OR ELSE YOU WILL RUN INTO ISSUES!

Now I will begin to make it be functional

image

Normally Gmod will automatically refresh your weapon lua file when you save it but in the event you don't see any changes just run this developer console command: lambdaplayers_dev_reloadaddon.

I am in-game now and I know it worked because I see this is Weapon Permissions

image

Now I can set the spawn weapon to my weapon and test it

image

Although it appears we have ran into a issue. What do we do now?

image

It is very important that you go to every lua file and line from top to bottom of the error that the error mentions so you can figure out if your weapon is missing a variable or if it's a issue with the addon.

In this case, the error told us the we are missing the attack sound to which I have fixed now

image

After that it works!

image

Of course something is off. The weapon is too accurate. Why is that? Of course we are missing the spread variable

image

There we go and now after that I changed the rateoffire to 0.3 seconds and the weapon now works just as I want it to. I show these mistakes as it's important to be able to troubleshoot why your weapon is causing errors or something isn't right. Normally I just copy and paste weapons so I don't really have to make these mistakes again but I wanted to make a weapon from scratch here to demonstrate to you on the process of making a weapon. I won't go over the callbacks since those are relatively simple as well and again I assume you have basic Glua knowledge.

Adding a Kill Icon

Applying a kill icon to your weapon is pretty simple. Just simply add killicon = "" to your weapon table. This is what the comment in holster.lua says about killicons:

killicon | String | The file path to a material ( without the file extension ) to use as the kill icon for this weapon or the alias name of a existing kill icon, example weapon_ar2 is a existing kill icon

To break this down, you can provide a existing kill icon by providing the entity classname. Example, prop_physics this will show up as the toilet. Alternatively, you can provide a file path relative to the materials folder to a VMT file you will use as your kill icon.

To make a custom kill icon, you must know how to work with VTFEdit.

Prepare your .png/.tng/.jpg file that will use as your kill icon and have VTFEdit ready as shown.

image

Next, drag and drop the image on VTFEdit

image

VTFEdit will open and will show you this

image

Don't worry about this at all except make sure Resize is checked on. All you have to do now is Press OK

You will now see your image in VTFEdit

image

What you need to do now is save the image so it can be turned into a VTF file. Head over to File and press Save

image

Save the file anywhere you want and congratulations you now have a VTF file. In the root of your addon, create a materials folder if you haven't already. It should look like this ADDONNAME/materials. Next, create any folder after that like ADDONNAME/materials/ADDONNAMEkillicons and simply place your VTF file in it. For this example I have this file path:

image

Notice the .VMT file. This is the next step. Create a text file and rename it so it has .vmt at the end just like the example above. VMT files are simply text files so open the VMT file you created with notepad or whatever text editing software you have and copy this into it:

UnlitGeneric
{
	"$baseTexture" 		"PATHTOVTF"
	"$vertexcolor" 		1
	"$vertexalpha" 		1
	"$nolod" 			1
	"$additive"			1 // hldm style!
}

After you have done that change the PATHTOVTF to a file path relative from the materials folder to your .VTF file. Do not include the file extension.

Example would be, "$baseTexture" "lambdaplayers/killicons/baby". The VTF is named baby.vtf image

Now here's the last step. Go back to your weapon Lua File to the line that has your killicon = "". Within the "", place the file path relative to the materials folder to your VMT file. Do not include the file extension.

image

And here is the result:

image

Module Creation

Thanks to lambda's modular code you can expand upon Lambda Player's features or add new additions to Lambda Players. Making modules for lambda players is pretty simple so let us begin!

All you really have to do for your addon/module is to have this file path: ADDONNAME/lua/lambdaplayers/extaddon

After that point you can add either of the 3 following folders: server, shared, client. Each folder is dedicated to a certain "realm" so pick whatever suits your needs. Typically you will be just using shared since most functions require that. Now you can place your lua files in whatever folder you created and your addon will now be able to access Lambda's functions. Visit here for documentation on Lambda's functions https://github.com/IcyStarFrost/Lambda-Players/wiki/Functions and visit here for Lambda's hooks https://github.com/IcyStarFrost/Lambda-Players/wiki/Hooks

Here's a example:

image

Now it is up to you to start coding! If you will, have a look at the Official Lambda Modules source codes as the examples

You may need to reload the addon using this console command lambdaplayers_dev_reloadaddon to do the following:

  • See new ConVars in the Lambda Player settings
  • Reload weapons/modules that won't be reloaded by Lua Refresh for whatever reason. This can happen if you try to create new lua files in your addon while in-game
  • Whatever other reason a reload is required