@@ -35,10 +35,10 @@ void CLuaPedDefs::LoadFunctions()
35
35
{" givePedWeapon" , GivePedWeapon},
36
36
37
37
{" 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>},
42
42
{" setPedRotation" , SetPedRotation},
43
43
{" setPedWeaponSlot" , SetPedWeaponSlot},
44
44
{" setPedCanBeKnockedOffBike" , SetPedCanBeKnockedOffBike},
@@ -65,10 +65,10 @@ void CLuaPedDefs::LoadFunctions()
65
65
{" playPedVoiceLine" , ArgumentParser<PlayPedVoiceLine>},
66
66
67
67
{" 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>},
72
72
{" getPedRotation" , GetPedRotation},
73
73
{" getPedWeaponSlot" , GetPedWeaponSlot},
74
74
{" canPedBeKnockedOffBike" , CanPedBeKnockedOffBike},
@@ -995,110 +995,147 @@ int CLuaPedDefs::CanPedBeKnockedOffBike(lua_State* luaVM)
995
995
return 1 ;
996
996
}
997
997
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 )
999
999
{
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))
1002
1007
return false ;
1003
- return theEntity->SetBonePosition (static_cast <eBone>(boneId), position);
1008
+
1009
+ return CLuaMultiReturn<float , float , float >(position.fX , position.fY , position.fZ );
1004
1010
}
1005
1011
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 )
1007
1013
{
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) );
1010
1016
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))
1013
1023
return false ;
1014
- return theEntity->SetBoneRotation (static_cast <eBone>(boneId), yaw, pitch, roll);
1024
+
1025
+ return CLuaMultiReturn<float , float , float >(yaw, pitch, roll);
1015
1026
}
1016
1027
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 )
1018
1029
{
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 ;
1021
1038
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);
1024
1043
}
1025
1044
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 )
1027
1046
{
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)
1031
1053
return false ;
1032
1054
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 ();
1034
1065
}
1035
1066
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 )
1037
1068
{
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 ();
1040
1073
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)
1044
1075
return false ;
1045
1076
1046
- return std::make_tuple (yaw, pitch, roll );
1077
+ return entity-> SetBonePosition ( static_cast <eBone>(bone), position );
1047
1078
}
1048
1079
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 )
1050
1081
{
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) );
1053
1084
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 )
1057
1088
return false ;
1058
1089
1059
- return std::make_tuple (x, y, z, w );
1090
+ return entity-> SetBoneRotation ( static_cast <eBone>(bone), yaw, pitch, roll );
1060
1091
}
1061
1092
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 )
1063
1094
{
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);
1066
1104
}
1067
1105
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 )
1069
1107
{
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);
1082
1117
}
1083
1118
1084
- bool CLuaPedDefs::UpdateElementRpHAnim (lua_State* const luaVM, CClientEntity* entity )
1119
+ bool CLuaPedDefs::UpdateElementRpHAnim (CClientPed* ped )
1085
1120
{
1086
- CEntity* theEntity = entity->GetGameEntity ();
1087
- if (theEntity)
1088
- {
1089
- theEntity->UpdateRpHAnim ();
1121
+ CEntity* entity = ped->GetGameEntity ();
1090
1122
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 )
1099
1129
return true ;
1130
+
1131
+ RpClump* clump = entity->GetRpClump ();
1132
+
1133
+ if (clump)
1134
+ {
1135
+ ((void (__cdecl*)(RpClump*))0x5DF560 )(clump); // CPed::ShoulderBoneRotation
1100
1136
}
1101
- return false ;
1137
+
1138
+ return true ;
1102
1139
}
1103
1140
1104
1141
int CLuaPedDefs::GetPedBonePosition (lua_State* luaVM)
0 commit comments