Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void CLuaPedDefs::LoadFunctions()
{"setElementBonePosition", ArgumentParser<SetElementBonePosition>},
{"setElementBoneRotation", ArgumentParser<SetElementBoneRotation>},
{"setElementBoneQuaternion", ArgumentParser<SetElementBoneQuaternion>},
{"setElementBoneMatrix", ArgumentParser<SetElementBoneMatrix>},
{"setElementBoneMatrix", SetElementBoneMatrix},
{"setPedRotation", SetPedRotation},
{"setPedWeaponSlot", SetPedWeaponSlot},
{"setPedCanBeKnockedOffBike", SetPedCanBeKnockedOffBike},
Expand Down Expand Up @@ -1072,10 +1072,43 @@ std::variant<bool, CLuaMultiReturn<float, float, float, float>> 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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just implement that "CMatrix" can be read from 4x4 lua table and don't touch this file at all

int CLuaPedDefs::SetElementBoneMatrix(lua_State* const luaVM)
{
CEntity* theEntity = entity->GetGameEntity();
return theEntity ? theEntity->SetBoneMatrix(static_cast<eBone>(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<eBone>(boneId), boneMatrix))
{
lua_pushboolean(luaVM, true);
return 1;
}
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

lua_pushboolean(luaVM, false);
return 0;
}

std::variant<bool, std::array<std::array<float, 4>, 4>> CLuaPedDefs::GetElementBoneMatrix(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId)
Expand Down
3 changes: 1 addition & 2 deletions Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ class CLuaPedDefs : public CLuaDefs
static std::variant<bool, CLuaMultiReturn<float, float, float>> GetElementBoneRotation(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId);
static std::variant<bool, CLuaMultiReturn<float, float, float, float>> 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);

LUA_DECLARE(SetElementBoneMatrix);
static std::variant<bool, std::array<std::array<float, 4>, 4>> GetElementBoneMatrix(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId);

static bool UpdateElementRpHAnim(lua_State* const luaVM, CClientEntity* entity);
Expand Down
Loading