From 87dc3cd0e827998aaa49232f658fc53bf0256f5d Mon Sep 17 00:00:00 2001 From: Nova Date: Thu, 13 Nov 2025 14:45:49 -0500 Subject: [PATCH] Enforced local scripts can only modify self. Updated documentation to use self and player in examples. --- apps/openmw/mwlua/types/npc.cpp | 3 +++ files/lua_api/openmw/types.lua | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwlua/types/npc.cpp b/apps/openmw/mwlua/types/npc.cpp index 83e51c1b89..f2d78610eb 100644 --- a/apps/openmw/mwlua/types/npc.cpp +++ b/apps/openmw/mwlua/types/npc.cpp @@ -248,6 +248,9 @@ namespace MWLua }; npc["setWerewolf"] = [context](const Object& obj, bool werewolf) -> void { + if (dynamic_cast(&obj) && !dynamic_cast(&obj)) + throw std::runtime_error("Local scripts can modify only self"); + const MWWorld::Ptr& ptr = obj.ptr(); if (!ptr.getClass().isNpc()) throw std::runtime_error("NPC or Player expected"); diff --git a/files/lua_api/openmw/types.lua b/files/lua_api/openmw/types.lua index b5c57f289e..ff07f8dce3 100644 --- a/files/lua_api/openmw/types.lua +++ b/files/lua_api/openmw/types.lua @@ -1095,9 +1095,9 @@ -- @param openmw.core#GameObject actor The NPC or player to transform -- @param #boolean werewolf True to transform into werewolf, false to transform back to normal -- @usage -- Transform player into werewolf in a global script --- types.NPC.setWerewolf(player, true) +-- player.type.setWerewolf(player, true) -- @usage -- Transform self back to normal in a local script --- types.NPC.setWerewolf(self, false) +-- self.type.setWerewolf(self, false) --- -- Returns the read-only @{#NpcRecord} of an NPC