Skip to content

Commit cee4d11

Browse files
committed
Source
1 parent b5399a4 commit cee4d11

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4412,6 +4412,25 @@ bool CClientGame::ApplyPedDamageFromGame(eWeaponType weaponUsed, float fDamage,
44124412
}
44134413
pDamagedPed->GetGamePlayer()->SetHealth(fPreviousHealth);
44144414
pDamagedPed->GetGamePlayer()->SetArmor(fPreviousArmor);
4415+
4416+
if (IS_PLAYER(pDamagedPed) && pDamagedPed->IsLocalPlayer() && g_pNet->CanServerBitStream(eBitStreamVersion::PlayerDamageCancelled))
4417+
{
4418+
if (auto stream = g_pNet->AllocateNetBitStream())
4419+
{
4420+
if (pInflictingEntity)
4421+
stream->Write(pInflictingEntity->GetID());
4422+
else
4423+
stream->Write(0);
4424+
4425+
stream->Write(static_cast<std::uint8_t>(weaponUsed));
4426+
stream->Write(static_cast<std::uint8_t>(hitZone));
4427+
stream->Write(fDamage);
4428+
4429+
g_pNet->SendPacket(PACKET_ID_PLAYER_DAMAGE_CANCELLED, stream, PACKET_PRIORITY_HIGH, PACKET_RELIABILITY_RELIABLE_ORDERED);
4430+
g_pNet->DeallocateNetBitStream(stream);
4431+
}
4432+
}
4433+
44154434
return false;
44164435
}
44174436

Server/mods/deathmatch/logic/CGame.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include "packets/CPlayerListPacket.h"
6060
#include "packets/CPlayerClothesPacket.h"
6161
#include "packets/CPlayerWorldSpecialPropertyPacket.h"
62+
#include "packets/CPlayerDamageCancelledPacket.h"
6263
#include "packets/CServerInfoSyncPacket.h"
6364
#include "packets/CLuaPacket.h"
6465
#include "../utils/COpenPortsTester.h"
@@ -1322,6 +1323,12 @@ bool CGame::ProcessPacket(CPacket& Packet)
13221323
return true;
13231324
}
13241325

1326+
case PACKET_ID_PLAYER_DAMAGE_CANCELLED:
1327+
{
1328+
Packet_PlayerDamageCancelled(static_cast<CPlayerDamageCancelledPacket&>(Packet));
1329+
return true;
1330+
}
1331+
13251332
default:
13261333
break;
13271334
}
@@ -1642,6 +1649,7 @@ void CGame::AddBuiltInEvents()
16421649
m_Events.AddEvent("onPlayerChangesProtectedData", "element, key, value", nullptr, false);
16431650
m_Events.AddEvent("onPlayerChangesWorldSpecialProperty", "property, enabled", nullptr, false);
16441651
m_Events.AddEvent("onPlayerTeleport", "previousX, previousY, previousZ, currentX, currentY, currentZ", nullptr, false);
1652+
m_Events.AddEvent("onPlayerDamageCancelled", "attacker, cause, bodypart, loss", nullptr, false);
16451653

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

4318+
void CGame::Packet_PlayerDamageCancelled(CPlayerDamageCancelledPacket& packet) noexcept
4319+
{
4320+
CPlayer* player = packet.GetSourcePlayer();
4321+
4322+
if (!player)
4323+
return;
4324+
4325+
const std::uint32_t attacker = packet.GetAttacker();
4326+
const std::uint8_t cause = packet.GetCause();
4327+
const std::uint8_t bodypart = packet.GetBodypart();
4328+
const float loss = packet.GetLoss();
4329+
4330+
CLuaArguments arguments;
4331+
4332+
if (GetElementFromId<CElement>(attacker))
4333+
arguments.PushElement(GetElementFromId<CElement>(attacker));
4334+
else
4335+
arguments.PushNil();
4336+
4337+
arguments.PushNumber(cause);
4338+
arguments.PushNumber(bodypart);
4339+
arguments.PushNumber(loss);
4340+
4341+
player->CallEvent("onPlayerDamageCancelled", arguments, nullptr);
4342+
}
4343+
43104344
void CGame::Packet_PlayerModInfo(CPlayerModInfoPacket& Packet)
43114345
{
43124346
CPlayer* pPlayer = Packet.GetSourcePlayer();

Server/mods/deathmatch/logic/CPacketTranslator.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "packets/CPlayerNetworkStatusPacket.h"
5050
#include "packets/CPlayerResourceStartPacket.h"
5151
#include "packets/CPlayerWorldSpecialPropertyPacket.h"
52+
#include "packets/CPlayerDamageCancelledPacket.h"
5253

5354
CPacketTranslator::CPacketTranslator(CPlayerManager* pPlayerManager)
5455
{
@@ -217,6 +218,10 @@ CPacket* CPacketTranslator::Translate(const NetServerPlayerID& Socket, ePacketID
217218
pTemp = new CPlayerWorldSpecialPropertyPacket;
218219
break;
219220

221+
case PACKET_ID_PLAYER_DAMAGE_CANCELLED:
222+
pTemp = new CPlayerDamageCancelledPacket;
223+
break;
224+
220225
default:
221226
break;
222227
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: mods/deathmatch/logic/packets/CPlayerDamageCancelledPacket.cpp
6+
*
7+
* Multi Theft Auto is available from https://www.multitheftauto.com/
8+
*
9+
*****************************************************************************/
10+
11+
#include "StdInc.h"
12+
#include "CPlayerDamageCancelledPacket.h"
13+
14+
bool CPlayerDamageCancelledPacket::Read(NetBitStreamInterface& stream) noexcept
15+
{
16+
stream.Read(m_attacker);
17+
stream.Read(m_cause);
18+
stream.Read(m_bodypart);
19+
stream.Read(m_loss);
20+
21+
return true;
22+
}

Shared/mods/deathmatch/logic/Enums.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,5 @@ ADD_ENUM1(PACKET_ID_SERVER_INFO_SYNC)
216216
ADD_ENUM1(PACKET_ID_DISCORD_JOIN)
217217
ADD_ENUM1(PACKET_ID_PLAYER_RESOURCE_START)
218218
ADD_ENUM1(PACKET_ID_PLAYER_WORLD_SPECIAL_PROPERTY)
219+
ADD_ENUM1(PACKET_ID_PLAYER_DAMAGE_CANCELLED)
219220
IMPLEMENT_ENUM_END("ePacketID")

0 commit comments

Comments
 (0)