diff --git a/USAGE.md b/USAGE.md index e2799ac..e6f7797 100644 --- a/USAGE.md +++ b/USAGE.md @@ -117,6 +117,7 @@ These special debug commands start with `!` and are custom to Kawari. * `!invis: Toggles the hidden GM invisibility mode on or off for your character.` * `!unlockaetheryte `: Unlock an aetheryte. For the first parameter, the literal words are required. * `!teri `: Changes to the specified territory. +* `!finishevent`: Forcefully finishes the current event, useful if the script has an error and you're stuck talking to something. ### GM commands diff --git a/resources/scripts/Global.lua b/resources/scripts/Global.lua index b112ce4..1067423 100644 --- a/resources/scripts/Global.lua +++ b/resources/scripts/Global.lua @@ -212,7 +212,6 @@ registerCommand("setspeed", "commands/debug/SetSpeed.lua") registerCommand("nudge", "commands/debug/Nudge.lua") registerCommand("festival", "commands/debug/Festival.lua") registerCommand("permtest", "commands/debug/PermissionTest.lua") -registerCommand("reload", "commands/debug/Reload.lua") registerCommand("unlockaction", "commands/debug/UnlockAction.lua") registerCommand("wireframe", "commands/debug/ToggleWireframe.lua") registerCommand("invis", "commands/debug/ToggleInvisibility.lua") diff --git a/resources/scripts/commands/debug/Reload.lua b/resources/scripts/commands/debug/Reload.lua deleted file mode 100644 index 6c69111..0000000 --- a/resources/scripts/commands/debug/Reload.lua +++ /dev/null @@ -1,6 +0,0 @@ -required_rank = GM_RANK_DEBUG - -function onCommand(args, player) - player:reload_scripts() - player:send_message("Scripts reloaded!") -end diff --git a/src/world/chat_handler.rs b/src/world/chat_handler.rs index 0ed6fd9..34a1ac2 100644 --- a/src/world/chat_handler.rs +++ b/src/world/chat_handler.rs @@ -70,6 +70,18 @@ impl ChatHandler { connection.send_inventory(true).await; } + "!reload" => { + connection.reload_scripts(); + connection.send_message("Scripts reloaded!").await; + } + "!finishevent" => { + if let Some(event) = &connection.event { + connection.event_finish(event.id).await; + connection + .send_message("Current event forcefully finished.") + .await; + } + } _ => {} } } diff --git a/src/world/connection.rs b/src/world/connection.rs index cfb226c..634c13b 100644 --- a/src/world/connection.rs +++ b/src/world/connection.rs @@ -625,10 +625,7 @@ impl ZoneConnection { self.warp_aetheryte(*aetheryte_id).await; } Task::ReloadScripts => { - let mut lua = self.lua.lock().unwrap(); - if let Err(err) = load_global_script(&mut lua) { - tracing::warn!("Failed to load Global.lua: {:?}", err); - } + self.reload_scripts(); } Task::ToggleInvisibility { invisible } => { self.toggle_invisibility(*invisible).await; @@ -638,6 +635,14 @@ impl ZoneConnection { player.queued_tasks.clear(); } + /// Reloads Global.lua + pub fn reload_scripts(&mut self) { + let mut lua = self.lua.lock().unwrap(); + if let Err(err) = load_global_script(&mut lua) { + tracing::warn!("Failed to load Global.lua: {:?}", err); + } + } + pub async fn event_finish(&mut self, handler_id: u32) { // sent event finish { diff --git a/src/world/event.rs b/src/world/event.rs index 913116b..0bfc142 100644 --- a/src/world/event.rs +++ b/src/world/event.rs @@ -5,8 +5,9 @@ use crate::{common::ObjectTypeId, config::get_config}; use super::{LuaPlayer, Zone}; pub struct Event { - file_name: String, + pub file_name: String, lua: Lua, + pub id: u32, } impl Event { @@ -22,12 +23,12 @@ impl Event { .exec() { tracing::warn!("Syntax error in {}: {:?}", file_name, err); - return Self { file_name, lua }; + return Self { file_name, lua, id }; } lua.globals().set("EVENT_ID", id).unwrap(); - Self { file_name, lua } + Self { file_name, lua, id } } pub fn enter_territory(&mut self, player: &mut LuaPlayer, zone: &Zone) {