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 2 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
13 changes: 13 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,15 @@ void CElementRPCs::SetElementOnFire(CClientEntity* pSource, NetBitStreamInterfac
{
pSource->SetOnFire(bitStream.ReadBit());
}

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

bitStream.Read(ElementID);
bitStream.ReadBit(bCollidable);
Copy link
Contributor

Choose a reason for hiding this comment

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

bitStream.Read can return false

Copy link
Member

Choose a reason for hiding this comment

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

It cannot. The protocol guarantees that the message is fully received.

Copy link
Contributor

Choose a reason for hiding this comment

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

It cannot. The protocol guarantees that the message is fully received.

So what is the purpose of this function being a bool, and why does most of the code check if it returns true?

Copy link
Member

Choose a reason for hiding this comment

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

Code == documentation
It has sense on the server side. The client reads server packets only.
Checks on client could be used to add a new data to a packet without increasing bitstream version, i think


CClientEntity* pCollidableWith = CElementIDs::GetElement(ElementID);
pSource->SetCollidableWith(pCollidableWith, bCollidable);
}
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
37 changes: 36 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,39 @@ 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);
};
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