Simple gamemode tutorials?

Hello, I am new to lua and i’m looking for good tutorials for making a gamemode in GMod 13, googling didnt help much as most tutorials are from GM12, and the information in the wiki is too little for things such as Derma menus, I am also confused with the “init.lua, shared.lua, cl_init.lua” uses and how do I use them as well as where do I put some code in.

Any help at all would be appreciated.

This will show you how to setup the files for a gamemode for gmod 13
Once you have the files in order, and you can see your newly created gamemode in game, you’ll be ready to start.

From that point on most of the tutorials from gmod12 should still work, thou in my opinion it’s generally better to mess-around with stuff on your own, rather then following a tutorial line by line.

“init.lua, shared.lua, cl_init.lua” are the base files needed for a gamemode, they represent code that will run in different ways.
code in init.lua will only be run on the server while code in cl_init.lua will likewise only be ran on the client.
(you’ll come to understand that processes are separated; IE: You don’t render things on a server, you render from a client)
It goes without saying the code you write in shard.lua is executed on both the server and the client.

Here is a bit of server side code you can put into init.lua and mess-around with to get used to things
[lua]
local function ExampleHookedFunction( ply )
print( ply:GetName()…" joined the game.
" ) --This will showup in console on the server
end
hook.Add( “PlayerInitialSpawn”, “some_unique_name”, ExampleHookedFunction )
–The easiest way to think of hooks is ‘Hooks run functions when certain things happen’
–This hook runs the the given function whenever a player is spawned for the first time
–The hook passes the player entity as the first argument, which in the above is designated as ply

function ExampleFunction (ply, cmd, args) --ply is the entity that called the console command

local trace = ply:GetEyeTrace() -- Traces where the player is looking

local ent = ents.Create( "prop_physics" ) --prop_physics is the class name of the entity we wish to spawn
if not ent:IsValid() then return end -- if it's not valid, stop this function by returning

ent:SetModel( "models/hunter/blocks/cube2x2x2.mdl" )
ent:SetPos(trace.HitPos + Vector(0,0,50)) --trace.HitPos returns a vector of where the player's trace hit
ent:Spawn()


print("Prop Spawned by " .. ply:Nick() .. " wohoo!")

end
concommand.Add(“spawnblock” , ExampleFunction)
[/lua]

I was gonna write a few more examples, but i’m falling asleep at my keyboard.
Like I said before, it’s best to mess around with things and look at the wiki.
If you have any question, toss them in this thread. I should be around tomorrow; I’m sure others would help you out.

This is the current Glua wiki and has the proper syntax for glua.

This is a mirror of the old Glua wiki, some of the syntax is outdated but it still has a lot of useful information.

Hey, thanks for your help, now I can get started.

This should help too.

I have encountered another problem, I am trying to make player classes but when I call the function to change my class it writes “SetPlayerClass - attempt to use unknown player class player_soldier”
I don’t know if I done anything wrong here so heres some code from init.lua


AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
AddCSLuaFile( "player.lua" )
AddCSLuaFile( "player_class/soldier.lua" )
include( "player_class/soldier.lua" )
include( "player.lua" )
include( "shared.lua" )

The function to call it.


 function team_1( ply ) 
	 player_manager.SetPlayerClass( ply, "player_soldier" )
	 ply:Spawn()
 end 

There is a file called “soldier.lua” in another folder that I have included, but I dont know where I went wrong, no script errors.

Oh god, not him…

Here if you want help “setting up” at least this is the best bet:

Set Up - Gamemode Basics - Entities Extension - Flags

I know it’s personal preference, but I can’t stand people like that who make those types of videos. They should stick to making videos on YouTube pretending to be scared by horror games. These videos were the only ones I found useful. He’s actually calm, explains it, and doesn’t linger for 10 minutes on stupid shit. Besides, those videos are old and they don’t apply for Garry’s Mod 13. By the end you’ll end up redoing most of it anyways.

I’m really disappointed that Chessnut didn’t continue doing any more of those videos. They’re really well made and helpful.

I believe player class files are set to download and run automatically, so I’m not entirely sure, but I don’t think it works when you do it manually. I might be wrong though.