Skip to content
Closed
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
15 changes: 15 additions & 0 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4412,6 +4412,21 @@ bool CClientGame::ApplyPedDamageFromGame(eWeaponType weaponUsed, float fDamage,
}
pDamagedPed->GetGamePlayer()->SetHealth(fPreviousHealth);
pDamagedPed->GetGamePlayer()->SetArmor(fPreviousArmor);

if (IS_PLAYER(pDamagedPed) && pDamagedPed->IsLocalPlayer() && g_pNet->CanServerBitStream(eBitStreamVersion::PlayerDamageCancelled))
{
if (auto* stream = g_pNet->AllocateNetBitStream())
{
stream->Write(pInflictingEntity ? pInflictingEntity->GetID() : 0);
stream->Write(static_cast<std::uint8_t>(weaponUsed));
stream->Write(static_cast<std::uint8_t>(hitZone));
stream->Write(fDamage);

g_pNet->SendPacket(PACKET_ID_PLAYER_DAMAGE_CANCELLED, stream, PACKET_PRIORITY_HIGH, PACKET_RELIABILITY_RELIABLE_ORDERED);
g_pNet->DeallocateNetBitStream(stream);
}
}

return false;
}

Expand Down
34 changes: 34 additions & 0 deletions Server/mods/deathmatch/logic/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#include "packets/CPlayerListPacket.h"
#include "packets/CPlayerClothesPacket.h"
#include "packets/CPlayerWorldSpecialPropertyPacket.h"
#include "packets/CPlayerDamageCancelledPacket.h"
#include "packets/CServerInfoSyncPacket.h"
#include "packets/CLuaPacket.h"
#include "../utils/COpenPortsTester.h"
Expand Down Expand Up @@ -1322,6 +1323,12 @@ bool CGame::ProcessPacket(CPacket& Packet)
return true;
}

case PACKET_ID_PLAYER_DAMAGE_CANCELLED:
{
Packet_PlayerDamageCancelled(static_cast<CPlayerDamageCancelledPacket&>(Packet));
return true;
}

default:
break;
}
Expand Down Expand Up @@ -1642,6 +1649,7 @@ void CGame::AddBuiltInEvents()
m_Events.AddEvent("onPlayerChangesProtectedData", "element, key, value", nullptr, false);
m_Events.AddEvent("onPlayerChangesWorldSpecialProperty", "property, enabled", nullptr, false);
m_Events.AddEvent("onPlayerTeleport", "previousX, previousY, previousZ, currentX, currentY, currentZ", nullptr, false);
m_Events.AddEvent("onPlayerDamageCancelled", "attacker, cause, bodypart, loss", nullptr, false);

// Ped events
m_Events.AddEvent("onPedVehicleEnter", "vehicle, seat, jacked", NULL, false);
Expand Down Expand Up @@ -4307,6 +4315,32 @@ void CGame::Packet_PlayerWorldSpecialProperty(CPlayerWorldSpecialPropertyPacket&
player->CallEvent("onPlayerChangesWorldSpecialProperty", arguments, nullptr);
}

void CGame::Packet_PlayerDamageCancelled(CPlayerDamageCancelledPacket& packet)
{
CPlayer* player = packet.GetSourcePlayer();

if (!player)
return;

const std::uint32_t attacker = packet.GetAttacker();
const std::uint8_t cause = packet.GetCause();
const std::uint8_t bodypart = packet.GetBodypart();
const float loss = packet.GetLoss();

CLuaArguments arguments;

if (GetElementFromId<CElement>(attacker))
arguments.PushElement(GetElementFromId<CElement>(attacker));
else
arguments.PushNil();

arguments.PushNumber(cause);
arguments.PushNumber(bodypart);
arguments.PushNumber(loss);

player->CallEvent("onPlayerDamageCancelled", arguments, nullptr);
}

void CGame::Packet_PlayerModInfo(CPlayerModInfoPacket& Packet)
{
CPlayer* pPlayer = Packet.GetSourcePlayer();
Expand Down
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ class CGame
void Packet_PlayerNetworkStatus(class CPlayerNetworkStatusPacket& Packet);
void Packet_PlayerResourceStart(class CPlayerResourceStartPacket& Packet);
void Packet_PlayerWorldSpecialProperty(class CPlayerWorldSpecialPropertyPacket& packet) noexcept;
void Packet_PlayerDamageCancelled(class CPlayerDamageCancelledPacket& packet);

static void PlayerCompleteConnect(CPlayer* pPlayer);

Expand Down
5 changes: 5 additions & 0 deletions Server/mods/deathmatch/logic/CPacketTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "packets/CPlayerNetworkStatusPacket.h"
#include "packets/CPlayerResourceStartPacket.h"
#include "packets/CPlayerWorldSpecialPropertyPacket.h"
#include "packets/CPlayerDamageCancelledPacket.h"

CPacketTranslator::CPacketTranslator(CPlayerManager* pPlayerManager)
{
Expand Down Expand Up @@ -217,6 +218,10 @@ CPacket* CPacketTranslator::Translate(const NetServerPlayerID& Socket, ePacketID
pTemp = new CPlayerWorldSpecialPropertyPacket;
break;

case PACKET_ID_PLAYER_DAMAGE_CANCELLED:
pTemp = new CPlayerDamageCancelledPacket;
break;

default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: mods/deathmatch/logic/packets/CPlayerDamageCancelledPacket.cpp
*
* Multi Theft Auto is available from https://www.multitheftauto.com/
*
*****************************************************************************/

#include "StdInc.h"
#include "CPlayerDamageCancelledPacket.h"

bool CPlayerDamageCancelledPacket::Read(NetBitStreamInterface& stream)
{
stream.Read(m_attacker);
stream.Read(m_cause);
stream.Read(m_bodypart);
stream.Read(m_loss);

return true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: mods/deathmatch/logic/packets/CPlayerDamageCancelledPacket.h
*
* Multi Theft Auto is available from https://www.multitheftauto.com/
*
*****************************************************************************/

#pragma once

#include <string>
#include <cstdint>
#include "CPacket.h"

class CPlayerDamageCancelledPacket final : public CPacket
{
public:
CPlayerDamageCancelledPacket() noexcept {}

ePacketID GetPacketID() const noexcept { return PACKET_ID_PLAYER_DAMAGE_CANCELLED; }
unsigned long GetFlags() const noexcept { return PACKET_HIGH_PRIORITY | PACKET_RELIABLE | PACKET_SEQUENCED; }
virtual ePacketOrdering GetPacketOrdering() const noexcept { return PACKET_ORDERING_DEFAULT; }

bool Read(NetBitStreamInterface& stream);

std::uint32_t GetAttacker() const noexcept { return m_attacker; }
std::uint8_t GetCause() const noexcept { return m_cause; }
std::uint8_t GetBodypart() const noexcept { return m_bodypart; }
float GetLoss() const noexcept { return m_loss; }

private:
std::uint32_t m_attacker;
std::uint8_t m_cause;
std::uint8_t m_bodypart;
float m_loss;
};
1 change: 1 addition & 0 deletions Shared/mods/deathmatch/logic/Enums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,5 @@ ADD_ENUM1(PACKET_ID_SERVER_INFO_SYNC)
ADD_ENUM1(PACKET_ID_DISCORD_JOIN)
ADD_ENUM1(PACKET_ID_PLAYER_RESOURCE_START)
ADD_ENUM1(PACKET_ID_PLAYER_WORLD_SPECIAL_PROPERTY)
ADD_ENUM1(PACKET_ID_PLAYER_DAMAGE_CANCELLED)
IMPLEMENT_ENUM_END("ePacketID")
3 changes: 2 additions & 1 deletion Shared/sdk/net/Packets.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,6 @@ enum ePacketID
PACKET_ID_SERVER_INFO_SYNC,
PACKET_ID_DISCORD_JOIN,
PACKET_ID_PLAYER_RESOURCE_START,
PACKET_ID_PLAYER_WORLD_SPECIAL_PROPERTY
PACKET_ID_PLAYER_WORLD_SPECIAL_PROPERTY,
PACKET_ID_PLAYER_DAMAGE_CANCELLED
};
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 onPlayerDamageCancelled
// 2025-02-21
PlayerDamageCancelled,

// 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
Loading