-
Notifications
You must be signed in to change notification settings - Fork 333
Expression 2 Events
Expression 2 has event
s that allow you to manage what parts of your code run when certain things happen, like a player typing in chat and when a player leaves the server.
They're analogous to gmod's hook
system if you are familiar Garry's Mod Lua.
If you're here because of your code giving you warnings about certain runOn*
functions being deprecated, this is for you.
The clk (trigger) system is the old way of handling "events" with runOn*
and *clk()
functions. It's being replaced due to being one of the most confusing and suboptimal things about the language.
Events are closer to what real world programming languages do, are more efficient, and simpler to understand.
The syntax is pretty simple. They are similar to functions in how you declare them, but missing the return value type, and using event
instead of function
. Note, however, that events are not functions. They are a compile time construct. You can't redeclare them or stop them, at least for now. Check a variable inside the event if you do not want code inside of it to run anymore.
event chat(Ply:entity, Said:string, Team:number) {
print(Ply, " just said ", Said)
}
Owner = owner()
event keyPressed(Ply:entity, Key:string, Down:number, Bind:string) {
if (Ply == Owner & !Down) {
print("Owner released key " + Key)
}
}
Additionally, if you just begin to type event
and the name of the event, the editor will autocomplete the whole declaration for you!
All events you write in the code are registered at compile time once. So you should nest them inside any if
statement.
Once they are registered, every time the event fires, only the code inside of the event will run. You can think of them as functions you give to lua.
For simplicity and efficiency, timers work on a different system than events. See E2: Timers.
Declaration | Description |
---|---|
event chat(Player:entity, Message:string, Team:number) |
Runs when a Player sends a chat Message . Team is 1 if it's sent in team chat. Replaces chatClk . |
event chipUsed(Player:entity) |
Runs when the E2 chip is used by a Player . Replaces useClk . |
event egpHudConnect(Screen:wirelink, Player:entity, Connected:number) |
Runs when a Player connects to an EGP HUD, Screen . Connected is 1 if the player is connecting and 0 if the player is disconnecting. |
event entityCreated(Entity:entity) |
Runs when an Entity is created. |
event entityDamage(Victim:entity, Damage:damage) |
Runs when a Victim entity takes Damage . |
event fileErrored(File:string, Error:number) |
Runs when a file fails to load. File is the path of the requested file, Error is the error code enum. Replaces fileClk . |
event fileList(Path:string, Contents:array) |
Runs when a file list operations succeeds. Path is the requested path, Contents is an array of file names and directories as strings. Replaces fileListClk . |
event fileLoaded(File:string, Data:string) |
Runs when a file load succeeds. File is the path of the requested file, Data is the contents of the file. Replaces fileClk . |
event fileWritten(File:string, Data:string) |
Runs when a file finishes sending to the client. File is the path of the file, Data is the written data. |
event httpErrored(Error:string, Url:string) |
Runs when an HTTP request fails. Error is the error message and Url is the URL that was requested. Replaces httpClk . |
event httpLoaded(Body:string, Size:number, Url:string) |
Runs when an HTTP request succeeds. Body is the contents of the page, Size is the size of the page, and Url is the URL that was requested. Replaces httpClk . |
event input(InputName:string) |
Runs when an input triggers the E2. InputName is the name of the input. Replaced inputClk . |
event keyPressed(Player:entity, Key:string, Down:number, Bind:string) |
Runs when a Player presses or releases a Key . Down is 1 if the key is pressed and 0 if it is released. Bind corresponds to this table. Replaces keyClk . |
event playerChangedTeam(Player:entity, OldTeam:number, NewTeam:number) |
Runs when a Player changes from OldTeam to NewTeam . |
event playerConnected(Player:entity) |
Runs when a Player connects to the server. Replaces playerConnectClk . |
event playerDeath(Victim:entity, Inflictor:entity, Attacker:entity) |
Runs when a Victim player dies to the Attacker player. Inflictor is the weapon used. Replaces deathClk . |
event playerDisconnected(Player:entity) |
Runs when a Player disconnects from the server. Replaces playerDisconnectClk . |
event playerEnteredVehicle(Player:entity, Vehicle:entity) |
Runs when a Player enters a Vehicle . |
event playerLeftVehicle(Player:entity, Vehicle:entity) |
Runs when a Player leaves a Vehicle . |
event playerMove(Player:entity, MoveData:movedata, Command:usercmd) |
Runs when a Player moves with their mouse or keyboard. |
event playerSpawn(Player:entity) |
Runs when a Player spawns, including respawns. Replaces spawnClk . |
event playerUse(Player:entity, Entity:entity) |
Runs when a Player uses an Entity . |
event remote(Sender:entity, Player:entity, Payload:table) |
Event triggered by broadcastRemoteEvent(t) or e:sendRemoteEvent(t) , replacing datasignals and gtables |
event removed(Resetting:number) |
The last code ran before the chip is removed. Resetting is 1 if the E2 is resetting. Replaces last . |
event tick() |
Runs on every game tick. Replaces tickClk . |
event weaponPickup(Weapon:entity, Owner:entity) |
Runs when Owner picks up Weapon . |
event weaponSwitched(Player:entity, OldWeapon:entity, NewWeapon:entity) |
Runs when Player switches from OldWeapon to NewWeapon . |
event playerUse(Player:entity, Entity:entity) {
print(Player, "just used the prop", Entity)
}
This chip shows basic use of the chat event for chat commands.
@persist Owner:entity
Owner = owner()
event chat(Player:entity, Message:string, _:number) {
if (Player == Owner & Message[1] == "!") {
const Rest = Message:sub(2)
const Arguments = Rest:explode(" ")
switch (Arguments[1, string]) {
case "ping",
print("pong!")
break
default,
print("Unknown command: " + Arguments[1, string])
}
}
}
This chip detects any explosion damage to the chip and keeps track of it, and destroys itself if it takes too much damage.
@persist Health:number
Health = 1000
event entityDamage(Victim:entity, Damage:damage) {
if (Victim == entity()) { # Check if damaged prop was the chip
if (Damage:isType(_DMG_BLAST)) { # Only check for blast damage
Health -= Damage:getAmount() # Subtract health by damage amount
if (Health <= 0) {
selfDestruct() # Destroy chip, out of health
}
}
}
}
Please do not alter the e2 docs ...
pages manually.
They are autogenerated from the E2Helper. In the future, this will hopefully be its own dedicated website or tool.
Basic Features: core, debug, number, selfaware,
string, timer
🌎 World: angle, color, find, ranger, sound,
🔣 Math: bitwise, complex, matrix, quaternion, vector, vector2/4
📦 Entities: bone, constraint, egp, entity, hologram, npc
👨 Players: chat, console, player, weapon
📊 Data storage: array, files, globalvars, serialization, table
💬 Communication: datasignal, http, signal, wirelink,
❓ Informational: gametick, serverinfo, steamidconv, unitconv
Disabled by default: constraintcore, effects, propcore, remoteupload, wiring
Wire-Extras (repo): camera, ftrace, holoanim, light, stcontrol, tracesystem
- Home 🏠
- Syntax 🔣
- Directives 🎛️
- Editor 🖥️
- Events 🌟 (new!)
Click To Expand
- 🟥 SPU
- 🟥 Address Bus
- 🟥 Extended Bus
- 🟥 Plug/Socket
- 🟥 Port
- 🟥 Transfer Bus
- 🟩 GPU
- 🟥 Dynamic Memory
- 🟥 Flash EEPROM
- 🟥 ROM
- 🟧 Beacon Sensor
- 🟧 Locator
- 🟧 Target Finder
- 🟧 Waypoint
- 🟥 XYZ Beacon
- 🟩 CPU
- 🟩 Expression 2
- 🟩 Gates
- 🟥 PID
- 🟧 CD Disk
- 🟥 CD Ray
- 🟧 DHDD
- 🟥 Keycard
- 🟥 RAM-card
- 🟧 Satellite Dish
- 🟧 Store
- 🟧 Transferer
- 🟥 Wired Wirer
- 🟧 Adv Entity Marker
- 🟧 Damage Detector
- 🟧 Entity Marker
- 🟧 GPS
- 🟧 Gyroscope
- 🟥 HighSpeed Ranger
- 🟧 Laser Pointer Receiver
- 🟥 Microphone
- 🟧 Ranger
- 🟧 Speedometer
- 🟧 Water Sensor
- 🟧 7 Segment Display
- 🟥 Adv. Hud Indicator
- 🟧 Console Screen
- 🟧 Control Panel
- 🟧 Digital Screen
- 🟧 EGP v3
- 🟧 Fix RenderTargets
- 🟥 GPULib Switcher
- 🟧 Hud Indicator
- 🟧 Indicator
- 🟧 Lamp
- 🟧 Light
- 🟧 Oscilloscope
- 🟧 Pixel
- 🟧 Screen
- 🟧 Sound Emitter
- 🟧 Text Screen
- 🟩 Cam Controller
- 🟧 Colorer
- 🟧 FX Emitter
- 🟧 HighSpeed Holoemitter
- 🟧 HoloEmitter
- 🟧 HoloGrid
- 🟥 Interactable Holography Emitter
- 🟥 Materializer
- 🟥 Painter
- 🟧 Adv. Input
- 🟧 Button
- 🟧 Constant Value
- 🟥 Door Controller
- 🟧 Dual Input
- 🟧 Dynamic Button
- 🟧 Eye Pod
- 🟧 Graphics Tablet
- 🟧 Keyboard
- 🟥 Lever
- 🟧 Numpad
- 🟧 Numpad Input
- 🟧 Numpad Output
- 🟧 Plug
- 🟧 Pod Controller
- 🟧 Radio
- 🟧 Relay
- 🟧 Text Receiver
- 🟧 Two-way Radio
- 🟧 Vehicle Controller
- 🟥 Door
- 🟥 Adv. Dupe. Teleporter
- 🟥 Buoyancy
- 🟧 Clutch
- 🟧 Detonator
- 🟧 Explosives
- 🟧 Explosives (Simple)
- 🟥 Forcer
- 🟩 Freezer
- 🟧 Gimbal (Facer)
- 🟧 Grabber
- 🟧 Hoverball
- 🟧 Hoverdrive Controller
- 🟥 Hydraulic
- 🟧 Igniter
- 🟧 Nailer
- 🟩 Prop Spawner
- 🟥 Servo
- 🟥 Simple Servo
- 🟧 Thruster
- 🟥 Touchplate
- 🟥 Trail
- 🟩 Turret
- 🟩 User
- 🟥 Vector Thruster
- 🟥 Vehicle Exit Point
- 🟧 Weight (Adjustable)
- 🟧 Weld/Constraint Latch
- 🟥 Wheel
- 🟥 Wire Magnet
- 🟥 Wired Npc Controller
- 🟧 Debugger
- 🟥 GUI Wiring
- 🟥 Multi Wire
- 🟧 Namer
- 🟥 Simulate Data
- 🟩 Wiring
- 🟥 Beam Reader
- 🟥 Implanter
- 🟥 Reader
- 🟥 Target Filter
- 🟥 User Reader
Gates 🚥
Click To Expand
TBD