Skip to content

Add setElementCollidableWith server-side #4101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
17 changes: 17 additions & 0 deletions Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void CElementRPCs::LoadFunctions()
AddHandler(SET_PROPAGATE_CALLS_ENABLED, SetCallPropagationEnabled, "setCallPropagationEnabled");
AddHandler(SET_COLPOLYGON_HEIGHT, SetColPolygonHeight, "setColShapePolygonHeight");
AddHandler(SET_ELEMENT_ON_FIRE, SetElementOnFire, "setElementOnFire");
AddHandler(SET_ELEMENT_COLLIDABLE_WITH, SetElementCollidableWith, "setElementCollidableWith");
}

#define RUN_CHILDREN_SERVER(func) \
Expand Down Expand Up @@ -765,3 +766,19 @@ void CElementRPCs::SetElementOnFire(CClientEntity* pSource, NetBitStreamInterfac
{
pSource->SetOnFire(bitStream.ReadBit());
}

void CElementRPCs::SetElementCollidableWith(CClientEntity* pSource, NetBitStreamInterface& bitStream)
{
ElementID ElementID;

if (!bitStream.Can(eBitStreamVersion::SetElementCollidableWith_Serverside))
return;

bitStream.Read(ElementID);

CClientEntity* collidableWith = CElementIDs::GetElement(ElementID);

if (collidableWith == nullptr) // validity check
return;
Comment on lines +781 to +782
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!collidableWith)
    return;

pSource->SetCollidableWith(collidableWith, bitStream.ReadBit());
}
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/rpc/CElementRPCs.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ class CElementRPCs : public CRPCFunctions
DECLARE_ELEMENT_RPC(SetCallPropagationEnabled);
DECLARE_ELEMENT_RPC(SetColPolygonHeight);
DECLARE_ELEMENT_RPC(SetElementOnFire);
DECLARE_ELEMENT_RPC(SetElementCollidableWith);
};
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CPerfStat.RPCPacketUsage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ ADD_ENUM1(TOGGLE_OBJECT_RESPAWN)
ADD_ENUM1(RESET_WORLD_PROPERTIES)
ADD_ENUM1(SPAWN_VEHICLE_FLYING_COMPONENT)
ADD_ENUM1(SET_ELEMENT_ON_FIRE)
ADD_ENUM1(SET_ELEMENT_COLLIDABLE_WITH)
IMPLEMENT_ENUM_END("eElementRPCFunctions")

DECLARE_ENUM(CRPCFunctions::eRPCFunctions);
Expand Down
36 changes: 35 additions & 1 deletion Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
#include "packets/CChatEchoPacket.h"
#include "packets/CConsoleEchoPacket.h"
#include "packets/CChatClearPacket.h"
#include "packets/CElementRPCPacket.h"
#include "version.h"
#include <net/rpc_enums.h>

Expand Down Expand Up @@ -12566,3 +12565,38 @@ bool CStaticFunctionDefinitions::SpawnVehicleFlyingComponent(CVehicle* const veh

return true;
}

bool CStaticFunctionDefinitions::SetElementCollidableWith(CElement* element, CElement* withElement, bool canCollide)
{
switch (element->GetType())
{
case EElementType::PLAYER:
case EElementType::PED:
case EElementType::OBJECT:
case EElementType::WEAPON:
case EElementType::VEHICLE:
{
switch (withElement->GetType())
{
case EElementType::PLAYER:
case EElementType::PED:
case EElementType::OBJECT:
case EElementType::WEAPON:
case EElementType::VEHICLE:
{
CBitStream BitStream;
BitStream.pBitStream->Write(withElement->GetID());
BitStream.pBitStream->WriteBit(canCollide);
m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(element, SET_ELEMENT_COLLIDABLE_WITH, *BitStream.pBitStream));
return true;
}
default:
break;
}
break;
}
default:
break;
}
return false;
}
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -770,4 +770,5 @@ class CStaticFunctionDefinitions
static const char* GetOperatingSystemName();
static const char* GetVersionBuildTag();
static CMtaVersion GetVersionSortable();
static bool SetElementCollidableWith(CElement* element, CElement* withElement, bool canCollide);
};
6 changes: 6 additions & 0 deletions Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ void CLuaElementDefs::LoadFunctions()
{"setElementFrozen", setElementFrozen},
{"setLowLODElement", setLowLODElement},
{"setElementOnFire", ArgumentParser<SetElementOnFire>},
{"setElementCollidableWith", ArgumentParser<SetElementCollidableWith>},
};

// Add functions
Expand Down Expand Up @@ -2460,3 +2461,8 @@ bool CLuaElementDefs::SetElementOnFire(CElement* element, bool onFire) noexcept
{
return CStaticFunctionDefinitions::SetElementOnFire(element, onFire);
}

bool CLuaElementDefs::SetElementCollidableWith(CElement* element, CElement* withElement, bool canCollide)
{
return CStaticFunctionDefinitions::SetElementCollidableWith(element, withElement, canCollide);
}
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 SetElementCollidableWith(CElement* element, CElement* withElement, bool canCollide);
};
4 changes: 4 additions & 0 deletions Shared/sdk/net/bitstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,10 @@ enum class eBitStreamVersion : unsigned short
// 2025-01-29
PedSync_CameraRotation,

//Add setElementCollidableWith serverside
// 2025-03-14
SetElementCollidableWith_Serverside,

// This allows us to automatically increment the BitStreamVersion when things are added to this enum.
// Make sure you only add things above this comment.
Next,
Expand Down
2 changes: 2 additions & 0 deletions Shared/sdk/net/rpc_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,7 @@ enum eElementRPCFunctions

SET_ELEMENT_ON_FIRE,

SET_ELEMENT_COLLIDABLE_WITH,

NUM_RPC_FUNCS // Add above this line
};
Loading