Skip to content

Commit

Permalink
generate license plate (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
zpl-zak authored Feb 5, 2024
1 parent 1b70cdb commit ca5b5de
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion code/client/src/core/modules/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 14 additions & 1 deletion code/server/src/core/modules/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,20 @@ namespace MafiaMP::Core::Modules {
auto frame = e.get_mut<Framework::World::Modules::Base::Frame>();
frame->modelName = "berkley_810"; /* TODO */

e.add<Shared::Modules::VehicleSync::UpdateData>();
auto updateData = e.get_mut<Shared::Modules::VehicleSync::UpdateData>();

// 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<CarData>();
e.add<Framework::World::Modules::Base::RemovedOnGameModeReload>();

Expand Down
2 changes: 1 addition & 1 deletion code/shared/modules/vehicle_sync.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ca5b5de

Please sign in to comment.