Skip to content

Commit 71a78fa

Browse files
committed
Added OOP implementation for Vehicle.turnVelocity/Vehicle.setTurnVelocity
1 parent 0889e89 commit 71a78fa

File tree

5 files changed

+53
-4
lines changed

5 files changed

+53
-4
lines changed

MTA10/mods/shared_logic/lua/CLuaMain.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ void CLuaMain::AddVehicleClass ( lua_State* luaVM )
309309
lua_classfunction ( luaVM, "getAdjustableProperty", "getVehicleAdjustableProperty" );
310310
lua_classfunction ( luaVM, "getOverrideLights", "getVehicleOverrideLights" );
311311
lua_classfunction ( luaVM, "getPanelState", "getVehiclePanelState" );
312-
lua_classfunction ( luaVM, "getTurnVelocity", "getVehicleTurnVelocity" );
312+
lua_classfunction ( luaVM, "getTurnVelocity", CLuaOOPDefs::GetVehicleTurnVelocity );
313313
lua_classfunction ( luaVM, "isTaxiLightOn", "isVehicleTaxiLightOn" );
314314
lua_classfunction ( luaVM, "getComponents", "getVehicleComponents" );
315315
lua_classfunction ( luaVM, "getHeadLightColor", "getVehicleHeadLightColor" );
@@ -411,6 +411,7 @@ void CLuaMain::AddVehicleClass ( lua_State* luaVM )
411411
lua_classvariable ( luaVM, "nitroActivated", "setVehicleNitroActivated", "isVehicleNitroActivated" );
412412
lua_classvariable ( luaVM, "nitroRecharging", NULL, "isVehicleNitroRecharging" );
413413
lua_classvariable ( luaVM, "gravity", CLuaFunctionDefs::SetVehicleGravity, CLuaOOPDefs::GetVehicleGravity );
414+
lua_classvariable ( luaVM, "turnVelocity", CLuaFunctionDefs::SetVehicleTurnVelocity, CLuaOOPDefs::GetVehicleTurnVelocity );
414415

415416
//lua_classvariable ( luaVM, "color", CLuaFunctionDefs::SetVehicleColor, CLuaOOPDefs::GetVehicleColor );
416417
//lua_classvariable ( luaVM, "headlightColor", CLuaFunctionDefs::SetHeadLightColor, CLuaOOPDefs::GetHeadLightColor );

MTA10/mods/shared_logic/lua/oopdefs/CLuaOOPDefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class CLuaOOPDefs : public CLuaDefs
4343

4444
// Vehicle
4545
LUA_DECLARE ( GetVehicleGravity );
46+
LUA_DECLARE ( GetVehicleTurnVelocity );
4647

4748
// Marker
4849
LUA_DECLARE ( GetMarkerTarget );

MTA10/mods/shared_logic/lua/oopdefs/CLuaOOPFunctionDefs.Vehicle.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,26 @@ int CLuaOOPDefs::GetVehicleGravity ( lua_State* luaVM )
3131

3232
lua_pushboolean ( luaVM, false );
3333
return 1;
34-
}
34+
}
35+
36+
int CLuaOOPDefs::GetVehicleTurnVelocity ( lua_State* luaVM )
37+
{
38+
CClientVehicle* pVehicle;
39+
40+
CScriptArgReader argStream ( luaVM );
41+
argStream.ReadUserData ( pVehicle );
42+
43+
if ( !argStream.HasErrors () )
44+
{
45+
CVector vecTurnVelocity;
46+
pVehicle->GetTurnSpeed ( vecTurnVelocity );
47+
48+
lua_pushvector ( luaVM, vecTurnVelocity );
49+
return 1;
50+
}
51+
else
52+
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
53+
54+
lua_pushboolean ( luaVM, false );
55+
return 1;
56+
}

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ void CLuaVehicleDefs::AddClass ( lua_State* luaVM )
171171
lua_classfunction ( luaVM, "areSirensOn", "getVehicleSirensOn" );
172172
lua_classfunction ( luaVM, "getTowedByVehicle", "getVehicleTowedByVehicle" );
173173
lua_classfunction ( luaVM, "getTowingVehicle", "getVehicleTowingVehicle" );
174-
lua_classfunction ( luaVM, "getTurnVelocity", "getVehicleTurnVelocity" );
174+
lua_classfunction ( luaVM, "getTurnVelocity", "getVehicleTurnVelocity", CLuaVehicleDefs::OOP_GetVehicleTurnVelocity );
175175
lua_classfunction ( luaVM, "getTurretPosition", "getVehicleTurretPosition" );
176176
lua_classfunction ( luaVM, "getVehicleType", "getVehicleType" ); // This isn't "getType" because it would overwrite Element.getType
177177
lua_classfunction ( luaVM, "getUpgradeOnSlot", "getVehicleUpgradeOnSlot" );
@@ -235,7 +235,7 @@ void CLuaVehicleDefs::AddClass ( lua_State* luaVM )
235235
lua_classvariable ( luaVM, "maxPassengers", NULL, "getVehicleMaxPassengers" );
236236
lua_classvariable ( luaVM, "upgrades", NULL, "getVehicleUpgrades" );
237237
lua_classvariable ( luaVM, "turretPosition", "setVehicleTurretPosition", "getVehicleTurretPosition" );
238-
lua_classvariable ( luaVM, "turnVelocity", "setVehicleTurnVelocity", "getVehicleTurnVelocity" );
238+
lua_classvariable ( luaVM, "turnVelocity", "setVehicleTurnVelocity", "getVehicleTurnVelocity", SetVehicleTurnVelocity, OOP_GetVehicleTurnVelocity );
239239
lua_classvariable ( luaVM, "overrideLights", "setVehicleOverrideLights", "getVehicleOverrideLights" );
240240
lua_classvariable ( luaVM, "idleRespawnDelay", "setVehicleIdleRespawnDelay", NULL );
241241
lua_classvariable ( luaVM, "respawnDelay", "setVehicleRespawnDelay", NULL );
@@ -1039,6 +1039,30 @@ int CLuaVehicleDefs::GetVehicleTurnVelocity ( lua_State* luaVM )
10391039
}
10401040

10411041

1042+
int CLuaVehicleDefs::OOP_GetVehicleTurnVelocity ( lua_State* luaVM )
1043+
{
1044+
CVehicle* pVehicle;
1045+
1046+
CScriptArgReader argStream ( luaVM );
1047+
argStream.ReadUserData ( pVehicle );
1048+
1049+
if ( !argStream.HasErrors () )
1050+
{
1051+
CVector vecTurnVelocity;
1052+
if ( CStaticFunctionDefinitions::GetVehicleTurnVelocity ( pVehicle, vecTurnVelocity ) )
1053+
{
1054+
lua_pushvector ( luaVM, vecTurnVelocity );
1055+
return 1;
1056+
}
1057+
}
1058+
else
1059+
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
1060+
1061+
lua_pushboolean ( luaVM, false );
1062+
return 1;
1063+
}
1064+
1065+
10421066
int CLuaVehicleDefs::GetVehicleTurretPosition ( lua_State* luaVM )
10431067
{
10441068
CVehicle* pVehicle;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class CLuaVehicleDefs : public CLuaDefs
3636
LUA_DECLARE ( GetVehicleRotation );
3737
LUA_DECLARE ( GetVehicleSirensOn );
3838
LUA_DECLARE ( GetVehicleTurnVelocity );
39+
LUA_DECLARE ( OOP_GetVehicleTurnVelocity );
3940
LUA_DECLARE ( GetVehicleTurretPosition );
4041
LUA_DECLARE ( IsVehicleLocked );
4142
LUA_DECLARE ( GetVehiclesOfType );

0 commit comments

Comments
 (0)