From b5cd58057c5d3b0dc99ca44d5c976ca7b5eee79a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Mon, 5 Feb 2024 14:17:15 +0100 Subject: [PATCH] send playerIndex to clients --- code/client/src/core/modules/human.cpp | 9 ++++++--- code/client/src/core/modules/human.h | 1 + code/server/src/core/modules/human.cpp | 2 +- code/shared/messages/human/human_spawn.h | 9 ++++++++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/code/client/src/core/modules/human.cpp b/code/client/src/core/modules/human.cpp index 9c76da31..0bee6a20 100644 --- a/code/client/src/core/modules/human.cpp +++ b/code/client/src/core/modules/human.cpp @@ -130,7 +130,8 @@ namespace MafiaMP::Core::Modules { const auto humanPtr = tracking.human; const auto hp = updateData->_healthPercent; const auto nickname = humanData->nickname; - gApplication->GetImGUI()->PushWidget([humanPtr, hp, nickname]() { + const auto playerId = humanData->playerIndex; + gApplication->GetImGUI()->PushWidget([humanPtr, hp, nickname, playerId]() { const auto displaySize = ImGui::GetIO().DisplaySize; auto gameCamera = SDK::ue::game::camera::C_GameCamera::GetInstanceInternal(); @@ -154,7 +155,8 @@ namespace MafiaMP::Core::Modules { float unkFloat1, unkFloat2; camera->GetScreenPos(screenPos, headPos, onScreen, &unkFloat1, &unkFloat2, true); if (onScreen) { - Framework::External::ImGUI::Widgets::DrawNameTag({screenPos.x * displaySize.x, screenPos.y * displaySize.y}, nickname.empty() ? "Player" : nickname.c_str(), hp); + const auto playerName = fmt::format("{} ({})", nickname.empty() ? "Player" : nickname, playerId); + Framework::External::ImGUI::Widgets::DrawNameTag({screenPos.x * displaySize.x, screenPos.y * displaySize.y}, playerName.c_str(), hp); } } }); @@ -351,7 +353,8 @@ namespace MafiaMP::Core::Modules { auto updateData = e.get_mut(); auto humanData = e.get_mut(); - humanData->nickname = msg->GetNickname(); + humanData->nickname = msg->GetNickname(); + humanData->playerIndex = msg->GetPlayerIndex(); const auto carPassenger = msg->GetCarPassenger(); if (carPassenger.carId) { diff --git a/code/client/src/core/modules/human.h b/code/client/src/core/modules/human.h index d87702c8..6f9376a0 100644 --- a/code/client/src/core/modules/human.h +++ b/code/client/src/core/modules/human.h @@ -42,6 +42,7 @@ namespace MafiaMP::Core::Modules { } carPassenger {}; std::string nickname; + uint16_t playerIndex; }; Human(flecs::world &world); diff --git a/code/server/src/core/modules/human.cpp b/code/server/src/core/modules/human.cpp index 950b2357..96e50af2 100644 --- a/code/server/src/core/modules/human.cpp +++ b/code/server/src/core/modules/human.cpp @@ -52,7 +52,7 @@ namespace MafiaMP::Core::Modules { const auto frame = e.get(); const auto s = e.get(); Shared::Messages::Human::HumanSpawn humanSpawn; - humanSpawn.FromParameters(frame->modelHash, s->nickname); + humanSpawn.FromParameters(frame->modelHash, s->nickname, s->playerIndex); humanSpawn.SetServerID(e.id()); const auto trackingMetadata = e.get(); diff --git a/code/shared/messages/human/human_spawn.h b/code/shared/messages/human/human_spawn.h index 580c9011..511943c0 100644 --- a/code/shared/messages/human/human_spawn.h +++ b/code/shared/messages/human/human_spawn.h @@ -8,6 +8,7 @@ namespace MafiaMP::Shared::Messages::Human { private: uint64_t _spawnProfile; SLNet::RakString _nickname; + uint16_t _playerIndex; struct CarPassenger { uint64_t carId {}; @@ -19,14 +20,16 @@ namespace MafiaMP::Shared::Messages::Human { return MOD_HUMAN_SPAWN; } - void FromParameters(uint64_t spawnProfile, const std::string &nickname) { + void FromParameters(uint64_t spawnProfile, const std::string &nickname, uint16_t playerIndex) { _spawnProfile = spawnProfile; _nickname = nickname.c_str(); + _playerIndex = playerIndex; } void Serialize(SLNet::BitStream *bs, bool write) override { bs->Serialize(write, _spawnProfile); bs->Serialize(write, _nickname); + bs->Serialize(write, _playerIndex); bs->SerializeCompressed(write, _carPassenger); } @@ -42,6 +45,10 @@ namespace MafiaMP::Shared::Messages::Human { return _nickname.C_String(); } + uint16_t GetPlayerIndex() const { + return _playerIndex; + } + void SetCarPassenger(uint64_t carId, int seatId) { _carPassenger.carId = carId; _carPassenger.seatId = seatId;