Skip to content

Commit 90fd98a

Browse files
authored
New function setElementLighting (#3905)
setElementLighting
1 parent 8d7167a commit 90fd98a

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

Client/game_sa/CPhysicalSA.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ class CPhysicalSAInterface : public CEntitySAInterface
104104
CVector m_vecUnk; // 280
105105
uint32 m_pad4; // 292
106106
CPtrNodeDoubleLink<void>* m_pControlCodeNodeLink; // 296
107-
float m_fLighting; // 300
108-
float m_fLighting2; // 304
107+
float m_fLighting; // 300 surface brightness
108+
float m_fLighting2; // 304 dynamic lighting (unused, always set to 0 in the GTA code)
109109
class CShadowDataSA* m_pShadowData; // 308
110110

111111
CRect* GetBoundRect_(CRect* pRect);

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ void CLuaElementDefs::LoadFunctions()
9999
{"setElementFrozen", SetElementFrozen},
100100
{"setLowLODElement", ArgumentParser<SetLowLodElement>},
101101
{"setElementCallPropagationEnabled", SetElementCallPropagationEnabled},
102+
{"setElementLighting", ArgumentParser<SetElementLighting>},
102103
};
103104

104105
// Add functions
@@ -191,6 +192,7 @@ void CLuaElementDefs::AddClass(lua_State* luaVM)
191192
lua_classfunction(luaVM, "setLowLOD", "setLowLODElement");
192193
lua_classfunction(luaVM, "setCallPropagationEnabled", "setElementCallPropagationEnabled");
193194
lua_classfunction(luaVM, "setStreamable", "setElementStreamable");
195+
lua_classfunction(luaVM, "setLighting", "setElementLighting");
194196

195197
lua_classvariable(luaVM, "callPropagationEnabled", "setElementCallPropagationEnabled", "isElementCallPropagationEnabled");
196198
lua_classvariable(luaVM, "waitingForGroundToLoad", NULL, "isElementWaitingForGroundToLoad");
@@ -225,6 +227,7 @@ void CLuaElementDefs::AddClass(lua_State* luaVM)
225227
lua_classvariable(luaVM, "velocity", SetElementVelocity, OOP_GetElementVelocity);
226228
lua_classvariable(luaVM, "angularVelocity", SetElementAngularVelocity, OOP_GetElementTurnVelocity);
227229
lua_classvariable(luaVM, "isElement", NULL, "isElement");
230+
lua_classvariable(luaVM, "lighting", "setElementLighting", "getElementLighting");
228231
// TODO: Support element data: player.data["age"] = 1337; <=> setElementData(player, "age", 1337)
229232

230233
lua_registerclass(luaVM, "Element");
@@ -1340,6 +1343,7 @@ std::variant<bool, float> CLuaElementDefs::GetElementLighting(CClientEntity* ent
13401343
break;
13411344
}
13421345
case CCLIENTOBJECT:
1346+
case CCLIENTWEAPON:
13431347
{
13441348
CObject* object = static_cast<CClientObject*>(entity)->GetGameObject();
13451349
if (object)
@@ -2604,3 +2608,41 @@ int CLuaElementDefs::IsElementWaitingForGroundToLoad(lua_State* luaVM)
26042608
lua_pushboolean(luaVM, false);
26052609
return 1;
26062610
}
2611+
2612+
bool CLuaElementDefs::SetElementLighting(CClientEntity* entity, float lighting)
2613+
{
2614+
switch (entity->GetType())
2615+
{
2616+
case CCLIENTPLAYER:
2617+
case CCLIENTPED:
2618+
{
2619+
auto* ped = static_cast<CClientPed*>(entity)->GetGamePlayer();
2620+
if (!ped)
2621+
return false;
2622+
2623+
ped->SetLighting(lighting);
2624+
return true;
2625+
}
2626+
case CCLIENTVEHICLE:
2627+
{
2628+
auto* vehicle = static_cast<CClientVehicle*>(entity)->GetGameVehicle();
2629+
if (!vehicle)
2630+
return false;
2631+
2632+
vehicle->SetLighting(lighting);
2633+
return true;
2634+
}
2635+
case CCLIENTOBJECT:
2636+
case CCLIENTWEAPON:
2637+
{
2638+
auto* object = static_cast<CClientObject*>(entity)->GetGameObject();
2639+
if (!object)
2640+
return false;
2641+
2642+
object->SetLighting(lighting);
2643+
return true;
2644+
}
2645+
}
2646+
2647+
return false;
2648+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,5 @@ class CLuaElementDefs : public CLuaDefs
9999
LUA_DECLARE(SetElementFrozen);
100100
static bool SetLowLodElement(lua_State* luaVM, CClientEntity* pEntity, std::optional<CClientEntity*> pLowLodEntity);
101101
LUA_DECLARE(SetElementCallPropagationEnabled);
102+
static bool SetElementLighting(CClientEntity* entity, float lighting);
102103
};

0 commit comments

Comments
 (0)