Skip to content

Commit ee0858e

Browse files
committed
Return vectors for vehicles component funcs (fixes mantis 9507)
1 parent 5a90830 commit ee0858e

File tree

2 files changed

+62
-5
lines changed

2 files changed

+62
-5
lines changed

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

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@ void CLuaVehicleDefs::AddClass ( lua_State* luaVM )
189189
lua_classfunction ( luaVM, "getSirenParams", "getVehicleSirenParams" );
190190
lua_classfunction ( luaVM, "getSirens", "getVehicleSirens" );
191191
lua_classfunction ( luaVM, "getSirensOn", "getVehicleSirensOn" );
192-
lua_classfunction ( luaVM, "getComponentPosition", "getVehicleComponentPosition" );
192+
lua_classfunction ( luaVM, "getComponentPosition", OOP_GetVehicleComponentPosition );
193193
lua_classfunction ( luaVM, "getComponentVisible", "getVehicleComponentVisible" );
194-
lua_classfunction ( luaVM, "getComponentRotation", "getVehicleComponentRotation" );
194+
lua_classfunction ( luaVM, "getComponentRotation", OOP_GetVehicleComponentRotation );
195195
lua_classfunction ( luaVM, "getUpgrades", "getVehicleUpgrades" );
196196
lua_classfunction ( luaVM, "getUpgradeSlotName", "getVehicleUpgradeSlotName" );
197197
lua_classfunction ( luaVM, "getCompatibleUpgrades", "getVehicleCompatibleUpgrades" );
@@ -3040,7 +3040,6 @@ int CLuaVehicleDefs::SetVehicleComponentPosition ( lua_State* luaVM )
30403040
return 1;
30413041
}
30423042

3043-
30443043
int CLuaVehicleDefs::GetVehicleComponentPosition ( lua_State* luaVM )
30453044
{
30463045
// float, float, float getVehicleComponentPosition ( vehicle theVehicle, string theComponent [, string base = "root"] )
@@ -3071,6 +3070,34 @@ int CLuaVehicleDefs::GetVehicleComponentPosition ( lua_State* luaVM )
30713070
return 1;
30723071
}
30733072

3073+
int CLuaVehicleDefs::OOP_GetVehicleComponentPosition ( lua_State* luaVM )
3074+
{
3075+
// float, float, float getVehicleComponentPosition ( vehicle theVehicle, string theComponent [, string base = "root"] )
3076+
SString strComponent;
3077+
CClientVehicle * pVehicle = NULL;
3078+
EComponentBaseType outputBase;
3079+
3080+
CScriptArgReader argStream ( luaVM );
3081+
argStream.ReadUserData ( pVehicle );
3082+
argStream.ReadString ( strComponent );
3083+
argStream.ReadEnumString ( outputBase, EComponentBase::ROOT );
3084+
3085+
if ( !argStream.HasErrors () )
3086+
{
3087+
CVector vecPosition;
3088+
if ( pVehicle->GetComponentPosition ( strComponent, vecPosition, outputBase ) )
3089+
{
3090+
lua_pushvector ( luaVM, vecPosition );
3091+
return 1;
3092+
}
3093+
}
3094+
else
3095+
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
3096+
3097+
lua_pushboolean ( luaVM, false );
3098+
return 1;
3099+
}
3100+
30743101
int CLuaVehicleDefs::SetVehicleComponentRotation ( lua_State* luaVM )
30753102
{
30763103
// bool setVehicleComponentRotation ( vehicle theVehicle, string theComponent, float rotX, float rotY, float rotZ [, string base = "parent"] )
@@ -3132,6 +3159,36 @@ int CLuaVehicleDefs::GetVehicleComponentRotation ( lua_State* luaVM )
31323159
return 1;
31333160
}
31343161

3162+
int CLuaVehicleDefs::OOP_GetVehicleComponentRotation ( lua_State* luaVM )
3163+
{
3164+
// float, float, float getVehicleComponentRotation ( vehicle theVehicle, string theComponent [, string base = "parent"] )
3165+
SString strComponent;
3166+
CClientVehicle * pVehicle = NULL;
3167+
EComponentBaseType outputBase;
3168+
3169+
CScriptArgReader argStream ( luaVM );
3170+
argStream.ReadUserData ( pVehicle );
3171+
argStream.ReadString ( strComponent );
3172+
argStream.ReadEnumString ( outputBase, EComponentBase::PARENT );
3173+
3174+
if ( !argStream.HasErrors () )
3175+
{
3176+
CVector vecRotation;
3177+
if ( pVehicle->GetComponentRotation ( strComponent, vecRotation, outputBase ) )
3178+
{
3179+
// Script uses degrees
3180+
ConvertRadiansToDegrees ( vecRotation );
3181+
lua_pushvector ( luaVM, vecRotation );
3182+
return 1;
3183+
}
3184+
}
3185+
else
3186+
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
3187+
3188+
lua_pushboolean ( luaVM, false );
3189+
return 1;
3190+
}
3191+
31353192
int CLuaVehicleDefs::ResetVehicleComponentPosition ( lua_State* luaVM )
31363193
{
31373194
CScriptArgReader argStream ( luaVM );

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ class CLuaVehicleDefs : public CLuaDefs
136136

137137
// Components
138138
LUA_DECLARE ( SetVehicleComponentPosition );
139-
LUA_DECLARE ( GetVehicleComponentPosition );
139+
LUA_DECLARE_OOP ( GetVehicleComponentPosition );
140140
LUA_DECLARE ( SetVehicleComponentRotation );
141-
LUA_DECLARE ( GetVehicleComponentRotation );
141+
LUA_DECLARE_OOP ( GetVehicleComponentRotation );
142142
LUA_DECLARE ( ResetVehicleComponentPosition );
143143
LUA_DECLARE ( ResetVehicleComponentRotation );
144144
LUA_DECLARE ( SetVehicleComponentVisible );

0 commit comments

Comments
 (0)