Skip to content
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

send playerIndex to clients + show ID in nametag #84

Merged
merged 1 commit into from
Feb 5, 2024
Merged
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
9 changes: 6 additions & 3 deletions code/client/src/core/modules/human.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
}
});
Expand Down Expand Up @@ -351,7 +353,8 @@ namespace MafiaMP::Core::Modules {
auto updateData = e.get_mut<Shared::Modules::HumanSync::UpdateData>();
auto humanData = e.get_mut<HumanData>();

humanData->nickname = msg->GetNickname();
humanData->nickname = msg->GetNickname();
humanData->playerIndex = msg->GetPlayerIndex();

const auto carPassenger = msg->GetCarPassenger();
if (carPassenger.carId) {
Expand Down
1 change: 1 addition & 0 deletions code/client/src/core/modules/human.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace MafiaMP::Core::Modules {
} carPassenger {};

std::string nickname;
uint16_t playerIndex;
};

Human(flecs::world &world);
Expand Down
2 changes: 1 addition & 1 deletion code/server/src/core/modules/human.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace MafiaMP::Core::Modules {
const auto frame = e.get<Framework::World::Modules::Base::Frame>();
const auto s = e.get<Framework::World::Modules::Base::Streamer>();
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<Shared::Modules::HumanSync::UpdateData>();
Expand Down
9 changes: 8 additions & 1 deletion code/shared/messages/human/human_spawn.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace MafiaMP::Shared::Messages::Human {
private:
uint64_t _spawnProfile;
SLNet::RakString _nickname;
uint16_t _playerIndex;

struct CarPassenger {
uint64_t carId {};
Expand All @@ -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);
}

Expand All @@ -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;
Expand Down
Loading