Lua Stuff You Don’t Seem To Know About

I’ve spotted people doing a few things the stupid way. Here’s a few things you might not know about.

entity:Fire

If you really really want to use ent_fire to achieve stuff you don’t need to call the console command. You can use this function.

ent:Fire( "break", 1 );

Now stop using console commands!

RunConsoleCommand

RunConsoleCommand was introduced recently. This allows me to block certain console commands better. You use it like

RunConsoleCommand( "say", "Hello there!" )

You can add as many arguments as you want and they automatically get quotes added if its needed.

Default Gamemode

I don’t think anyone in the last gamemode contest added a default gamemode to their maps. This means that if you want to play that gamemode you have to manually set it in the new game dialog. Which sucks. All you have to do is add a new entity to your map and set the key. It’s easy. There’s a tutorial on the wiki.

The lua_run entity

The lua_run entity allows mappers to run Lua. You can trigger it using all the usual logic and trigger entities. Include the garrysmod.fdg in Hammer to get it to show up. It sets a couple of globals when it’s activated that you can use in your code:

  • ACTIVATOR – The entity that activated it
  • CALLER – The entity that called it
  • TRIGGER_PLAYER – The player that triggered it (if it exists)

The entity is coded in Lua so if you’re unsure what it’s doing take a look at the code.

The New Particles

Everyone is making entities to get access to the new particle system. I already added functions for you to mess with this.

ParticleEffect( strName, vPos, aAngle, entity (optional) )
ParticleEffectAttach( strName, attach_type, entity, iAttachment )

Attachment type in the above is one of:

PATTACH_ABSORIGIN
PATTACH_ABSORIGIN_FOLLOW
PATTACH_CUSTOMORIGIN
PATTACH_POINT
PATTACH_POINT_FOLLOW
PATTACH_WORLDORIGIN

Although I’m pretty sure that to attach a particle you need to have the right settings in the particle itself.