TylerH Posted December 13, 2009 Share Posted December 13, 2009 File Name: Hook System File Submitter: TylerH File Submitted: 13 Dec 2009 File Category: Lua Scripts This is a relatively simple hook system, a near duplicate of the functionality offered in Garry's Mod. The API is rather simple: GetHooks - Returns the entire table of hooks Add(event_name, name, func) - Adds your callback function with the unique name to be called under event_name. Remove(event_name, name) - Removes your previously set callback with the name from event_name Call(event_name, ...) - Triggers all callbacks for the given event_name, passing the arguements ... (any that you want). Will also return any return values. Here is a simple example: In your entity, module, whatever: function DrawMy****() DrawRect(50,50,500,500) DrawText("Cake",0,60) end hook.Add("HUDPaint","MyEntity_DrawMy****", DrawMy****) In your fpscontroller.lua: require('hook') ... while ... RenderWorld() hook.Call("HUDPaint") Flip() end Pretty easy...works for everything from core functionality up to high level game logic. People in Garry's Mod really abuse this system, yet it is somehow rather fast. Click here to download this file Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
Rick Posted December 13, 2009 Share Posted December 13, 2009 This is cool, but it's not all inclusive to an object. I think it would be better if Josh created a Draw2D() function for each object just like Update() & Spawn() so we don't have to mess around with the fpscontroller.lua file at all. Quote Link to comment Share on other sites More sharing options...
Niosop Posted December 13, 2009 Share Posted December 13, 2009 Cool, thanks Quote Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
TylerH Posted December 13, 2009 Author Share Posted December 13, 2009 This is cool, but it's not all inclusive to an object. I think it would be better if Josh created a Draw2D() function for each object just like Update() & Spawn() so we don't have to mess around with the fpscontroller.lua file at all. That seems a bit too specialized. Then you will have people who want an UpdateMatrix, Render, Draw2D, Draw3D, UpdatePhysics, OnCulled, OnCollision, all kinds of callbacks. It is better if people can implement things theirselves. I think the simplest set of callbacks for an entity would be: Pre-Update Pre-Draw Post-Update Post-Draw Then you can use them for whatever you want. Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
Rick Posted December 13, 2009 Share Posted December 13, 2009 There is already in a Collision() callback. I don't think drawing 2D is specialized. Every engine needs to be able to draw 2D and since in LE we have to do it at a specific location in the loop, it should expose a callback for it to lua so our entities can handle it. Quote Link to comment Share on other sites More sharing options...
TylerH Posted December 13, 2009 Author Share Posted December 13, 2009 I don't disagree, I am just saying that a system to allow us to setup our own callbacks, however many, would be the best solution, though I guess that isn't easily doable since we can't play around in the engine (source) itself. Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.