Serious Garry's Mod Coding Help Thread

SleepyMode

woah
GTA RP Playtester
Joined
May 12, 2016
Messages
661
Nebulae
2,427
Hello everyone!
Since Facepunch Forums are down, there no longer exists the place where users could easily ask for help when it comes to making things in Garry's Mod.

I know some of the community members have long been trying to either learn how to work with Garry's Mod or are already in the middle of working on different projects and may run into some issues, as even evident by some threads that have been posted on the forums over the years.

Posting Guidelines
  • You may ask for help with solving a problem, but do not expect this to be a way to recruit developers of any kind.
  • Keep it on-topic with Garry's Mod only, do not go off course and leave the languages at GLua and C++(for binary modules).
  • When asking a question, do not be vague or attempt to hide details which may be necessary to help solve your issue.
  • Keep references to other communities to the absolute minimum and refrain from posting links.
  • Do not quote a question saying you ran into a similar issue without posting possible causes or a solution. Use the rating system.
  • Do not harass people for their coding styles and do not provide them with what you think is ideal unless it is part of the issue.
  • Forum rules still apply to the discretion of the moderators.

Important Links
Garry's Mod Wiki
Lua - Getting Started
 

lucid

aussie battler
Joined
Feb 2, 2017
Messages
1,662
Nebulae
6,513
Hello everyone!
Since Facepunch Forums are down, there no longer exists the place where users could easily ask for help when it comes to making things in Garry's Mod.

I know some of the community members have long been trying to either learn how to work with Garry's Mod or are already in the middle of working on different projects and may run into some issues, as even evident by some threads that have been posted on the forums over the years.

Posting Guidelines
  • You may ask for help with solving a problem, but do not expect this to be a way to recruit developers of any kind.
  • Keep it on-topic with Garry's Mod only, do not go off course and leave the languages at GLua and C++(for binary modules).
  • When asking a question, do not be vague or attempt to hide details which may be necessary to help solve your issue.
  • Keep references to other communities to the absolute minimum and refrain from posting links.
  • Do not quote a question saying you ran into a similar issue without posting possible causes or a solution. Use the rating system.
  • Do not harass people for their coding styles and do not provide them with what you think is ideal unless it is part of the issue.
  • Forum rules still apply to the discretion of the moderators.

Important Links
Garry's Mod Wiki
Lua - Getting Started

hi i need help with jobs.lua on my semi-serious darkRP server. if you help me i will give you trial moderator
 

SleepyMode

woah
GTA RP Playtester
Joined
May 12, 2016
Messages
661
Nebulae
2,427
hi i need help with jobs.lua on my semi-serious darkRP server. if you help me i will give you trial moderator
Very nice lucid.

Unironically though DarkRP has it's own wiki with pretty much all the information you may need.
As for jobs, specifically, there also exists a generator to help with those which are less willing to learn Lua for whatever may be the reason, as can be found here.

The general format for jobs in DarkRP will be:
Code:
TEAM_NAME = DarkRP.createJob("Job Name", {
    color = Color(0, 0, 0, 0), -- Color of the job, RGBA 0-255.
    model = "model/player/example.mdl", -- The model of the player in the job, there can be multiple, use a table.
    description = [[Some
    Multi-line
    Description.]],
    weapons = {}, -- All weapons the job will get, insert into the table by means of strings with the name of the weapon, such as "weapon_pistol".
    command = "jobname", -- The chat command that can be used to join the job.
    max = 4, -- The maximum amount of players in this job.
    salary = 100, -- The paycheck of this job on intervals.
    admin = 0, -- Admin level required. 0 = players, 1 = admins, 2 = superadmins.
    vote = true, -- Whether this job utilizes the vote system for entry or not.
    hasLicense = true, -- Do players within this job receive a free gun license? Optional.
    NeedToChangeFrom = TEAM_POLICE, -- The team that the player must change form, if any. Optional.
    customCheck = function(ply)
        return ply:GetUserGroup() == "donator"
    end, -- The custom check for whether a player can join the job or not. This is a Lua function with the player as the only parameter. Optional.
    CustomCheckFailMsg = function(ply, jobTbl)
        return "This job is restricted to donators."
    end, -- A way to get a custom message the player will see if the custom-check fails. Optional.
    modelScale = 5, -- The scale of the model. 1 is standard. Optional.
    maxpocket = 10, -- The maximal amount of items that can fit in the player's pocket. Optional.
    maps = {"gm_construct", "gm_flatgrass"}, -- Maps in which this job will be available. Optional.
    candemote = true, -- Whether people in this job can be demoted. Optional.
    mayor = false, -- Whether players in this job have access to the mayor systems. Optional.
    chief = false, -- Whether players in this job have access to the police chief systems. Optional.
    medic = false, -- Whether players in this job have access to the medic systems. Optional.
    cook = false, -- Whether players in this job have access to the cook systems. Optional.
    hobo = false, -- Whether players in this job have access to the hobo systems. Optional.
    ammo = {["pistol"] = 15}, -- Ammo the player will spawn with.
    category = "Category Name", -- The name of the category the player will be in. This must be a valid category.
    sortOrder = 15, -- The order in which the job will show on the category. Optional.
    playerClass = "player", -- The GMod class to which players will be assigned. Optional. See http://wiki.garrysmod.com/page/player_manager/RegisterClass.
    CanPlayerSuicide = function(ply)
        return ply:Alive()
    end, -- Whether the player can suicide or not. Optional.
    PlayerCanPickupWeapon = function(ply, wep)
        -- If the player's health is over 50, restrict him to picking up HL2 pistols.
        if (ply:Health() > 50) then
            return (wep == "weapon_pistol")
        end
    end, -- Whether a player can pick up a weapon or not.
    PlayerDeath = function(ply, inflictor, killer)
        print("Player " .. ply:Name() .. " was killed" .. ((IsValid(killer) and killer:IsPlayer()) and ("by " ..killer:Name() .. ".") or ".")
    end, -- Called when the player dies
    PlayerLoadout = function(ply)
        ply:SetMaxHealth(150)
        ply:SetHealth(150)

        ply:SetArmor(150)
    end -- Called when the player should have his loadout assigned.
})

And in fact there are plenty of other fields no one really uses in DarkRP jobs.
Most of them can be found here.
 
Last edited:
Reactions: List