diff --git a/src/game/features/vehicle/Spawn.cpp b/src/game/features/vehicle/Spawn.cpp index f641711..2ffb940 100644 --- a/src/game/features/vehicle/Spawn.cpp +++ b/src/game/features/vehicle/Spawn.cpp @@ -4,12 +4,15 @@ #include "core/backend/ScriptMgr.hpp" #include "core/commands/BoolCommand.hpp" #include "game/gta/data/VehicleValues.hpp" +#include "core/frontend/Notifications.hpp" namespace YimMenu::Features { static StringCommand _VehicleModelname{"vehmodelname", "Vehicle model name", "The model name of the vehicle you wish to spawn."}; static BoolCommand _SpawnInVehicle{"spawninvehicle", "Spawn in vehicle", "Enter vehicle once it is spawned", false}; static BoolCommand _SpawnWithMaximumUpgrades{"spawnupgraded", "Spawn with maximum upgrades", "Spawn vehicle with maximum upgrades", false}; + static BoolCommand _UseCustomLicensePlate{"usecustomlicenseplate", "Use custom license plate", "Use a custom license plate for the vehicle", false}; + static StringCommand _CustomLicensePlate{"customlicenseplate", "Custom license plate", "The custom license plate for the vehicle"}; class SpawnVehicle : public Command { using Command::Command; @@ -17,35 +20,50 @@ namespace YimMenu::Features virtual void OnCall() override { auto model = _VehicleModelname.GetString(); + + if (!model.length()) + { + Notifications::Show("Spawn Vehicle", "No model name provided.", NotificationType::Error); + return; + } Hash modelHash = Joaat(model); - if (!modelHash) - { - LOG(WARNING) << "Couldn't spawn vehicle because no model name was specified."; - return; - } + assert(modelHash != 0); if (STREAMING::IS_MODEL_IN_CDIMAGE(modelHash)) { rage::fvector3 coords = Self::GetPed().GetPosition(); - auto veh = Vehicle::Create(modelHash, coords, Self::GetPed().GetHeading()).GetHandle(); + auto veh = Vehicle::Create(modelHash, coords, Self::GetPed().GetHeading()); + auto vehHandle = veh.GetHandle(); if (_SpawnInVehicle.GetState()) { - PED::SET_PED_INTO_VEHICLE(Self::GetPed().GetHandle(), veh, -1); + PED::SET_PED_INTO_VEHICLE(Self::GetPed().GetHandle(), vehHandle, -1); } if (_SpawnWithMaximumUpgrades.GetState()) { - VEHICLE::SET_VEHICLE_MOD_KIT(veh, 0); - - for (int t = (int)VehicleModType::MOD_SPOILERS; t < (int)VehicleModType::MOD_LIGHTBAR; t++) { - VEHICLE::SET_VEHICLE_MOD(veh, t, VEHICLE::GET_NUM_VEHICLE_MODS(veh, t) - 1, false); - } - - VEHICLE::SET_VEHICLE_TYRES_CAN_BURST(veh, false); + veh.Upgrade(); } + + if (_UseCustomLicensePlate.GetState()) + { + std::string licensePlate = _CustomLicensePlate.GetString(); + + if (licensePlate.length() > 8) + { + Notifications::Show("Spawn Vehicle", "License plate must be 8 characters or less.", NotificationType::Error); + } + else if (licensePlate.length() > 0) + { + veh.SetPlateText(licensePlate); + } + } + } + else + { + Notifications::Show("Spawn Vehicle", "Invalid model name provided.", NotificationType::Error); } } }; diff --git a/src/game/frontend/submenus/World.cpp b/src/game/frontend/submenus/World.cpp index 4b6e251..21be140 100644 --- a/src/game/frontend/submenus/World.cpp +++ b/src/game/frontend/submenus/World.cpp @@ -12,6 +12,8 @@ namespace YimMenu::Submenus spawnGroup->AddItem(std::make_shared("vehmodelname"_J)); spawnGroup->AddItem(std::make_shared("spawninvehicle"_J)); spawnGroup->AddItem(std::make_shared("spawnupgraded"_J)); + spawnGroup->AddItem(std::make_shared("usecustomlicenseplate"_J)); + spawnGroup->AddItem(std::make_shared("usecustomlicenseplate"_J, std::make_shared("customlicenseplate"_J))); spawnGroup->AddItem(std::make_shared("spawnvehicle"_J)); mainGroup->AddItem(spawnGroup); diff --git a/src/game/gta/Vehicle.cpp b/src/game/gta/Vehicle.cpp index b182f2d..be9f0c6 100644 --- a/src/game/gta/Vehicle.cpp +++ b/src/game/gta/Vehicle.cpp @@ -2,6 +2,7 @@ #include "Natives.hpp" #include "core/backend/ScriptMgr.hpp" #include "game/pointers/Pointers.hpp" +#include "game/gta/data/VehicleValues.hpp" namespace YimMenu { @@ -83,4 +84,35 @@ namespace YimMenu return VEHICLE::GET_VEHICLE_ESTIMATED_MAX_SPEED(GetHandle()); } + + void Vehicle::Upgrade() + { + ENTITY_ASSERT_VALID(); + ENTITY_ASSERT_CONTROL(); + + auto veh = GetHandle(); + + VEHICLE::SET_VEHICLE_MOD_KIT(veh, 0); + + for (int t = (int)VehicleModType::MOD_SPOILERS; t < (int)VehicleModType::MOD_LIGHTBAR; t++) + { + VEHICLE::SET_VEHICLE_MOD(veh, t, VEHICLE::GET_NUM_VEHICLE_MODS(veh, t) - 1, false); + } + + VEHICLE::SET_VEHICLE_TYRES_CAN_BURST(veh, false); + } + + void Vehicle::SetPlateText(const std::string text) + { + ENTITY_ASSERT_VALID(); + ENTITY_ASSERT_CONTROL(); + + if (text.length() > 8) + { + return; + } + + const char* cstr = text.c_str(); + VEHICLE::SET_VEHICLE_NUMBER_PLATE_TEXT(GetHandle(), cstr); + } } \ No newline at end of file diff --git a/src/game/gta/Vehicle.hpp b/src/game/gta/Vehicle.hpp index 433ab5c..18d50d9 100644 --- a/src/game/gta/Vehicle.hpp +++ b/src/game/gta/Vehicle.hpp @@ -18,5 +18,8 @@ namespace YimMenu // speed float GetMaxSpeed(); + + void Upgrade(); + void SetPlateText(const std::string text); }; } \ No newline at end of file