@@ -35,10 +35,10 @@ void CLuaPedDefs::LoadFunctions()
3535 {" givePedWeapon" , GivePedWeapon},
3636
3737 {" setPedVoice" , SetPedVoice},
38- {" setElementBonePosition" , ArgumentParser< SetElementBonePosition>},
39- {" setElementBoneRotation" , ArgumentParser< SetElementBoneRotation>},
40- {" setElementBoneQuaternion" , ArgumentParser< SetElementBoneQuaternion>},
41- {" setElementBoneMatrix" , ArgumentParser< SetElementBoneMatrix>},
38+ {" setElementBonePosition" , ArgumentParserWarn< false , SetElementBonePosition>},
39+ {" setElementBoneRotation" , ArgumentParserWarn< false , SetElementBoneRotation>},
40+ {" setElementBoneQuaternion" , ArgumentParserWarn< false , SetElementBoneQuaternion>},
41+ {" setElementBoneMatrix" , ArgumentParserWarn< false , SetElementBoneMatrix>},
4242 {" setPedRotation" , SetPedRotation},
4343 {" setPedWeaponSlot" , SetPedWeaponSlot},
4444 {" setPedCanBeKnockedOffBike" , SetPedCanBeKnockedOffBike},
@@ -65,10 +65,10 @@ void CLuaPedDefs::LoadFunctions()
6565 {" playPedVoiceLine" , ArgumentParser<PlayPedVoiceLine>},
6666
6767 {" getPedVoice" , GetPedVoice},
68- {" getElementBonePosition" , ArgumentParser< GetElementBonePosition>},
69- {" getElementBoneRotation" , ArgumentParser< GetElementBoneRotation>},
70- {" getElementBoneQuaternion" , ArgumentParser< GetElementBoneQuaternion>},
71- {" getElementBoneMatrix" , ArgumentParser< GetElementBoneMatrix>},
68+ {" getElementBonePosition" , ArgumentParserWarn< false , GetElementBonePosition>},
69+ {" getElementBoneRotation" , ArgumentParserWarn< false , GetElementBoneRotation>},
70+ {" getElementBoneQuaternion" , ArgumentParserWarn< false , GetElementBoneQuaternion>},
71+ {" getElementBoneMatrix" , ArgumentParserWarn< false , GetElementBoneMatrix>},
7272 {" getPedRotation" , GetPedRotation},
7373 {" getPedWeaponSlot" , GetPedWeaponSlot},
7474 {" canPedBeKnockedOffBike" , CanPedBeKnockedOffBike},
@@ -995,110 +995,147 @@ int CLuaPedDefs::CanPedBeKnockedOffBike(lua_State* luaVM)
995995 return 1 ;
996996}
997997
998- bool CLuaPedDefs::SetElementBonePosition (lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, CVector position )
998+ std::variant< bool , CLuaMultiReturn< float , float , float >> CLuaPedDefs::GetElementBonePosition ( CClientPed* ped, const std::uint16_t bone )
999999{
1000- CEntity* theEntity = entity->GetGameEntity ();
1001- if (!theEntity)
1000+ if (bone < BONE_ROOT || bone > BONE_LEFTBREAST)
1001+ throw std::invalid_argument (" Invalid bone: " + std::to_string (bone));
1002+
1003+ CEntity* entity = ped->GetGameEntity ();
1004+ CVector position;
1005+
1006+ if (!entity || !entity->GetBonePosition (static_cast <eBone>(bone), position))
10021007 return false ;
1003- return theEntity->SetBonePosition (static_cast <eBone>(boneId), position);
1008+
1009+ return CLuaMultiReturn<float , float , float >(position.fX , position.fY , position.fZ );
10041010}
10051011
1006- bool CLuaPedDefs::SetElementBoneRotation (lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, float yaw, float pitch, float roll )
1012+ std::variant< bool , CLuaMultiReturn< float , float , float >> CLuaPedDefs::GetElementBoneRotation ( CClientPed* ped, const std::uint16_t bone )
10071013{
1008- if (boneId > BONE_RIGHTFOOT )
1009- throw LuaFunctionError (" Invalid bone ID " , false );
1014+ if (bone < BONE_ROOT || bone > BONE_LEFTBREAST )
1015+ throw std::invalid_argument (" Invalid bone: " + std::to_string (bone) );
10101016
1011- CEntity* theEntity = entity->GetGameEntity ();
1012- if (!theEntity)
1017+ CEntity* entity = ped->GetGameEntity ();
1018+ float yaw = 0 .0f ;
1019+ float pitch = 0 .0f ;
1020+ float roll = 0 .0f ;
1021+
1022+ if (!entity || !entity->GetBoneRotation (static_cast <eBone>(bone), yaw, pitch, roll))
10131023 return false ;
1014- return theEntity->SetBoneRotation (static_cast <eBone>(boneId), yaw, pitch, roll);
1024+
1025+ return CLuaMultiReturn<float , float , float >(yaw, pitch, roll);
10151026}
10161027
1017- bool CLuaPedDefs::SetElementBoneQuaternion (lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, float x , float y , float z, float w )
1028+ std::variant< bool , CLuaMultiReturn< float , float , float , float >> CLuaPedDefs::GetElementBoneQuaternion (CClientPed* ped, const std:: uint16_t bone )
10181029{
1019- if (boneId > BONE_RIGHTFOOT)
1020- throw LuaFunctionError (" Invalid bone ID" , false );
1030+ if (bone < BONE_ROOT || bone > BONE_LEFTBREAST)
1031+ throw std::invalid_argument (" Invalid bone: " + std::to_string (bone));
1032+
1033+ CEntity* entity = ped->GetGameEntity ();
1034+ float x = 0 .0f ;
1035+ float y = 0 .0f ;
1036+ float z = 0 .0f ;
1037+ float w = 0 .0f ;
10211038
1022- CEntity* theEntity = entity->GetGameEntity ();
1023- return theEntity ? theEntity->SetBoneRotationQuat (static_cast <eBone>(boneId), x, y, z, w) : false ;
1039+ if (!entity || !entity->GetBoneRotationQuat (static_cast <eBone>(bone), x, y, z, w))
1040+ return false ;
1041+
1042+ return CLuaMultiReturn<float , float , float , float >(x, y, z, w);
10241043}
10251044
1026- std::variant<bool , CLuaMultiReturn< float , float , float >> CLuaPedDefs::GetElementBonePosition (lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId )
1045+ std::variant<bool , std::array<std::array< float , 4 >, 4 >> CLuaPedDefs::GetElementBoneMatrix ( CClientPed* ped, const std::uint16_t bone )
10271046{
1028- CEntity* theEntity = entity->GetGameEntity ();
1029- CVector position;
1030- if (!theEntity || !theEntity->GetBonePosition (static_cast <eBone>(boneId), position))
1047+ if (bone < BONE_ROOT || bone > BONE_LEFTBREAST)
1048+ throw std::invalid_argument (" Invalid bone: " + std::to_string (bone));
1049+
1050+ CEntity* entity = ped->GetGameEntity ();
1051+
1052+ if (!entity)
10311053 return false ;
10321054
1033- return std::make_tuple (position.fX , position.fY , position.fZ );
1055+ RwMatrix* rwmatrix = entity->GetBoneRwMatrix (static_cast <eBone>(bone));
1056+
1057+ if (!rwmatrix)
1058+ return false ;
1059+
1060+ CMatrix matrix;
1061+
1062+ g_pGame->GetRenderWare ()->RwMatrixToCMatrix (*rwmatrix, matrix);
1063+
1064+ return matrix.To4x4Array ();
10341065}
10351066
1036- std::variant< bool , CLuaMultiReturn< float , float , float >> CLuaPedDefs::GetElementBoneRotation (lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId )
1067+ bool CLuaPedDefs::SetElementBonePosition ( CClientPed* ped, const std::uint16_t bone, const CVector position )
10371068{
1038- if (boneId > BONE_RIGHTFOOT)
1039- throw LuaFunctionError (" Invalid bone ID" , false );
1069+ if (bone < BONE_ROOT || bone > BONE_LEFTBREAST)
1070+ throw std::invalid_argument (" Invalid bone: " + std::to_string (bone));
1071+
1072+ CEntity* entity = ped->GetGameEntity ();
10401073
1041- float yaw = 0 .0f , pitch = 0 .0f , roll = 0 .0f ;
1042- CEntity* theEntity = entity->GetGameEntity ();
1043- if (!theEntity || !theEntity->GetBoneRotation (static_cast <eBone>(boneId), yaw, pitch, roll))
1074+ if (!entity)
10441075 return false ;
10451076
1046- return std::make_tuple (yaw, pitch, roll );
1077+ return entity-> SetBonePosition ( static_cast <eBone>(bone), position );
10471078}
10481079
1049- std::variant< bool , CLuaMultiReturn< float , float , float , float >> CLuaPedDefs::GetElementBoneQuaternion (lua_State* const luaVM, CClientPed* entity, std:: uint32_t boneId )
1080+ bool CLuaPedDefs::SetElementBoneRotation (CClientPed* ped, const std:: uint16_t bone, const float yaw, const float pitch, const float roll )
10501081{
1051- if (boneId > BONE_RIGHTFOOT )
1052- throw LuaFunctionError (" Invalid bone ID " , false );
1082+ if (bone < BONE_ROOT || bone > BONE_LEFTBREAST )
1083+ throw std::invalid_argument (" Invalid bone: " + std::to_string (bone) );
10531084
1054- float x = 0 . 0f , y = 0 . 0f , z = 0 . 0f , w = 0 . 0f ;
1055- CEntity* theEntity = entity-> GetGameEntity ();
1056- if (!theEntity || !theEntity-> GetBoneRotationQuat ( static_cast <eBone>(boneId), x, y, z, w) )
1085+ CEntity* entity = ped-> GetGameEntity () ;
1086+
1087+ if (!entity )
10571088 return false ;
10581089
1059- return std::make_tuple (x, y, z, w );
1090+ return entity-> SetBoneRotation ( static_cast <eBone>(bone), yaw, pitch, roll );
10601091}
10611092
1062- bool CLuaPedDefs::SetElementBoneMatrix (lua_State* const luaVM, CClientPed* entity, std:: uint32_t boneId, CMatrix boneMatrix )
1093+ bool CLuaPedDefs::SetElementBoneQuaternion (CClientPed* ped, const std:: uint16_t bone, const float x, const float y, const float z, const float w )
10631094{
1064- CEntity* theEntity = entity->GetGameEntity ();
1065- return theEntity ? theEntity->SetBoneMatrix (static_cast <eBone>(boneId), boneMatrix) : false ;
1095+ if (bone < BONE_ROOT || bone > BONE_LEFTBREAST)
1096+ throw std::invalid_argument (" Invalid bone: " + std::to_string (bone));
1097+
1098+ CEntity* entity = ped->GetGameEntity ();
1099+
1100+ if (!entity)
1101+ return false ;
1102+
1103+ return entity->SetBoneRotationQuat (static_cast <eBone>(bone), x, y, z, w);
10661104}
10671105
1068- std::variant< bool , std::array<std::array< float , 4 >, 4 >> CLuaPedDefs::GetElementBoneMatrix (lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId )
1106+ bool CLuaPedDefs::SetElementBoneMatrix ( CClientPed* ped, const std::uint16_t bone, const CMatrix matrix )
10691107{
1070- CEntity* theEntity = entity->GetGameEntity ();
1071- if (theEntity)
1072- {
1073- RwMatrix* boneRwMatrix = theEntity->GetBoneRwMatrix (static_cast <eBone>(boneId));
1074- if (boneRwMatrix)
1075- {
1076- CMatrix matrix;
1077- g_pGame->GetRenderWare ()->RwMatrixToCMatrix (*boneRwMatrix, matrix);
1078- return matrix.To4x4Array ();
1079- }
1080- }
1081- return false ;
1108+ if (bone < BONE_ROOT || bone > BONE_LEFTBREAST)
1109+ throw std::invalid_argument (" Invalid bone: " + std::to_string (bone));
1110+
1111+ CEntity* entity = ped->GetGameEntity ();
1112+
1113+ if (!entity)
1114+ return false ;
1115+
1116+ return entity->SetBoneMatrix (static_cast <eBone>(bone), matrix);
10821117}
10831118
1084- bool CLuaPedDefs::UpdateElementRpHAnim (lua_State* const luaVM, CClientEntity* entity )
1119+ bool CLuaPedDefs::UpdateElementRpHAnim (CClientPed* ped )
10851120{
1086- CEntity* theEntity = entity->GetGameEntity ();
1087- if (theEntity)
1088- {
1089- theEntity->UpdateRpHAnim ();
1121+ CEntity* entity = ped->GetGameEntity ();
10901122
1091- if (theEntity->GetModelIndex () == 0 ) // CJ skin
1092- {
1093- RpClump* clump = theEntity->GetRpClump ();
1094- if (clump)
1095- {
1096- ((void (__cdecl*)(RpClump*))0x5DF560 )(clump); // CPed::ShoulderBoneRotation
1097- }
1098- }
1123+ if (!entity)
1124+ return false ;
1125+
1126+ entity->UpdateRpHAnim ();
1127+
1128+ if (entity->GetModelIndex () != 0 )
10991129 return true ;
1130+
1131+ RpClump* clump = entity->GetRpClump ();
1132+
1133+ if (clump)
1134+ {
1135+ ((void (__cdecl*)(RpClump*))0x5DF560 )(clump); // CPed::ShoulderBoneRotation
11001136 }
1101- return false ;
1137+
1138+ return true ;
11021139}
11031140
11041141int CLuaPedDefs::GetPedBonePosition (lua_State* luaVM)
0 commit comments