diff --git a/Client/game_sa/CPhysicalSA.h b/Client/game_sa/CPhysicalSA.h index eb5a2a4515..a1236f371b 100644 --- a/Client/game_sa/CPhysicalSA.h +++ b/Client/game_sa/CPhysicalSA.h @@ -104,8 +104,8 @@ class CPhysicalSAInterface : public CEntitySAInterface CVector m_vecUnk; // 280 uint32 m_pad4; // 292 CPtrNodeDoubleLink* m_pControlCodeNodeLink; // 296 - float m_fLighting; // 300 - float m_fLighting2; // 304 + float m_fLighting; // 300 surface brightness + float m_fLighting2; // 304 dynamic lighting (unused, always set to 0 in the GTA code) class CShadowDataSA* m_pShadowData; // 308 CRect* GetBoundRect_(CRect* pRect); diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp index e88f8f6751..ff4f9b3abb 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp @@ -99,6 +99,7 @@ void CLuaElementDefs::LoadFunctions() {"setElementFrozen", SetElementFrozen}, {"setLowLODElement", ArgumentParser}, {"setElementCallPropagationEnabled", SetElementCallPropagationEnabled}, + {"setElementLighting", ArgumentParser}, }; // Add functions @@ -191,6 +192,7 @@ void CLuaElementDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "setLowLOD", "setLowLODElement"); lua_classfunction(luaVM, "setCallPropagationEnabled", "setElementCallPropagationEnabled"); lua_classfunction(luaVM, "setStreamable", "setElementStreamable"); + lua_classfunction(luaVM, "setLighting", "setElementLighting"); lua_classvariable(luaVM, "callPropagationEnabled", "setElementCallPropagationEnabled", "isElementCallPropagationEnabled"); lua_classvariable(luaVM, "waitingForGroundToLoad", NULL, "isElementWaitingForGroundToLoad"); @@ -225,6 +227,7 @@ void CLuaElementDefs::AddClass(lua_State* luaVM) lua_classvariable(luaVM, "velocity", SetElementVelocity, OOP_GetElementVelocity); lua_classvariable(luaVM, "angularVelocity", SetElementAngularVelocity, OOP_GetElementTurnVelocity); lua_classvariable(luaVM, "isElement", NULL, "isElement"); + lua_classvariable(luaVM, "lighting", "setElementLighting", "getElementLighting"); // TODO: Support element data: player.data["age"] = 1337; <=> setElementData(player, "age", 1337) lua_registerclass(luaVM, "Element"); @@ -1340,6 +1343,7 @@ std::variant CLuaElementDefs::GetElementLighting(CClientEntity* ent break; } case CCLIENTOBJECT: + case CCLIENTWEAPON: { CObject* object = static_cast(entity)->GetGameObject(); if (object) @@ -2604,3 +2608,41 @@ int CLuaElementDefs::IsElementWaitingForGroundToLoad(lua_State* luaVM) lua_pushboolean(luaVM, false); return 1; } + +bool CLuaElementDefs::SetElementLighting(CClientEntity* entity, float lighting) +{ + switch (entity->GetType()) + { + case CCLIENTPLAYER: + case CCLIENTPED: + { + auto* ped = static_cast(entity)->GetGamePlayer(); + if (!ped) + return false; + + ped->SetLighting(lighting); + return true; + } + case CCLIENTVEHICLE: + { + auto* vehicle = static_cast(entity)->GetGameVehicle(); + if (!vehicle) + return false; + + vehicle->SetLighting(lighting); + return true; + } + case CCLIENTOBJECT: + case CCLIENTWEAPON: + { + auto* object = static_cast(entity)->GetGameObject(); + if (!object) + return false; + + object->SetLighting(lighting); + return true; + } + } + + return false; +} diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.h index 40f93761e4..87b8c42f64 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.h @@ -99,4 +99,5 @@ class CLuaElementDefs : public CLuaDefs LUA_DECLARE(SetElementFrozen); static bool SetLowLodElement(lua_State* luaVM, CClientEntity* pEntity, std::optional pLowLodEntity); LUA_DECLARE(SetElementCallPropagationEnabled); + static bool SetElementLighting(CClientEntity* entity, float lighting); };