Skip to content

Commit c5ef506

Browse files
znvjderqaisjp
authored andcommitted
Add new functions getVehicleRespawnPosition/Rotation (#334)
1 parent 424560d commit c5ef506

File tree

5 files changed

+140
-3
lines changed

5 files changed

+140
-3
lines changed

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6698,6 +6698,34 @@ bool CStaticFunctionDefinitions::SetVehicleIdleRespawnDelay(CElement* pElement,
66986698
return false;
66996699
}
67006700

6701+
bool CStaticFunctionDefinitions::GetVehicleRespawnRotation(CElement* pElement, CVector& vecRotation)
6702+
{
6703+
assert(pElement);
6704+
6705+
if (IS_VEHICLE(pElement))
6706+
{
6707+
CVehicle* pVehicle = static_cast<CVehicle*>(pElement);
6708+
vecRotation = pVehicle->GetRespawnRotationDegrees();
6709+
6710+
return true;
6711+
}
6712+
return false;
6713+
}
6714+
6715+
bool CStaticFunctionDefinitions::GetVehicleRespawnPosition(CElement* pElement, CVector& vecPosition)
6716+
{
6717+
assert(pElement);
6718+
6719+
if (IS_VEHICLE(pElement))
6720+
{
6721+
CVehicle* pVehicle = static_cast<CVehicle*>(pElement);
6722+
vecPosition = pVehicle->GetRespawnPosition();
6723+
6724+
return true;
6725+
}
6726+
return false;
6727+
}
6728+
67016729
bool CStaticFunctionDefinitions::SetVehicleRespawnPosition(CElement* pElement, const CVector& vecPosition, const CVector& vecRotation)
67026730
{
67036731
assert(pElement);

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ class CStaticFunctionDefinitions
301301
static bool SetVehiclePanelState(CElement* pElement, unsigned char ucPanel, unsigned char ucState);
302302
static bool SetVehicleIdleRespawnDelay(CElement* pElement, unsigned long ulTime);
303303
static bool SetVehicleRespawnDelay(CElement* pElement, unsigned long ulTime);
304+
static bool GetVehicleRespawnPosition(CElement* pElement, CVector& vecPosition);
305+
static bool GetVehicleRespawnRotation(CElement* pElement, CVector& vecRotation);
304306
static bool SetVehicleRespawnPosition(CElement* pElement, const CVector& vecPosition, const CVector& vecRotation);
305307
static bool ToggleVehicleRespawn(CElement* pElement, bool bRespawn);
306308
static bool ResetVehicleExplosionTime(CElement* pElement);

Server/mods/deathmatch/logic/CVehicle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ class CVehicle : public CElement
308308

309309
// Functions used to remember where this vehicle spawns
310310
const CVector& GetRespawnPosition(void) { return m_vecRespawnPosition; };
311+
const CVector& GetRespawnRotationDegrees(void) { return m_vecRespawnRotationDegrees; };
311312
void SetRespawnPosition(const CVector& vecPosition) { m_vecRespawnPosition = vecPosition; };
312-
void GetRespawnRotationDegrees(CVector& vecRotation) { vecRotation = m_vecRespawnRotationDegrees; };
313313
void SetRespawnRotationDegrees(const CVector& vecRotation) { m_vecRespawnRotationDegrees = vecRotation; };
314314
float GetRespawnHealth(void) { return m_fRespawnHealth; };
315315
void SetRespawnHealth(float fHealth) { m_fRespawnHealth = fHealth; };

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

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ void CLuaVehicleDefs::LoadFunctions()
8484
CLuaCFunctions::AddFunction("setVehicleRespawnDelay", SetVehicleRespawnDelay);
8585
CLuaCFunctions::AddFunction("setVehicleIdleRespawnDelay", SetVehicleIdleRespawnDelay);
8686
CLuaCFunctions::AddFunction("setVehicleRespawnPosition", SetVehicleRespawnPosition);
87+
CLuaCFunctions::AddFunction("getVehicleRespawnPosition", GetVehicleRespawnPosition);
88+
CLuaCFunctions::AddFunction("getVehicleRespawnRotation", GetVehicleRespawnRotation);
8789
CLuaCFunctions::AddFunction("respawnVehicle", RespawnVehicle);
8890
CLuaCFunctions::AddFunction("resetVehicleExplosionTime", ResetVehicleExplosionTime);
8991
CLuaCFunctions::AddFunction("resetVehicleIdleTime", ResetVehicleIdleTime);
@@ -248,7 +250,8 @@ void CLuaVehicleDefs::AddClass(lua_State* luaVM)
248250
lua_classvariable(luaVM, "overrideLights", "setVehicleOverrideLights", "getVehicleOverrideLights");
249251
lua_classvariable(luaVM, "idleRespawnDelay", "setVehicleIdleRespawnDelay", NULL);
250252
lua_classvariable(luaVM, "respawnDelay", "setVehicleRespawnDelay", NULL);
251-
lua_classvariable(luaVM, "respawnPosition", "setVehicleRespawnPosition", NULL);
253+
lua_classvariable(luaVM, "respawnPosition", "setVehicleRespawnPosition", "getVehicleRespawnPosition", SetVehicleRespawnPosition, OOP_GetVehicleRespawnPosition);
254+
lua_classvariable(luaVM, "respawnRotation", NULL, "getVehicleRespawnRotation", NULL, OOP_GetVehicleRespawnRotation);
252255
lua_classvariable(luaVM, "onGround", NULL, "isVehicleOnGround");
253256
lua_classvariable(luaVM, "name", NULL, "getVehicleName");
254257
lua_classvariable(luaVM, "vehicleType", NULL, "getVehicleType");
@@ -2221,6 +2224,108 @@ int CLuaVehicleDefs::SetVehicleRespawnDelay(lua_State* luaVM)
22212224
return 1;
22222225
}
22232226

2227+
int CLuaVehicleDefs::OOP_GetVehicleRespawnRotation(lua_State* luaVM)
2228+
{
2229+
CElement* pElement = NULL;
2230+
2231+
CScriptArgReader argStream(luaVM);
2232+
argStream.ReadUserData(pElement);
2233+
2234+
if (!argStream.HasErrors())
2235+
{
2236+
CVector vecRotationDegress;
2237+
if (CStaticFunctionDefinitions::GetVehicleRespawnRotation(pElement, vecRotationDegress))
2238+
{
2239+
lua_pushvector(luaVM, vecRotationDegress);
2240+
2241+
return 1;
2242+
}
2243+
}
2244+
else
2245+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
2246+
2247+
lua_pushboolean(luaVM, false);
2248+
return 1;
2249+
}
2250+
2251+
int CLuaVehicleDefs::OOP_GetVehicleRespawnPosition(lua_State* luaVM)
2252+
{
2253+
CElement* pElement = NULL;
2254+
2255+
CScriptArgReader argStream(luaVM);
2256+
argStream.ReadUserData(pElement);
2257+
2258+
if (!argStream.HasErrors())
2259+
{
2260+
CVector vecPosition;
2261+
if (CStaticFunctionDefinitions::GetVehicleRespawnPosition(pElement, vecPosition))
2262+
{
2263+
lua_pushvector(luaVM, vecPosition);
2264+
2265+
return 1;
2266+
}
2267+
}
2268+
else
2269+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
2270+
2271+
lua_pushboolean(luaVM, false);
2272+
return 1;
2273+
}
2274+
2275+
int CLuaVehicleDefs::GetVehicleRespawnRotation(lua_State* luaVM)
2276+
{
2277+
// float, float, float getVehicleRespawnRotation( vehicle theVehicle )
2278+
CElement* pElement = NULL;
2279+
2280+
CScriptArgReader argStream(luaVM);
2281+
argStream.ReadUserData(pElement);
2282+
2283+
if (!argStream.HasErrors())
2284+
{
2285+
CVector vecRotationDegress;
2286+
if (CStaticFunctionDefinitions::GetVehicleRespawnRotation(pElement, vecRotationDegress))
2287+
{
2288+
lua_pushnumber(luaVM, vecRotationDegress.fX);
2289+
lua_pushnumber(luaVM, vecRotationDegress.fY);
2290+
lua_pushnumber(luaVM, vecRotationDegress.fZ);
2291+
2292+
return 3;
2293+
}
2294+
}
2295+
else
2296+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
2297+
2298+
lua_pushboolean(luaVM, false);
2299+
return 1;
2300+
}
2301+
2302+
int CLuaVehicleDefs::GetVehicleRespawnPosition(lua_State* luaVM)
2303+
{
2304+
// float, float, float getVehicleRespawnPosition( vehicle theVehicle )
2305+
CElement* pElement = NULL;
2306+
2307+
CScriptArgReader argStream(luaVM);
2308+
argStream.ReadUserData(pElement);
2309+
2310+
if (!argStream.HasErrors())
2311+
{
2312+
CVector vecPosition;
2313+
if (CStaticFunctionDefinitions::GetVehicleRespawnPosition(pElement, vecPosition))
2314+
{
2315+
lua_pushnumber(luaVM, vecPosition.fX);
2316+
lua_pushnumber(luaVM, vecPosition.fY);
2317+
lua_pushnumber(luaVM, vecPosition.fZ);
2318+
2319+
return 3;
2320+
}
2321+
}
2322+
else
2323+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
2324+
2325+
lua_pushboolean(luaVM, false);
2326+
return 1;
2327+
}
2328+
22242329
int CLuaVehicleDefs::SetVehicleRespawnPosition(lua_State* luaVM)
22252330
{
22262331
CElement* pElement;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class CLuaVehicleDefs : public CLuaDefs
9090
LUA_DECLARE(SetVehicleIdleRespawnDelay);
9191
LUA_DECLARE(SetVehicleRespawnDelay);
9292
LUA_DECLARE(SetVehicleRespawnPosition);
93+
LUA_DECLARE_OOP(GetVehicleRespawnPosition);
94+
LUA_DECLARE_OOP(GetVehicleRespawnRotation);
9395
LUA_DECLARE(ToggleVehicleRespawn);
9496
LUA_DECLARE(ResetVehicleExplosionTime);
9597
LUA_DECLARE(ResetVehicleIdleTime);
@@ -120,4 +122,4 @@ class CLuaVehicleDefs : public CLuaDefs
120122
LUA_DECLARE(GetVehicleSirens);
121123
LUA_DECLARE(GetVehicleSirenParams);
122124
LUA_DECLARE(SetVehiclePlateText);
123-
};
125+
};

0 commit comments

Comments
 (0)