From c8d049061c6282912a96e88cf23f46b6f545fa25 Mon Sep 17 00:00:00 2001 From: Walace Date: Thu, 7 Nov 2024 09:03:18 -0300 Subject: [PATCH 1/2] Add to accept 4x4 lua table in setElementBoneMatrix function --- .../deathmatch/logic/luadefs/CLuaPedDefs.cpp | 39 +++++++++++++++++-- .../deathmatch/logic/luadefs/CLuaPedDefs.h | 2 +- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp index f38096dceea..aa573d8805f 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp @@ -1072,10 +1072,43 @@ std::variant> CLuaPedDefs::Get return std::make_tuple(x, y, z, w); } -bool CLuaPedDefs::SetElementBoneMatrix(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, CMatrix boneMatrix) +bool CLuaPedDefs::SetElementBoneMatrix(lua_State* const luaVM) { - CEntity* theEntity = entity->GetGameEntity(); - return theEntity ? theEntity->SetBoneMatrix(static_cast(boneId), boneMatrix) : false; + CClientEntity* entity = NULL; + std::uint32_t boneId; + CMatrix boneMatrix; + + CScriptArgReader argStream(luaVM); + argStream.ReadUserData(entity); + argStream.ReadNumber(boneId); + + if (argStream.NextIsTable()) + { + if (!ReadMatrix(luaVM, argStream.m_iIndex, boneMatrix)) + { + argStream.SetCustomError("Matrix is not 4 x 4"); + } + } + else + { + argStream.ReadMatrix(boneMatrix); + } + + if (!argStream.HasErrors()) + { + CEntity* theEntity = entity->GetGameEntity(); + + if (theEntity->SetBoneMatrix(static_cast(boneId), boneMatrix)) + { + lua_pushboolean(luaVM, true); + return true; + } + } + else + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + + lua_pushboolean(luaVM, false); + return false; } std::variant, 4>> CLuaPedDefs::GetElementBoneMatrix(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h index d97a484d8e1..79fa295f152 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h @@ -58,7 +58,7 @@ class CLuaPedDefs : public CLuaDefs static std::variant> GetElementBoneRotation(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId); static std::variant> GetElementBoneQuaternion(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId); - static bool SetElementBoneMatrix(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, CMatrix boneMatrix); + static bool SetElementBoneMatrix(lua_State* const luaVM); static std::variant, 4>> GetElementBoneMatrix(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId); From a48a63a8d76c60f30c87e811fc294428f3137331 Mon Sep 17 00:00:00 2001 From: Walace Date: Thu, 7 Nov 2024 09:47:40 -0300 Subject: [PATCH 2/2] Fix SetElementBoneMatrix argument parser --- Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp | 8 ++++---- Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp index aa573d8805f..e97a0ca1f67 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp @@ -37,7 +37,7 @@ void CLuaPedDefs::LoadFunctions() {"setElementBonePosition", ArgumentParser}, {"setElementBoneRotation", ArgumentParser}, {"setElementBoneQuaternion", ArgumentParser}, - {"setElementBoneMatrix", ArgumentParser}, + {"setElementBoneMatrix", SetElementBoneMatrix}, {"setPedRotation", SetPedRotation}, {"setPedWeaponSlot", SetPedWeaponSlot}, {"setPedCanBeKnockedOffBike", SetPedCanBeKnockedOffBike}, @@ -1072,7 +1072,7 @@ std::variant> CLuaPedDefs::Get return std::make_tuple(x, y, z, w); } -bool CLuaPedDefs::SetElementBoneMatrix(lua_State* const luaVM) +int CLuaPedDefs::SetElementBoneMatrix(lua_State* const luaVM) { CClientEntity* entity = NULL; std::uint32_t boneId; @@ -1101,14 +1101,14 @@ bool CLuaPedDefs::SetElementBoneMatrix(lua_State* const luaVM) if (theEntity->SetBoneMatrix(static_cast(boneId), boneMatrix)) { lua_pushboolean(luaVM, true); - return true; + return 1; } } else m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); lua_pushboolean(luaVM, false); - return false; + return 0; } std::variant, 4>> CLuaPedDefs::GetElementBoneMatrix(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h index 79fa295f152..20dbbe6faa7 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h @@ -58,8 +58,7 @@ class CLuaPedDefs : public CLuaDefs static std::variant> GetElementBoneRotation(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId); static std::variant> GetElementBoneQuaternion(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId); - static bool SetElementBoneMatrix(lua_State* const luaVM); - + LUA_DECLARE(SetElementBoneMatrix); static std::variant, 4>> GetElementBoneMatrix(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId); static bool UpdateElementRpHAnim(lua_State* const luaVM, CClientEntity* entity);