Lua - Turn off map light

How could I toggle a map light using lua? I want to be able to target the closest light to a player and turn it off. I’m making the map if that makes it easier.

You need to find the ent, check if its class is the light class(dunno the hammer class anymore), and then fire TurnOff(I think) on the entity.

Thanks, that worked well - how can I tell if a light is off or a door is open/shut?

As i remember, its can be done by logic_compare

Sorry for bumping in with no actual useful advice, but I’m really curious - can this be done in any map, and on any light (which I doubt due to light bakes)? Or does it need to be a specific light entity (which makes far more sense)? I too was looking for a way to disable map lights, but on any map. I’m assuming this isn’t possible?

it is possible aslong as you know the entity class, like light_enviorement etc.

I’ve got it so when you press IN_USE it disables all lights in a radius of 100, they then turn back on after 10 seconds. This works on a map I’ve just downloaded from the workshop because the lights entity GetClass() is ‘light’.

**
What I want to be able to do is ONLY turn off the lights in the room the player is in, not just by radius, but I know this probably isn’t possible. Does anyone know a way it might be?
**

Make 5 traces, 4 in every way and 1 from floor to roof. You’ll figure the room’s approximate size and then use

ents.FindInBox to find the light entities, and trigger them.

Wow, nice - Alternatively, i’ll have to try and name the entities properly in hammer ( if possible ), but this is definitely a nice solution for now.