From e237cbe84dcd6079d61a8f3fe724dcbf0f6ade7e Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Mon, 5 May 2025 23:30:36 -0400 Subject: [PATCH] Create GenericWarp script to handle simple warps It turns out that most warps are just a yes/no, and can be handled by one single script. I scripted the lift attendants from Bulwark Hall <-> Airship Landing <-> Drowning Wench this way. --- resources/scripts/Global.lua | 13 +++++++++---- .../LimsaInnDoor.lua => common/GenericWarp.lua} | 8 ++------ resources/scripts/custom/000/cmndefinnbed_00020.lua | 3 +++ resources/scripts/opening/OpeningGridania.lua | 3 --- resources/scripts/opening/OpeningLimsaLominsa.lua | 3 --- resources/scripts/opening/OpeningUldah.lua | 3 --- resources/scripts/warp/WarpInnGridania.lua | 3 --- resources/scripts/warp/WarpInnLimsaLominsa.lua | 3 --- src/bin/kawari-world.rs | 2 +- src/world/chat_handler.rs | 6 +++--- src/world/event.rs | 4 +++- 11 files changed, 21 insertions(+), 30 deletions(-) rename resources/scripts/{tosort/LimsaInnDoor.lua => common/GenericWarp.lua} (50%) diff --git a/resources/scripts/Global.lua b/resources/scripts/Global.lua index c4090ad..c9959e2 100644 --- a/resources/scripts/Global.lua +++ b/resources/scripts/Global.lua @@ -3,6 +3,8 @@ function onBeginLogin(player) player:send_message("Welcome to Kawari!") end +-- please keep these ids sorted! + -- Actions registerAction(3, "actions/Sprint.lua") registerAction(9, "actions/FastBlade.lua") @@ -11,10 +13,13 @@ registerAction(9, "actions/FastBlade.lua") registerAction(6221, "items/Fantasia.lua") -- Events +registerEvent(131078, "warp/WarpInnGridania.lua") +registerEvent(131079, "warp/WarpInnLimsaLominsa.lua") +registerEvent(131082, "common/GenericWarp.lua") +registerEvent(131092, "common/GenericWarp.lua") +registerEvent(131093, "common/GenericWarp.lua") +registerEvent(131094, "common/GenericWarp.lua") +registerEvent(720916, "custom/000/cmndefinnbed_00020.lua") registerEvent(1245185, "opening/OpeningLimsaLominsa.lua") registerEvent(1245186, "opening/OpeningGridania.lua") registerEvent(1245187, "opening/OpeningUldah.lua") -registerEvent(131078, "warp/WarpInnGridania.lua") -registerEvent(131079, "warp/WarpInnLimsaLominsa.lua") -registerEvent(131082, "tosort/LimsaInnDoor.lua") -registerEvent(720916, "custom/000/cmndefinnbed_00020.lua") diff --git a/resources/scripts/tosort/LimsaInnDoor.lua b/resources/scripts/common/GenericWarp.lua similarity index 50% rename from resources/scripts/tosort/LimsaInnDoor.lua rename to resources/scripts/common/GenericWarp.lua index d4b9be2..5ff175e 100644 --- a/resources/scripts/tosort/LimsaInnDoor.lua +++ b/resources/scripts/common/GenericWarp.lua @@ -1,10 +1,6 @@ ---- TODO: find a way to hardcode it this way -EVENT_ID = 131082 - --- TODO: it seems that these all might share one common function, and the only difference is the event id +-- generic warp, use this for most warps that are just a yes/no option function onTalk(target, player) - --- prompt to exit the inn player:play_scene(target, EVENT_ID, 00000, 8192, 0) end @@ -13,6 +9,6 @@ function onReturn(scene, results, player) if results[1] == 1 then -- get warp - player:warp(EVENT_ID) + player:warp(EVENT_ID) end end diff --git a/resources/scripts/custom/000/cmndefinnbed_00020.lua b/resources/scripts/custom/000/cmndefinnbed_00020.lua index 9b123de..071974a 100644 --- a/resources/scripts/custom/000/cmndefinnbed_00020.lua +++ b/resources/scripts/custom/000/cmndefinnbed_00020.lua @@ -28,6 +28,9 @@ function onReturn(scene, results, player) player:finish_event(EVENT_ID) elseif scene == 1 then -- sleep anim + -- play log out scene + player:play_scene(player.id, EVENT_ID, 2, 8192, 0) + elseif scene == 2 then -- log out player:finish_event(EVENT_ID) end end diff --git a/resources/scripts/opening/OpeningGridania.lua b/resources/scripts/opening/OpeningGridania.lua index 2baa625..b451f46 100644 --- a/resources/scripts/opening/OpeningGridania.lua +++ b/resources/scripts/opening/OpeningGridania.lua @@ -1,6 +1,3 @@ ---- TODO: find a way to hardcode it this way -EVENT_ID = 1245186 - --- load defines from Opening Excel sheet, which has this and we don't need to hardcode it' POS_START = 2299848 diff --git a/resources/scripts/opening/OpeningLimsaLominsa.lua b/resources/scripts/opening/OpeningLimsaLominsa.lua index c029462..9601594 100644 --- a/resources/scripts/opening/OpeningLimsaLominsa.lua +++ b/resources/scripts/opening/OpeningLimsaLominsa.lua @@ -1,6 +1,3 @@ ---- TODO: find a way to hardcode it this way -EVENT_ID = 1245185 - --- load defines from Opening Excel sheet, which has this and we don't need to hardcode it' POS_START = 4101800 diff --git a/resources/scripts/opening/OpeningUldah.lua b/resources/scripts/opening/OpeningUldah.lua index ef33e2b..c20ae92 100644 --- a/resources/scripts/opening/OpeningUldah.lua +++ b/resources/scripts/opening/OpeningUldah.lua @@ -1,6 +1,3 @@ ---- TODO: find a way to hardcode it this way -EVENT_ID = 1245187 - --- load defines from Opening Excel sheet, which has this and we don't need to hardcode it' POS_START = 4101669 diff --git a/resources/scripts/warp/WarpInnGridania.lua b/resources/scripts/warp/WarpInnGridania.lua index d5bd580..b63a6d3 100644 --- a/resources/scripts/warp/WarpInnGridania.lua +++ b/resources/scripts/warp/WarpInnGridania.lua @@ -1,6 +1,3 @@ ---- TODO: find a way to hardcode it this way -EVENT_ID = 131079 -- TODO: wrong, i was testing in limsa - function onTalk(actorId, player) -- has inn access -- player:play_scene(131079, 00001, 1, 0) diff --git a/resources/scripts/warp/WarpInnLimsaLominsa.lua b/resources/scripts/warp/WarpInnLimsaLominsa.lua index e1df407..0a196c1 100644 --- a/resources/scripts/warp/WarpInnLimsaLominsa.lua +++ b/resources/scripts/warp/WarpInnLimsaLominsa.lua @@ -1,6 +1,3 @@ ---- TODO: find a way to hardcode it this way -EVENT_ID = 131079 - function onTalk(target, player) -- has inn access player:play_scene(target, EVENT_ID, 00001, 8192, 0) diff --git a/src/bin/kawari-world.rs b/src/bin/kawari-world.rs index 8f68687..c3a1081 100644 --- a/src/bin/kawari-world.rs +++ b/src/bin/kawari-world.rs @@ -733,7 +733,7 @@ async fn client_loop( if let Some(event_script) = state.event_scripts.get(event_id) { - connection.event = Some(Event::new(&event_script)); + connection.event = Some(Event::new(*event_id, &event_script)); connection .event .as_mut() diff --git a/src/world/chat_handler.rs b/src/world/chat_handler.rs index 64fc805..59171cd 100644 --- a/src/world/chat_handler.rs +++ b/src/world/chat_handler.rs @@ -301,9 +301,9 @@ impl ChatHandler { } let event = match event_id { - 1245185 => Event::new("opening/OpeningLimsaLominsa.lua"), - 1245186 => Event::new("opening/OpeningGridania.lua"), - 1245187 => Event::new("opening/OpeningUldah.lua"), + 1245185 => Event::new(1245185, "opening/OpeningLimsaLominsa.lua"), + 1245186 => Event::new(1245186, "opening/OpeningGridania.lua"), + 1245187 => Event::new(1245187, "opening/OpeningUldah.lua"), _ => panic!("Unsupported event!"), }; diff --git a/src/world/event.rs b/src/world/event.rs index 3bb8bb0..8d2a9a0 100644 --- a/src/world/event.rs +++ b/src/world/event.rs @@ -9,7 +9,7 @@ pub struct Event { } impl Event { - pub fn new(path: &str) -> Self { + pub fn new(id: u32, path: &str) -> Self { let lua = Lua::new(); let config = get_config(); @@ -19,6 +19,8 @@ impl Event { .exec() .unwrap(); + lua.globals().set("EVENT_ID", id).unwrap(); + Self { lua } }