Garry's Mod

Garry's Mod

Control Map Entities - Entity:fire() E2 Function (Wiremod / ent_fire)
 This topic has been pinned, so it's probably important
LibertyForce  [developer] Aug 13, 2014 @ 3:58am
FAQs / Documentation
New Revision for Version 2.0

Input types

This depends on the entity that you want to control. Commands such as "kill" (deletes the entity) will always work. Please see the Valve Developer Wiki for detailed information. You will need to look up the entity's class (you can use Easy Entity Inspector) and then look under category "inputs".

Here are the most common things you want to control:

Doors (func_door / func_door_rotating / prop_door_rotating / ...)
Entity:fire("open") # Opens the door
Entity:fire("close") # Closes the door
Entity:fire("lock") # Locks the door (will not open if you press "use" on it)
Entity:fire("unlock") # Unlocks the door

Note: This does not apply for the Combine gates, that you see on maps like city 17. These aren't really doors, but prop_dynamic that play an animation to open the door. Here's how to control this:
Entity:fire("setanimation","open") # Opens the door
Entity:fire("setanimation","close") # Closes the door
The fire() function uses an argument in additon to the input here.

Buttons (func_button)
Entity:fire("use") # Activate the button, just like you pressed it
Entity:fire("lock") # Blocks the button from being pressed
Entity:fire("unlock") # Unblocks the button
Note: If you want to control a map event only via wire, you can block the button and then use
Entity:fire("unlock") Entity:fire("use") Entity:fire("lock")
to be able to control it from via wire.

Thumpers (prop_thumper)
Entity:fire("enable") # Activates the Thumper
Entity:fire("disable") # Deactivates the Thumper

Turrets (npc_turret_floor / npc_turret_ceiling)
Entity:fire("enable") # Activates the Turret
Entity:fire("disable") # Deactivates the Turret
Entity:fire("toggle") # Toggles between On and Off
Only Floor Turret:
Entity:fire("DepleteAmmo") # Turrets behaves like it has no more ammo
Entity:fire("RestoreAmmo") # Undoes "DepleteAmmo"
Entity:fire("selfdestruct") # Burns, then explodes
Entity:setKeyValue("spawnflags",512) # Makes turret friendly (like the ones hacked by Alyx in Nova Prospekt)


Generic commands

The following inputs are the most common. You might want to try them out.
"kill" - Deletes the entity. Warning: This is not ingame killing or suicide!
"use" - Like you pressed "use" on the entity.
"enable", "disable", "turnon", "turnoff" - You can try this to turn on / off things

To get all commands an entity accepts, look at it and type ent_fire !picker (don't press enter) in console. You will see an autocomplete list that will give you all inputs that entity accepts. Use some common sense to figure out the valid ones.



Retrieve own entity

If you plan to dupe the entity (i.e. a thumper) along with whatever it controls, please note that this will ONLY work on Advanced Duplicator or (better) Advanced Duplicator 2[github.com].

Then you'll have to face the problem of changing entity IDs on every spawn. The easiest way to get around this would be to use Wirelink. Link an input E:wirelink directly to the entity. Then fire the entity from the wirelink using:
E:entity():fire("command")
Note: You can also use the E:entity type input, but these used to unlink in the past when duping.


Retrieve map entity

Note: You should really get Easy Entity Inspector or a similar tool to retrieve IDs of the entities!


Methode 1:

Locate the entity and use Easy Entity Inspector to retrieve it's MapCreationID. It's the second number in the first textfield with the entity class.
Ex.: If it shows:
[534 | 2092] prop_door_rotating
Then 2092 would be it's MapCreationID.
If it shows -1 then it's not an map entity but created by a player!

Then, you can use the function entityMapID:
@persist Ent:entity if ( first() | dupefinished() ) { Ent = entityMapID(2092) # Replace 2092 with your retrieved ID } Ent:fire("command")


Methode 2:

If the mapper assigned a unique mapping name to the entity, you can also use E2's find() function. Again, you should use Easy Entity Inspector to retrieve the name.

@persist Ent:entity if ( first() | dupefinished() ) { findByName("insert_unique_name_here") Ent = find() } Ent:fire("command")

Be sure to store the Ent variable under @persist, so you don't have to run the find() all the time.


Methode 3:

If you can't retrieve an entity's MapCreationID or name for some reason, then you still have some options left. You could work with the normal entity ID if you can get thet, but be aware that it can change anytime, for example when the Admin cleans up the map.

I personally figured out that an E2 ranger works nicely to get entities that change IDs. Place an E2 on or near the entity. Use the following code:
@persist Ent:entity Ent = ranger(-10):entity()
This will return the first entity the ranger hits with 10 units from the back of the E2 chip. I used -10, because it looks nicer to place the back of the E2 chip towards the entity. If you use 10 the ranger will come out of the chip's front. Like always, you should store the Ent variable under @persist and only run this once.



I hope, that this gives beginners a little start. If you figured out some more uses, feel free to share them below.
Last edited by LibertyForce; May 16, 2016 @ 10:12am
< >
Showing 1-4 of 4 comments
TomsMo Jul 12, 2015 @ 11:02pm 
Thanks for the great add-on! Taking over map entities is really neat.
http://steamcommunity.com/sharedfiles/filedetails/?id=480630207
Last edited by TomsMo; Jul 12, 2015 @ 11:02pm
M c T h u g g i n Dec 20, 2017 @ 8:43am 
Can you show a simple code for opening set animation doors? I'm new to this and I wanted to make a simple code but I don't know where to start.
tkgaynor Feb 28, 2021 @ 3:49pm 
I have a problem with trying to get a wire keypad to work. CombineGate:fire("setanimation","open") i think i messed the name up. I tried to name the combine gate to "CombineGate" but when i tried, it gave me the: no such function string:fire string string
Sanders Oct 21, 2024 @ 11:19am 
ok is there a way to use player hints with this? like if the door is locked on a map and someone presses said door then they get a message of "door is locked" or something? this would be neat
< >
Showing 1-4 of 4 comments
Per page: 1530 50