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
local function ExampleHookedFunction( ply )
print( ply:GetName()…" joined the game.
" ) --This will showup in console on the server
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
print("Prop Spawned by " .. ply:Nick() .. " wohoo!")
concommand.Add(“spawnblock” , ExampleFunction)
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.