Lua and Hammer?

Hey everyone,

Recently I have seen developers combine maps with their script. Something like lets just say their is a block in the middle of the map. With lua you can add things to this box. But, I was wondering how to do that? Any good tutorials you guys can link me to? This is a very generalized question so I’m not asking for anything so specific.

I’m assuming you’re talking about scripted brush entities, such as triggers. They are scripted like regular SENTs. This is how you would probably want to go about setting it up with a few hooks you might need. To place the entity in the map, open hammer and create a block with the trigger material on each side and tie (cntrl + t ) it to an entity. Manually type in the name of your entity and turn off smart edit if you want to enter your custom key values so that your script can access them.

// shared.lua

ENT.Type             = "brush"
ENT.PrintName        = ""
ENT.Author            = ""

ENT.Spawnable            = false
ENT.AdminSpawnable        = false

// init.lua

AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( 'shared.lua' )

function ENT:Initialize()


function ENT:StartTouch(ent)

function ENT:EndTouch(ent)

function ENT:KeyValue( key, value )


function ENT:Think()


Perfect! Also, is it possible to combine that with custom gamemode variables?

Yes. What are you trying to do with it?

Trying to make a trigger surface do ‘something’ whenever the player touches it. But I want that ‘something’ to be defined with the gamemode so I have more freedom to work with it.

Well just write your script inside the StartTouch hook. You should be able to access all global variables like normal.