From ca5b5de40b6438008f10e6780302d290fc90c5ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Mon, 5 Feb 2024 20:55:15 +0100 Subject: [PATCH] generate license plate (#91) --- code/client/src/core/modules/vehicle.cpp | 2 +- code/server/src/core/modules/vehicle.cpp | 15 ++++++++++++++- code/shared/modules/vehicle_sync.hpp | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/code/client/src/core/modules/vehicle.cpp b/code/client/src/core/modules/vehicle.cpp index d5d18a85..7692897a 100644 --- a/code/client/src/core/modules/vehicle.cpp +++ b/code/client/src/core/modules/vehicle.cpp @@ -207,7 +207,7 @@ namespace MafiaMP::Core::Modules { vehicle->SetGear(updateData->gear); vehicle->SetHandbrake(updateData->handbrake, false); vehicle->SetHorn(updateData->hornOn); - if (strcmp(vehicle->GetSPZText(), updateData->licensePlate)) { + if (::strcmp(vehicle->GetSPZText(), updateData->licensePlate) > 0) { vehicle->SetSPZText(updateData->licensePlate, true); } vehicle->SetPower(updateData->power); diff --git a/code/server/src/core/modules/vehicle.cpp b/code/server/src/core/modules/vehicle.cpp index cc38c7fc..dc47fbde 100644 --- a/code/server/src/core/modules/vehicle.cpp +++ b/code/server/src/core/modules/vehicle.cpp @@ -43,7 +43,20 @@ namespace MafiaMP::Core::Modules { auto frame = e.get_mut(); frame->modelName = "berkley_810"; /* TODO */ - e.add(); + auto updateData = e.get_mut(); + + // generate a random license plate + { + constexpr char letters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + constexpr char numbers[] = "0123456789"; + for (int i = 0; i < 2; i++) { + updateData->licensePlate[i] = letters[::rand() % (sizeof(letters) - 1)]; + } + for (int i = 3; i < 6; i++) { + updateData->licensePlate[i] = numbers[::rand() % (sizeof(numbers) - 1)]; + } + } + e.add(); e.add(); diff --git a/code/shared/modules/vehicle_sync.hpp b/code/shared/modules/vehicle_sync.hpp index 294d4d01..48ed9737 100644 --- a/code/shared/modules/vehicle_sync.hpp +++ b/code/shared/modules/vehicle_sync.hpp @@ -25,7 +25,7 @@ namespace MafiaMP::Shared::Modules { int gear = 0; float handbrake = 0.0f; bool hornOn = false; - char licensePlate[7] = "M1-MP"; + char licensePlate[7] = "AZ-000"; LockState lockState = LockState::Unlocked; float power = 0.0f; bool radioOn = false;