Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ void CLuaElementDefs::LoadFunctions()
{"setElementCallPropagationEnabled", SetElementCallPropagationEnabled},
{"setElementLighting", ArgumentParser<SetElementLighting>},
{"setElementOnFire", ArgumentParser<SetElementOnFire>},
{"isElementOnGround", ArgumentParser<IsElementOnGround>},
};

// Add functions
Expand Down Expand Up @@ -171,6 +172,7 @@ void CLuaElementDefs::AddClass(lua_State* luaVM)
lua_classfunction(luaVM, "getData", "getElementData");
lua_classfunction(luaVM, "getAllData", "getAllElementData");
lua_classfunction(luaVM, "isOnFire", "isElementOnFire");
lua_classfunction(luaVM, "onGround", "isElementOnGround");

lua_classfunction(luaVM, "setAttachedOffsets", "setElementAttachedOffsets");
lua_classfunction(luaVM, "setData", "setElementData");
Expand Down Expand Up @@ -231,6 +233,7 @@ void CLuaElementDefs::AddClass(lua_State* luaVM)
lua_classvariable(luaVM, "isElement", NULL, "isElement");
lua_classvariable(luaVM, "lighting", "setElementLighting", "getElementLighting");
lua_classvariable(luaVM, "onFire", "setElementOnFire", "isElementOnFire");
lua_classvariable(luaVM, "onGround", NULL, "isElementOnGround");
// TODO: Support element data: player.data["age"] = 1337; <=> setElementData(player, "age", 1337)

lua_registerclass(luaVM, "Element");
Expand Down Expand Up @@ -2660,3 +2663,19 @@ bool CLuaElementDefs::IsElementOnFire(CClientEntity* entity) noexcept
{
return entity->IsOnFire();
}

bool CLuaElementDefs::IsElementOnGround(CClientEntity* entity)
{
switch (entity->GetType())
{
case CCLIENTPLAYER:
case CCLIENTPED:
return static_cast<CClientPed*>(entity)->IsOnGround();
case CCLIENTVEHICLE:
return static_cast<CClientVehicle*>(entity)->IsOnGround();
default:
throw std::invalid_argument{"This element type does not support IsElementOnGround"};
}

return false;
}
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class CLuaElementDefs : public CLuaDefs
LUA_DECLARE(IsElementCallPropagationEnabled);
LUA_DECLARE(IsElementWaitingForGroundToLoad);
static bool IsElementOnFire(CClientEntity* entity) noexcept;
static bool IsElementOnGround(CClientEntity* entity);

// Element set funcs
LUA_DECLARE(CreateElement);
Expand Down
9 changes: 8 additions & 1 deletion Server/mods/deathmatch/logic/CResourceChecker.Data.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ namespace

{false, "removeAllGameBuildings", "removeGameWorld"},
{false, "restoreAllGameBuildings", "restoreGameWorld"},

{false, "isPedOnGround", "isElementOnGround"},
{false, "isVehicleOnGround", "isElementOnGround"},
};

SDeprecatedItem serverDeprecatedList[] = {
Expand Down Expand Up @@ -244,6 +247,10 @@ namespace

// Ped
{false, "setPedOnFire", "setElementOnFire"},
{false, "isPedOnFire", "isElementOnFire"}
{false, "isPedOnFire", "isElementOnFire"},
{false, "isPedOnGround", "isElementOnGround"},

// Vehicle
{false, "isVehicleOnGround", "isElementOnGround"}
};
} // namespace
19 changes: 19 additions & 0 deletions Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void CLuaElementDefs::LoadFunctions()
{"getElementCollisionsEnabled", getElementCollisionsEnabled},
{"getLowLODElement", getLowLODElement},
{"isElementOnFire", ArgumentParser<IsElementOnFire>},
{"isElementOnGround", ArgumentParser<IsElementOnGround>},

// Attachement
{"attachElements", attachElements},
Expand Down Expand Up @@ -193,6 +194,7 @@ void CLuaElementDefs::AddClass(lua_State* luaVM)
lua_classfunction(luaVM, "isLowLOD", "isElementLowLOD");
lua_classfunction(luaVM, "isAttached", "isElementAttached");
lua_classfunction(luaVM, "isOnFire", "isElementOnFire");
lua_classfunction(luaVM, "onGround", "isElementOnGround");

lua_classvariable(luaVM, "id", "setElementID", "getElementID");
lua_classvariable(luaVM, "callPropagationEnabled", "setElementCallPropagationEnabled", "isElementCallPropagationEnabled");
Expand Down Expand Up @@ -222,6 +224,7 @@ void CLuaElementDefs::AddClass(lua_State* luaVM)
lua_classvariable(luaVM, "angularVelocity", "setElementAngularVelocity", "getElementAngularVelocity", setElementTurnVelocity, OOP_getElementTurnVelocity);
lua_classvariable(luaVM, "isElement", NULL, "isElement");
lua_classvariable(luaVM, "onFire", "setElementOnFire", "isElementOnFire");
lua_classvariable(luaVM, "onGround", NULL, "isElementOnGround");

lua_registerclass(luaVM, "Element");
}
Expand Down Expand Up @@ -2460,3 +2463,19 @@ bool CLuaElementDefs::SetElementOnFire(CElement* element, bool onFire) noexcept
{
return CStaticFunctionDefinitions::SetElementOnFire(element, onFire);
}

bool CLuaElementDefs::IsElementOnGround(CElement* element)
{
switch (element->GetType())
{
case CElement::PLAYER:
case CElement::PED:
return static_cast<CPed*>(element)->IsOnGround();
case CElement::VEHICLE:
return static_cast<CVehicle*>(element)->IsOnGround();
default:
throw std::invalid_argument{"This element type does not support IsElementOnGround"};
}

return false;
}
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,5 @@ class CLuaElementDefs : public CLuaDefs
LUA_DECLARE(setLowLODElement);
LUA_DECLARE(setElementCallPropagationEnabled);
static bool SetElementOnFire(CElement* element, bool onFire) noexcept;
static bool IsElementOnGround(CElement* element);
};