Creating trigger entities and storing collision order?

So this is my first post, and I’m attempting to create a gamemode similar to trikzsurf like how skyworld works in CSS. They use sourcemod to create triggers ingame and then based on which triggers the player has landed on and what order, it can tell the server they have completed a trick. I’m attempting to create something similar, but have been having problems even finding tutorials for proper implementation of entities. I know I can use Entity:SetTrigger to enable callbacks of trigger events when collided, my problem is actually creating an entity in the first place. Every tutorial I’ve been able to find is either almost a decade old or doesn’t explain what goes where, and when I try to implement pieces of code blindly, it just throwing errors.

I’m not asking for code to be spoonfed, but if anyone can at least steer me in the right direction or link me a proper tutorial, that would be appreciated. Thank you very much and hopefully after I learn more about LUA I can be a productive member of the forum and help others as well!

[editline]8th August 2017[/editline]

My gamemode file structure only consists of “gamemodename” inside the gamemodes folder and gamemodename.txt with everything it needs in that main folder, and cl_init.lua, init.lua, and shared.lua are in the gamemode folder inside my gamemode. Not much code is written for it right now other than setting up a really basic checkpoints system, and setting console vars to make the gameplay the way it should be. Here’s my init.lua file for it:

and my shared.lua:

bump

Is no one able to help me? I really just want some sort of tutorial or anything helpful, like I said I’m not asking to be spoonfed I just need to be pointed in the right direction is all. Any help would be appreciated. Thank you

So you want to know how to make a brush entity or how to store players that trigger it?

Sorta both, I want to dynamically create multiple triggers around the map in arbitrary places through lua (hardcoded) and log any events where the players collide with it, and using that I need to somehow check the order that the player has touched the triggers and match it against a predefined “list” of tricks. If it matches, alert the player that they completed a trick.

Are you making the map or using a map that’s already made?

Please use a little more of this: " "

It’s properly indented in my text editor, it just must have pasted wrong my bad.

I’ve considered creating the triggers in the maps designed specifically for the gamemode, but I also wanted the ability to add triggers to maps that already exist and weren’t meant for it, like construct for example. And I guess you could argue that I could just use a bsp decompiler and add them in, but that would mean it’d be an entirely new map and not only would people have to redownload the map, if they ever played it in a gamemode that wasn’t mine it’d just look exactly like a construct clone with no differences.

You can code an entity of brush type with SetTrigger enabled and create the entities in your hardcoded positions in an InitPostEntity hook. In your entity’s Touch method is where you can do whatever you want with the player.

Yes… but how do I create entities? What file/function does the InitPostEntity hook go into?

You create a file with the name of your entity in lua/entities. You can see examples here: https://github.com/Facepunch/garrysmod/tree/master/garrysmod/lua/entities

The hook would go in lua/autorun/server, or any serverside file.

so like the files I had in the original post, I can put it in my init.lua? If I put my entity in the server files, how do I make a reference to it in my code to create it afterwards also?

Yes, and you can create the entity with ents.Create

How do you spawn brush entities and define their “brushes”?

You set their collision bounds.

Is that actually checked? I heard a long time ago that you can’t use ents.Create for brushes, that you have to place those in hammer

Generally you can’t use ents.Create for brushes is because you can’t define their models, but for triggers you don’t really need an actual model. In fact, I’ve made a brush trigger entity just yesterday, and using SetCollisionBounds on it indeed works fine. Though I also had to do SetSolid(SOLID_BBOX) on it.

For visible brushes, you’ll need to have a mesh attached to it that draws manually.

I’m not too worried about rendering the trigger, I could just draw a 3d box with the same coords if needed, so long as the trigger is placed where I’m trying to place it.

Second question, is there any way to get the face or vertex of the actual map closest to the players position or that the player is touching? Don’t know the full extent of lua or if it’s possible, but it would help a ton

I suppose you could find the closest solid position by doing a series of decreasing traces, but maps are baked into a series of indiscriminate brushes and models that you can’t test individually.