From f4d349070c99443cdf5f4607047a48093804c32b Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Tue, 24 Oct 2023 13:51:12 -0500 Subject: [PATCH 1/3] Add isTeleportingEnabled and setTeleportingEnabled --- apps/openmw/mwlua/types/player.cpp | 13 +++++++++++++ files/lua_api/openmw/types.lua | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwlua/types/player.cpp b/apps/openmw/mwlua/types/player.cpp index ab15385f08e..52170f70758 100644 --- a/apps/openmw/mwlua/types/player.cpp +++ b/apps/openmw/mwlua/types/player.cpp @@ -138,6 +138,19 @@ namespace MWLua throw std::runtime_error("The argument must be a player."); return input->getControlSwitch(key); }; + player["isTeleportingEnabled"] = [](const Object& player) -> bool { + if (player.ptr() != MWBase::Environment::get().getWorld()->getPlayerPtr()) + throw std::runtime_error("The argument must be a player."); + return MWBase::Environment::get().getWorld()->isTeleportingEnabled(); + }; + player["setTeleportingEnabled"] = [context](const Object& player, bool state) { + if (player.ptr() != MWBase::Environment::get().getWorld()->getPlayerPtr()) + throw std::runtime_error("The argument must be a player."); + if (dynamic_cast(&player) && !dynamic_cast(&player)) + throw std::runtime_error("Only player and global scripts can toggle teleportation."); + context.mLuaManager->addAction([state] { MWBase::Environment::get().getWorld()->enableTeleporting(state); }, + "toggleTeleportingAction"); + }; player["setControlSwitch"] = [input](const Object& player, std::string_view key, bool v) { if (player.ptr() != MWBase::Environment::get().getWorld()->getPlayerPtr()) throw std::runtime_error("The argument must be a player."); diff --git a/files/lua_api/openmw/types.lua b/files/lua_api/openmw/types.lua index c65a7323cbf..3df689ce0e2 100644 --- a/files/lua_api/openmw/types.lua +++ b/files/lua_api/openmw/types.lua @@ -919,13 +919,26 @@ -- @function [parent=#Player] getCrimeLevel -- @param openmw.core#GameObject player -- @return #number - + --- -- Whether the character generation for this player is finished. -- @function [parent=#Player] isCharGenFinished -- @param openmw.core#GameObject player -- @return #boolean +--- +-- Whether teleportation for this player is enabled. +-- @function [parent=#Player] isTeleportingEnabled +-- @param openmw.core#GameObject player +-- @param #boolean player +-- @return #boolean + +--- +-- Enables or disables teleportation for this player. +-- @function [parent=#Player] setTeleportingEnabled +-- @param openmw.core#GameObject player +-- @param #boolean state True to enable teleporting, false to disable. + --- -- Returns a list containing quests @{#PlayerQuest} for the specified player, indexed by quest ID. -- @function [parent=#Player] quests From 3e31142c0bba38f0f116d43e9c28f371ffa753f9 Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Wed, 25 Oct 2023 17:24:18 -0500 Subject: [PATCH 2/3] Remove lua action --- apps/openmw/mwlua/types/player.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/openmw/mwlua/types/player.cpp b/apps/openmw/mwlua/types/player.cpp index 52170f70758..fc4c9858cc1 100644 --- a/apps/openmw/mwlua/types/player.cpp +++ b/apps/openmw/mwlua/types/player.cpp @@ -148,8 +148,7 @@ namespace MWLua throw std::runtime_error("The argument must be a player."); if (dynamic_cast(&player) && !dynamic_cast(&player)) throw std::runtime_error("Only player and global scripts can toggle teleportation."); - context.mLuaManager->addAction([state] { MWBase::Environment::get().getWorld()->enableTeleporting(state); }, - "toggleTeleportingAction"); + MWBase::Environment::get().getWorld()->enableTeleporting(state); }; player["setControlSwitch"] = [input](const Object& player, std::string_view key, bool v) { if (player.ptr() != MWBase::Environment::get().getWorld()->getPlayerPtr()) From 6a671186ee1089cde407c422d7c27471a2f88a81 Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Thu, 26 Oct 2023 11:50:50 -0500 Subject: [PATCH 3/3] Removed unused var --- apps/openmw/mwlua/types/player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwlua/types/player.cpp b/apps/openmw/mwlua/types/player.cpp index fc4c9858cc1..cef0753817c 100644 --- a/apps/openmw/mwlua/types/player.cpp +++ b/apps/openmw/mwlua/types/player.cpp @@ -143,7 +143,7 @@ namespace MWLua throw std::runtime_error("The argument must be a player."); return MWBase::Environment::get().getWorld()->isTeleportingEnabled(); }; - player["setTeleportingEnabled"] = [context](const Object& player, bool state) { + player["setTeleportingEnabled"] = [](const Object& player, bool state) { if (player.ptr() != MWBase::Environment::get().getWorld()->getPlayerPtr()) throw std::runtime_error("The argument must be a player."); if (dynamic_cast(&player) && !dynamic_cast(&player))