Skip to content

Commit fc8f39e

Browse files
committed
Optionally return multiple numbers instead of vectors in Vehicle.setComponentPosition/Rotation
Also applied to Element.getBoundingBox
1 parent c24b118 commit fc8f39e

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,9 +1035,24 @@ int CLuaElementDefs::OOP_GetElementBoundingBox(lua_State* luaVM)
10351035
CVector vecMin, vecMax;
10361036
if (CStaticFunctionDefinitions::GetElementBoundingBox(*pEntity, vecMin, vecMax))
10371037
{
1038-
lua_pushvector(luaVM, vecMin);
1039-
lua_pushvector(luaVM, vecMax);
1040-
return 2;
1038+
// If the caller expects six results, return six floats, otherwise two vectors
1039+
int iExpected = lua_ncallresult(luaVM);
1040+
if (iExpected == 6)
1041+
{
1042+
lua_pushnumber(luaVM, vecMin.fX);
1043+
lua_pushnumber(luaVM, vecMin.fY);
1044+
lua_pushnumber(luaVM, vecMin.fZ);
1045+
lua_pushnumber(luaVM, vecMax.fX);
1046+
lua_pushnumber(luaVM, vecMax.fY);
1047+
lua_pushnumber(luaVM, vecMax.fZ);
1048+
return 6;
1049+
}
1050+
else
1051+
{
1052+
lua_pushvector(luaVM, vecMin);
1053+
lua_pushvector(luaVM, vecMax);
1054+
return 2;
1055+
}
10411056
}
10421057
}
10431058
else

Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3236,8 +3236,21 @@ int CLuaVehicleDefs::OOP_GetVehicleComponentPosition(lua_State* luaVM)
32363236
CVector vecPosition;
32373237
if (pVehicle->GetComponentPosition(strComponent, vecPosition, outputBase))
32383238
{
3239-
lua_pushvector(luaVM, vecPosition);
3240-
return 1;
3239+
// If the caller expects three results, return 3 floats, otherwise a vector
3240+
int iExpected = lua_ncallresult(luaVM);
3241+
if (iExpected == 3)
3242+
{
3243+
lua_pushnumber(luaVM, vecPosition.fX);
3244+
lua_pushnumber(luaVM, vecPosition.fY);
3245+
lua_pushnumber(luaVM, vecPosition.fZ);
3246+
return 3;
3247+
}
3248+
else
3249+
{
3250+
lua_pushvector(luaVM, vecPosition);
3251+
return 1;
3252+
}
3253+
32413254
}
32423255
}
32433256
else
@@ -3327,8 +3340,20 @@ int CLuaVehicleDefs::OOP_GetVehicleComponentRotation(lua_State* luaVM)
33273340
{
33283341
// Script uses degrees
33293342
ConvertRadiansToDegrees(vecRotation);
3330-
lua_pushvector(luaVM, vecRotation);
3331-
return 1;
3343+
// If the caller expects three results, return 3 floats, otherwise a vector
3344+
int iExpected = lua_ncallresult(luaVM);
3345+
if (iExpected == 3)
3346+
{
3347+
lua_pushnumber(luaVM, vecRotation.fX);
3348+
lua_pushnumber(luaVM, vecRotation.fY);
3349+
lua_pushnumber(luaVM, vecRotation.fZ);
3350+
return 3;
3351+
}
3352+
else
3353+
{
3354+
lua_pushvector(luaVM, vecRotation);
3355+
return 1;
3356+
}
33323357
}
33333358
}
33343359
else

0 commit comments

Comments
 (0)