S&box Wiki

Revision Difference

EventSystem#530564

<cat>Code.Misc</cat> <title>Event System</title> The event system is like the Hook system in Garry's Mod. It allows you to register functions on classes to receive a callback on certain global events. # Registering a callback Adding an `[Event]` attribute will add it to the list to be called. ``` [Event( "server.tick" )] public void MyCallback() { // will get called every server tick } ``` # Current Engine Events The various events called from the engine currently: * `client.disconnect` - called from `GameLoop.ClientDisconnected` * `frame` - called from `GameLoop.PreRender` * `client.tick` `server.tick` `tick` - tick is always called, client/server are appropriate to their state * `physics.step` - called from `GameLoop.PostPhysicsStep` * `client.hotloaded` - called from `HotloadManager.DoSwap`⤶ # Custom Events You can call your own events. ``` Event.Run( "gameover" ) ```