diff --git a/docs/hooks.md b/docs/hooks.md index 34b11792..91b6b757 100644 --- a/docs/hooks.md +++ b/docs/hooks.md @@ -1,14 +1,14 @@ # List of available hooks: - - `ctx.hook.on_world_initialized()` - - `ctx.hook.on_world_update()` - - `ctx.hook.on_world_update_client()` - - `ctx.hook.on_world_update_host()` - - `ctx.hook.on_new_player_seen(new_playerdata, player_count)` - called the first time player with this peer_id has entered the world - - `ctx.hook.on_local_player_spawn(my_player)` + - `ctx.hook.on_world_initialized()` - called on OnWorldInitialized. + - `ctx.hook.on_world_update()` - called on OnWorldPreUpdate. + - `ctx.hook.on_world_update_client()` - called on OnWorldPreUpdate, but only on clients. + - `ctx.hook.on_world_update_host()` - called on OnWorldPreUpdate, but only on host. + - `ctx.hook.on_new_player_seen(new_playerdata, player_count)` - called the first time player with this peer_id has entered the world. + - `ctx.hook.on_local_player_spawn(my_player)` - called when the *local* gets spawned. `my_player` is playerdata table for this player. - `ctx.hook.on_client_spawned(peer_id, new_playerdata)` - - `ctx.hook.on_should_send_updates()` - called either when we connect, or somebody else connects (and sends "welcome" message) + - `ctx.hook.on_should_send_updates()` - called either when we connect, or somebody else connects (and sends "welcome" message). - `ctx.hook.on_draw_debug_window(imgui)` - `ctx.hook.on_local_player_polymorphed(currently_polymorphed)` - `ctx.hook.on_client_polymorphed(peer_id, player_data)` - - `ctx.hook.on_late_init()` + - `ctx.hook.on_late_init()` - called on OnModPostInit. diff --git a/ew_api_example/compatibility.xml b/ew_api_example/compatibility.xml new file mode 100755 index 00000000..0433079e --- /dev/null +++ b/ew_api_example/compatibility.xml @@ -0,0 +1,4 @@ + + \ No newline at end of file diff --git a/ew_api_example/init.lua b/ew_api_example/init.lua new file mode 100644 index 00000000..c79d70c3 --- /dev/null +++ b/ew_api_example/init.lua @@ -0,0 +1,3 @@ +if ModIsEnabled("quant.ew") then + ModLuaFileAppend("mods/quant.ew/files/api/extra_modules.lua", "mods/ew_api_example/module.lua") +end diff --git a/ew_api_example/mod.xml b/ew_api_example/mod.xml new file mode 100755 index 00000000..6e59468c --- /dev/null +++ b/ew_api_example/mod.xml @@ -0,0 +1,9 @@ + + diff --git a/ew_api_example/module.lua b/ew_api_example/module.lua new file mode 100644 index 00000000..d21f6647 --- /dev/null +++ b/ew_api_example/module.lua @@ -0,0 +1,9 @@ +local module = {} + +function module.on_world_update() + if GameGetFrameNum() % 60 == 0 then + GamePrint("Hi from api example!") + end +end + +return module diff --git a/quant.ew/files/api/extra_modules.lua b/quant.ew/files/api/extra_modules.lua new file mode 100644 index 00000000..b4264f20 --- /dev/null +++ b/quant.ew/files/api/extra_modules.lua @@ -0,0 +1,4 @@ +-- All files that get LuaAppended here before OnModInit happens get run as modules. +-- Every module should return a table of functions (can be empty). +-- Functions starting with `on_` are called hooks. They will get called when relevant. +-- See docs/hooks.md for a list of all hooks. diff --git a/quant.ew/init.lua b/quant.ew/init.lua index 9068d508..1f264b01 100755 --- a/quant.ew/init.lua +++ b/quant.ew/init.lua @@ -119,6 +119,13 @@ local function load_modules() ctx.load_system("wand_charm") end +local function load_extra_modules() + print("Starting to load extra stuff") + for _, file in ipairs(ModLuaFileGetAppends("mods/quant.ew/files/api/extra_modules.lua")) do + ctx.dofile_and_add_hooks(file) + end +end + local function is_suitable_target(entity) return EntityGetIsAlive(entity) and not EntityHasTag(entity,"ew_notplayer") end @@ -410,8 +417,9 @@ function OnModPreInit() print("Entangled worlds init ok") end -function OnModInit() end - +function OnModInit() + load_extra_modules() +end function OnModPostInit() ctx.hook.on_late_init()