Skip to content

Commit dc27d47

Browse files
authored
Add setVehicleRespawnRotation function and tweaked OOP variants (#338)
This makes a very minor change to some undocumented behaviour: setRespawnPosition previously would set the rotation to 0,0,0 if you didn't provide the rotation. Now it doesn't change the rotation.
2 parents c5e78f6 + 66931c1 commit dc27d47

File tree

4 files changed

+69
-10
lines changed

4 files changed

+69
-10
lines changed

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6813,17 +6813,31 @@ bool CStaticFunctionDefinitions::GetVehicleRespawnPosition(CElement* pElement, C
68136813
return false;
68146814
}
68156815

6816-
bool CStaticFunctionDefinitions::SetVehicleRespawnPosition(CElement* pElement, const CVector& vecPosition, const CVector& vecRotation)
6816+
bool CStaticFunctionDefinitions::SetVehicleRespawnRotation(CElement* pElement, const CVector& vecRotation)
68176817
{
68186818
assert(pElement);
6819-
RUN_CHILDREN(SetVehicleRespawnPosition(*iter, vecPosition, vecRotation))
6819+
RUN_CHILDREN(SetVehicleRespawnRotation(*iter, vecRotation))
68206820

68216821
if (IS_VEHICLE(pElement))
68226822
{
68236823
CVehicle* pVehicle = static_cast<CVehicle*>(pElement);
6824+
pVehicle->SetRespawnRotationDegrees(vecRotation);
6825+
6826+
return true;
6827+
}
6828+
6829+
return false;
6830+
}
68246831

6832+
bool CStaticFunctionDefinitions::SetVehicleRespawnPosition(CElement* pElement, const CVector& vecPosition)
6833+
{
6834+
assert(pElement);
6835+
RUN_CHILDREN(SetVehicleRespawnPosition(*iter, vecPosition))
6836+
6837+
if (IS_VEHICLE(pElement))
6838+
{
6839+
CVehicle* pVehicle = static_cast<CVehicle*>(pElement);
68256840
pVehicle->SetRespawnPosition(vecPosition);
6826-
pVehicle->SetRespawnRotationDegrees(vecRotation);
68276841

68286842
return true;
68296843
}

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ class CStaticFunctionDefinitions
306306
static bool SetVehicleRespawnDelay(CElement* pElement, unsigned long ulTime);
307307
static bool GetVehicleRespawnPosition(CElement* pElement, CVector& vecPosition);
308308
static bool GetVehicleRespawnRotation(CElement* pElement, CVector& vecRotation);
309-
static bool SetVehicleRespawnPosition(CElement* pElement, const CVector& vecPosition, const CVector& vecRotation);
309+
static bool SetVehicleRespawnRotation(CElement* pElement, const CVector& vecRotation);
310+
static bool SetVehicleRespawnPosition(CElement* pElement, const CVector& vecPosition);
310311
static bool ToggleVehicleRespawn(CElement* pElement, bool bRespawn);
311312
static bool ResetVehicleExplosionTime(CElement* pElement);
312313
static bool ResetVehicleIdleTime(CElement* pElement);

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

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ void CLuaVehicleDefs::LoadFunctions()
8484
CLuaCFunctions::AddFunction("setVehicleRespawnDelay", SetVehicleRespawnDelay);
8585
CLuaCFunctions::AddFunction("setVehicleIdleRespawnDelay", SetVehicleIdleRespawnDelay);
8686
CLuaCFunctions::AddFunction("setVehicleRespawnPosition", SetVehicleRespawnPosition);
87+
CLuaCFunctions::AddFunction("setVehicleRespawnRotation", SetVehicleRespawnRotation);
8788
CLuaCFunctions::AddFunction("getVehicleRespawnPosition", GetVehicleRespawnPosition);
8889
CLuaCFunctions::AddFunction("getVehicleRespawnRotation", GetVehicleRespawnRotation);
8990
CLuaCFunctions::AddFunction("respawnVehicle", RespawnVehicle);
@@ -186,6 +187,8 @@ void CLuaVehicleDefs::AddClass(lua_State* luaVM)
186187
lua_classfunction(luaVM, "getWheelStates", "getVehicleWheelStates");
187188
lua_classfunction(luaVM, "getDoorOpenRatio", "getVehicleDoorOpenRatio");
188189
lua_classfunction(luaVM, "getHandling", "getVehicleHandling");
190+
lua_classfunction(luaVM, "getRespawnPosition", "getVehicleRespawnPosition");
191+
lua_classfunction(luaVM, "getRespawnRotation", "getVehicleRespawnRotation");
189192

190193
lua_classfunction(luaVM, "setColor", "setVehicleColor");
191194
lua_classfunction(luaVM, "setDamageProof", "setVehicleDamageProof");
@@ -202,6 +205,7 @@ void CLuaVehicleDefs::AddClass(lua_State* luaVM)
202205
lua_classfunction(luaVM, "setPanelState", "setVehiclePanelState");
203206
lua_classfunction(luaVM, "setRespawnDelay", "setVehicleRespawnDelay");
204207
lua_classfunction(luaVM, "setRespawnPosition", "setVehicleRespawnPosition");
208+
lua_classfunction(luaVM, "setRespawnRotation", "setVehicleRespawnRotation");
205209
lua_classfunction(luaVM, "setSirensOn", "setVehicleSirensOn");
206210
lua_classfunction(luaVM, "setTurretPosition", "setVehicleTurretPosition");
207211
lua_classfunction(luaVM, "setDoorOpenRatio", "setVehicleDoorOpenRatio");
@@ -251,7 +255,7 @@ void CLuaVehicleDefs::AddClass(lua_State* luaVM)
251255
lua_classvariable(luaVM, "idleRespawnDelay", "setVehicleIdleRespawnDelay", NULL);
252256
lua_classvariable(luaVM, "respawnDelay", "setVehicleRespawnDelay", NULL);
253257
lua_classvariable(luaVM, "respawnPosition", "setVehicleRespawnPosition", "getVehicleRespawnPosition", SetVehicleRespawnPosition, OOP_GetVehicleRespawnPosition);
254-
lua_classvariable(luaVM, "respawnRotation", NULL, "getVehicleRespawnRotation", NULL, OOP_GetVehicleRespawnRotation);
258+
lua_classvariable(luaVM, "respawnRotation", "setVehicleRespawnRotation", "getVehicleRespawnRotation", SetVehicleRespawnRotation, OOP_GetVehicleRespawnRotation);
255259
lua_classvariable(luaVM, "onGround", NULL, "isVehicleOnGround");
256260
lua_classvariable(luaVM, "name", NULL, "getVehicleName");
257261
lua_classvariable(luaVM, "vehicleType", NULL, "getVehicleType");
@@ -2299,6 +2303,47 @@ int CLuaVehicleDefs::GetVehicleRespawnRotation(lua_State* luaVM)
22992303
return 1;
23002304
}
23012305

2306+
int CLuaVehicleDefs::SetVehicleRespawnPosition(lua_State* luaVM)
2307+
{
2308+
CElement* pElement;
2309+
CVector vecPosition;
2310+
2311+
CScriptArgReader argStream(luaVM);
2312+
argStream.ReadUserData(pElement);
2313+
argStream.ReadVector3D(vecPosition);
2314+
2315+
if (argStream.NextIsVector3D())
2316+
{
2317+
CVector vecRotation;
2318+
argStream.ReadVector3D(vecRotation);
2319+
2320+
if (!argStream.HasErrors())
2321+
{
2322+
if (CStaticFunctionDefinitions::SetVehicleRespawnPosition(pElement, vecPosition) &&
2323+
CStaticFunctionDefinitions::SetVehicleRespawnRotation(pElement, vecRotation))
2324+
{
2325+
lua_pushboolean(luaVM, true);
2326+
return 1;
2327+
}
2328+
}
2329+
else
2330+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
2331+
}
2332+
else if (!argStream.HasErrors())
2333+
{
2334+
if (CStaticFunctionDefinitions::SetVehicleRespawnPosition(pElement, vecPosition))
2335+
{
2336+
lua_pushboolean(luaVM, true);
2337+
return 1;
2338+
}
2339+
}
2340+
else
2341+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
2342+
2343+
lua_pushboolean(luaVM, false);
2344+
return 1;
2345+
}
2346+
23022347
int CLuaVehicleDefs::GetVehicleRespawnPosition(lua_State* luaVM)
23032348
{
23042349
// float, float, float getVehicleRespawnPosition( vehicle theVehicle )
@@ -2326,20 +2371,18 @@ int CLuaVehicleDefs::GetVehicleRespawnPosition(lua_State* luaVM)
23262371
return 1;
23272372
}
23282373

2329-
int CLuaVehicleDefs::SetVehicleRespawnPosition(lua_State* luaVM)
2374+
int CLuaVehicleDefs::SetVehicleRespawnRotation(lua_State* luaVM)
23302375
{
23312376
CElement* pElement;
2332-
CVector vecPosition;
23332377
CVector vecRotation;
23342378

23352379
CScriptArgReader argStream(luaVM);
23362380
argStream.ReadUserData(pElement);
2337-
argStream.ReadVector3D(vecPosition);
2338-
argStream.ReadVector3D(vecRotation, CVector());
2381+
argStream.ReadVector3D(vecRotation);
23392382

23402383
if (!argStream.HasErrors())
23412384
{
2342-
if (CStaticFunctionDefinitions::SetVehicleRespawnPosition(pElement, vecPosition, vecRotation))
2385+
if (CStaticFunctionDefinitions::SetVehicleRespawnRotation(pElement, vecRotation))
23432386
{
23442387
lua_pushboolean(luaVM, true);
23452388
return 1;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class CLuaVehicleDefs : public CLuaDefs
9090
LUA_DECLARE(SetVehicleIdleRespawnDelay);
9191
LUA_DECLARE(SetVehicleRespawnDelay);
9292
LUA_DECLARE(SetVehicleRespawnPosition);
93+
LUA_DECLARE(SetVehicleRespawnRotation);
9394
LUA_DECLARE_OOP(GetVehicleRespawnPosition);
9495
LUA_DECLARE_OOP(GetVehicleRespawnRotation);
9596
LUA_DECLARE(ToggleVehicleRespawn);

0 commit comments

Comments
 (0)