Personal Questions for Gamemode Creation

I tried being as descriptive as possible with my title but there was only so many ways that I could describe this thread. What I need is answers to several questions that I have on gamemode creation while I create the gamemode that I want. I am going to list the questions in priority that they need to be answered. Don’t feel afraid to get a bit off topic with your answer as long as it stays on the topic of gamemode creation, if there is extra tips or tricks you guys have I would love to hear it. Working with a team or finding people to be with me in a team is not an option at all. Do to various reasons I need to work by myself on the actual code, so please do not give me a tip that would require multiple people or tell me to find someone.


1: How do classes (not to be confused with teams) exactly work? (I need example code for this one) EDIT: Class as in the player_manager.
2: I need a good description on Stencils and how to make proper things with them. Also if anyone could tell me how to use them to make holes in props or entities that'd be amazing.
3: What's the difference between the render and surface libraries? I saw one example where someone used surface.DrawRect() with stencils and set the x and y position to 
-ScrW()*2 and -ScrH()*2. Instead of making a rectangle it made an outline around the stenciled object. Why?
4: How do I make a melee weapon and how do I make a ranged weapon with special effects on the player it hits?
5: I am making the gamemode off of the base gamemode not the sandbox, is there any functions I should avoid overwriting?

I will be adding more as the thread goes on, I will solve the thread as soon as my gamemode is finished (because after that I wouldn’t have anymore questions).

  1. No. They’re part of the game engine and are not made in Lua. I think some people have tried to remake it in Lua though.

  2. Do you mean stuff like

Entity:GetClass?
Every entity in Garry’s Mod has a class to identify it.
You can name SENT (scripted entity) classes whatever you want, but the default game engine ones usually follow a nice pattern:

  • Weapons usually start with ‘weapon_’, unless they’re a SWEP (scripted weapon).
  • Tools usually start with ‘tool_’ or ‘stool_’.
  • Vehicles are usually ‘prop_vehicle’, unless they’re SENTs (scripted entities).
  • Moving props with physics are usually ‘prop_physics’ or ‘prop_dynamic’, but can be a bunch of things.
  • Ragdolls are ‘prop_ragdoll’.

There’s many other kinds of classes, but they don’t really matter. They’re just useful for identification.

  1. Me too. I’ve always wanted to know how to make holes in things using stencils.
    You’ll probably have to use

cam.Start3D2D and

render.RenderView to draw a hole, and a stencil for the hole’s shape.

4: There’s many kinds of algorithms. Really, anything in programming can be called an algorithm. It’s very vague.
You don’t really need to worry about algorithms until you know specifically what you want to achieve in your gamemode.
Then, if you need to find an algorithm to do it, you can just google whatever you want to do.

5: Both sorts of weapons are of the same type, a SWEP (scripted weapon).
There’s a basic tutorial to introduce you to them here.

6: Not sure. I’ve never made a gamemode, but I know about other stuff.

  1. http://forum.facepunch.com/showthread.php?t=1337232

Thank you for your response. I meant the class for player_manager and edited the first post to be more specific, however the extra info will be extremely helpful.

I looked at that thread before but still having a hard time understanding. Do you need to use STENCILCOMPARISONFUNCTION_ALWAYS? or is that just included for those specific examples?

Is this what you are looking for?

Hello, I have a job lua error that I am trying to get immediate help for, here is the error

[ERROR] Lua is unable to understand file “darkrp_customthings/jobs.lua” because its author made a mistake around line number 18.
The best help I can give you is this:

Right before the ‘TEAM_SWATLEADER’, Lua expected to read an ‘=’-sign, but it didn’t.

Here is the job,

TEAM_SWATLEADER = DarkRP.createJob(“SWAT Leader”, {
color = Color(0, 58, 255, 255),
model = {“models/player/bfh_enforcer.mdl”},
description = [[You run the swat team, good luck.]],
weapons = {“m9k_scar”, “m9k_spas12”, “m9k_deagle”},
command = “SWATLEADER”,
max = 1,
salary = 250,
admin = 0,
vote = false,
hasLicense = true,
candemote = true,
category = "SWAT ",
PlayerSpawn = function(ply)
ply:SetMaxHealth(200)
ply:SetHealth(200)
ply:SetArmor(150)
end,
customCheck = function(ply) return
table.HasValue({“Donator”, “superadmin”, “Owner”, “Co-Owner”}, ply:GetNWString(“usergroup”))
end,
CustomCheckFailMsg = “This job is donator only!”,
})


(User was banned for this post ("Don't try and hijack someone else's help thread, especially when you've already made one" - Sgt Doom))

This is not “Fix my shitty darkrp jobs file” thread

Yes, thank you, could i put my code for the classes in a separate Lua file and include it in my shared.lua file which would use team.SetClass()?

In addition to my stencil question. Is there a way to keep something from rendering? Specifically players? (return true doesn’t work for some reason in the below code)


local IN_HOOK = false

hook.Add("PrePlayerDraw", "test", function(ply)

	if((IN_HOOK) or (LocalPlayer():GetNWBool("opticalMutation", false) == false)) then return end
	
	IN_HOOK = true
	
	render.SetStencilEnable(true)
		
		render.ClearStencil()
		render.SetStencilReferenceValue(1)
		render.SetStencilCompareFunction(STENCIL_ALWAYS)
		render.SetStencilPassOperation(STENCIL_ZERO)
		render.SetStencilFailOperation(STENCIL_ZERO)
		render.SetStencilZFailOperation(STENCIL_REPLACE)
		render.SetBlend(0)
			ply:DrawModel()
		render.SetBlend(1)
		
		render.SetStencilCompareFunction(STENCIL_EQUAL)
		
		cam.IgnoreZ(true)
		ply:DrawModel()
		cam.IgnoreZ(false)
		
	render.SetStencilEnable(false)
	
	IN_HOOK = false
	return true

end)

EDIT: Just in case, this is code made by someone else that I am using. Don’t sue (in the form of getting me banned for some reason).

I got inspired by this question to try something I’ve always wanted to do:

Now I can actually give you a useful answer.

To make holes in things using stencils, I used a lot of code from World Portals. It has fantastically simple code to draw a ‘hole’ in anything you want, and it lets you draw whatever you want in this ‘hole’. It also provides useful functions to convert positions and angles from one location to another.

Although the code isn’t called ‘World Holes’, there’s no way to draw a hole without it being somewhat like a portal.

Two files in this code are used to draw the portals.

The first is in a RenderScene hook.

The reason the portals get drawn using this hook is because

GM:RenderScene provides a 2D drawing context. You need this context to render the view onto a flat texture. If you try to use

render.RenderView in a 3D context, it will screw up a lot of stuff, especially your viewmodel.

The second part is in ENT:Draw.

Here is where the material is drawn onto the screen using a stencil in a 3D context. It uses

render.DrawQuadEasy to draw the stencil outline, but you can change this to draw any shape at all. For my code, I used

cam.Start3D2D, and

surface.DrawPoly. This let me draw flat circles, which I needed for a bullet hole.

I know this explanation is pretty bad, but really, all you need to do is copy paste the whole stencil bit like I did, and then just change the

render.RenderView coordinates to move the camera around.

Use RenderOverride on the player.

I’m a bit of a noob ^_^’ can you give me an example? Besides the one on the wiki?


hook.Add("OnEntityCreated", "blah", function(pEntity)
	if (pEntity:IsPlayer()) then
		pEntity.RenderOverride = function(pEntity)
			render.SetStencilEnable(true)
			
			render.ClearStencil()
			render.SetStencilReferenceValue(1)
			render.SetStencilCompareFunction(STENCIL_ALWAYS)
			render.SetStencilPassOperation(STENCIL_ZERO)
			render.SetStencilFailOperation(STENCIL_ZERO)
			render.SetStencilZFailOperation(STENCIL_REPLACE)
			
			render.SetBlend(0)
				pEntity:DrawModel()
			render.SetBlend(1)
			
			render.SetStencilCompareFunction(STENCIL_EQUAL)
			
			cam.IgnoreZ(true)
				pEntity:DrawModel()
			cam.IgnoreZ(false)
			
			render.SetStencilEnable(false)
		end
	end
end)

This helps a lot thank you :smiley: I am still going to do further research into this before I remove the question from this thread but thank you a lot for this!

[editline]12th September 2017[/editline]

:open_mouth: I will use this immediately thank you!

btw when I use the avatar panel, it doesn’t multiplies when I change resolution. Is there a way to circumvent that?


include("shared.lua")

local HEALTHBAR_HUD = Material("hud/health_hud.png", "noclamp")
local BLINKBAR_HUD = Material("hud/blink_hud.png", "noclamp")
local STAMINABAR_HUD = Material("hud/stamina_hud.png", "noclamp")

local CLASSD_HUD = Material("hud/classd_hud.png", "noclamp")
local MOBILETASKFORCE_HUD = Material("hud/guard_hud.png", "noclamp")
local MTFCOMMANDER_HUD = Material("hud/guard2_hud.png", "noclamp")
local RESEARCHER_HUD = Material("hud/researcher_hud.png", "noclamp")
local SCP_HUD = Material("hud/scp_hud.png", "noclamp")
local CHAOSINSURGENCY_HUD = Material("hud/spy_hud.png", "noclamp")

function GM:HudPaint()

	surface.SetMaterial(CLASSD_HUD)
	surface.SetDrawColor(255, 255, 255)
	surface.DrawTexturedRect(0, ScrH()/2 + ScrH()/4, ScrW()/4, ScrH()/4)

end

This isn’t working, any ideas?

Is HUDPaint, not HudPaint

:s: I am shame


local hide = {
	CHudHealth = true,
	CHudBattery = true,
}

function HUDShouldDraw( name )
	if ( hide[ name ] ) then return false end

	-- Don't return anything here, it may break other addons that rely on this hook.
end )

this doesn’t work properly, it just deletes everything in my HUDPaint()

That’s not even called, you are missing GM:
I highly recommend you to download some gamemode and then try to understand those