quote: So I installed the sample mod but it doesn't have any "Gadgets" folder. I'm assuming I copy the source code directory structure so I made \LuaRules\Gadgets under the mode name folder (LuaRules is at the same level as Units). |
Yes.
quote: If that's correct then I just need to create my lua file and stick it in there, right? |
Yes.
quote: How does the engine know when to call the method I will write? |
Events. For starters look at other gadgets' code, specifically search for methods defined in `gadget:`. For example in `unit_cannot_damage_unit.lua` you can see the method is called `gadget:UnitPreDamaged` which is the event for when unit is damaged.
quote: Is there a mod 3example that creates widgets? |
I assume by "mod" you mean a client-side piece of code and by "widgets" you mean GUI panels (unfortunately, in the Spring engine world, "widget" is the term for "clientside mod" as originally they were meant for GUI panels, but have since evolved to do various other tasks, for example automating unit orders).
I don't think there are any tutorial examples for those but you can look through the widgets provided in the game repository, this contains almost the entire default ZK GUI. Check out `LuaUI/Widgets`, especially the ones with names `gui_chili_*.lua` as Chili is our framework for working with GUI panels. These are also event based, like gadgets.