diff --git a/docs/dev_notes.md b/docs/dev_notes.md index 3b63ceb53..ef5f70feb 100644 --- a/docs/dev_notes.md +++ b/docs/dev_notes.md @@ -68,10 +68,10 @@ - [x] troll: set fire - [x] troll: wild attack +- [x] Generalize the sound function in `cl_misc.lua` and replace the other `PlaySoundFrontend` - [x] Make Z optional in tp to coords feature +- [x] Vehicle spawn should accept `[horse, cart, boat]` options, maybe add the buttons - [ ] Find out why the players page doesn't reflect the player health, maybe it is client side only? -- [ ] Vehicle spawn should accept `[horse, cart, boat]` options, maybe add the buttons -- [x] Generalize the sound function in `cl_misc.lua` and replace the other `PlaySoundFrontend` - [ ] Deprecate `cl_misc.lua`: move `playLibrarySound` to `cl_functions`, the rest to `cl_base` - [ ] make `recipes/indexv4.json` dropping version and adding tags diff --git a/nui/src/components/MainPage/MainPageList.tsx b/nui/src/components/MainPage/MainPageList.tsx index c0658600e..4e3afedd0 100644 --- a/nui/src/components/MainPage/MainPageList.tsx +++ b/nui/src/components/MainPage/MainPageList.tsx @@ -35,6 +35,8 @@ import { arrayRandom } from "../../utils/miscUtils"; import { copyToClipboard } from "../../utils/copyToClipboard"; import { useServerCtxValue } from "../../state/server.state"; import { VehicleMode, useVehicleMode } from "../../state/vehiclemode.state"; +import { useIsRedmValue } from "@nui/src/state/isRedm.state"; +import { getVehicleSpawnDialogData, vehiclePlaceholderReplacer } from "@nui/src/utils/vehicleSpawnDialogHelper"; const fadeHeight = 20; const listHeight = 388; @@ -80,6 +82,7 @@ export const MainPageList: React.FC = () => { const [healMode, setHealMode] = useHealMode(); const serverCtx = useServerCtxValue(); const menuVisible = useIsMenuVisibleValue(); + const isRedm = useIsRedmValue() //FIXME: this is so the menu resets multi selectors when we close it // but it is not working, and when I do this the first time we press @@ -191,49 +194,17 @@ export const MainPageList: React.FC = () => { }); } + const dialogData = getVehicleSpawnDialogData(isRedm); openDialog({ title: t("nui_menu.page_main.vehicle.spawn.dialog_title"), description: t("nui_menu.page_main.vehicle.spawn.dialog_desc"), - placeholder: "car, bike, heli, boat, Adder, Buzzard, etc", + placeholder: dialogData.shortcuts.join(', ') + ', etc.', onSubmit: (modelName: string) => { - modelName = modelName.trim().toLowerCase(); - if (modelName === "car") { - modelName = - Math.random() < 0.05 - ? "caddy" - : arrayRandom([ - "comet2", - "coquette", - "trophytruck", - "issi5", - "f620", - "nero", - "sc1", - "toros", - "tyrant", - ]); - } else if (modelName === "bike") { - modelName = - Math.random() < 0.05 - ? "bmx" - : arrayRandom(["esskey", "nemesis", "sanchez"]); - } else if (modelName === "heli") { - modelName = - Math.random() < 0.05 - ? "havok" - : arrayRandom(["buzzard2", "volatus"]); - } else if (modelName === "boat") { - modelName = - Math.random() < 0.05 - ? "seashark" - : arrayRandom(["dinghy", "toro2"]); - } + modelName = vehiclePlaceholderReplacer(modelName, dialogData.shortcutsData); fetchNui("spawnVehicle", { model: modelName }).then(({ e }) => { e ? enqueueSnackbar( - t("nui_menu.page_main.vehicle.spawn.dialog_error", { - modelName, - }), + t("nui_menu.page_main.vehicle.spawn.dialog_error", { modelName }), { variant: "error" } ) : enqueueSnackbar( @@ -582,7 +553,7 @@ export const MainPageList: React.FC = () => { // onSelect: handleSpawnWeapon, // }, ], - [playerMode, teleportMode, vehicleMode, healMode, serverCtx] + [playerMode, teleportMode, vehicleMode, healMode, serverCtx, isRedm] ); return ( diff --git a/nui/src/utils/vehicleSpawnDialogHelper.ts b/nui/src/utils/vehicleSpawnDialogHelper.ts new file mode 100644 index 000000000..e2bdc8671 --- /dev/null +++ b/nui/src/utils/vehicleSpawnDialogHelper.ts @@ -0,0 +1,70 @@ +import { arrayRandom } from './miscUtils'; + +type ShortcutDataType = { + easterEgg: string | false; + default: string[] +} +type ShortcutsDataType = Record + +const fivemShortcuts: ShortcutsDataType = { + car: { + easterEgg: 'caddy', + default: ['comet2', 'coquette', 'trophytruck', 'issi5', 'f620', 'nero', 'sc1', 'toros', 'tyrant'], + }, + bike: { + easterEgg: 'bmx', + default: ['esskey', 'nemesis', 'sanchez'], + }, + heli: { + easterEgg: 'havok', + default: ['buzzard2', 'volatus'], + }, + boat: { + easterEgg: 'seashark', + default: ['dinghy', 'toro2'], + }, +}; + +const redmShortcuts: ShortcutsDataType = { + horse: { + easterEgg: 'a_c_horsemulepainted_01', + default: ['a_c_horse_arabian_redchestnut', 'a_c_horse_turkoman_perlino', 'a_c_horse_missourifoxtrotter_buckskinbrindle'], + }, + buggy: { + easterEgg: false, + default: ['buggy01', 'buggy02', 'buggy03'], + }, + coach: { + easterEgg: false, + default: ['coach2', 'coach3', 'coach4', 'coach5', 'coach6'], + }, + canoe: { + easterEgg: 'rowboat', + default: ['canoe', 'pirogue', 'pirogue2'], + }, +}; + +/** + * Returns the input string or replaces it with a random vehicle shortcut + */ +export const vehiclePlaceholderReplacer = (vehInput: string, shortcutsData: ShortcutsDataType) => { + vehInput = vehInput.trim().toLowerCase(); + if (vehInput in shortcutsData) { + const shortcut = shortcutsData[vehInput as keyof typeof shortcutsData]; + if (shortcut.easterEgg && Math.random() < 0.05) { + vehInput = shortcut.easterEgg; + } else { + vehInput = arrayRandom(shortcut.default); + } + } + + return vehInput; +} + +/** + * Returns the appropriate vehicle shortcut data for a given game + */ +export const getVehicleSpawnDialogData = (isRedm: boolean) => ({ + shortcuts: isRedm ? Object.keys(redmShortcuts) : Object.keys(fivemShortcuts), + shortcutsData: isRedm ? redmShortcuts : fivemShortcuts, +}) diff --git a/resource/menu/client/cl_vehicle.lua b/resource/menu/client/cl_vehicle.lua index f22d5baa1..da20c39fd 100644 --- a/resource/menu/client/cl_vehicle.lua +++ b/resource/menu/client/cl_vehicle.lua @@ -301,8 +301,8 @@ RegisterNetEvent('txcl:vehicle:spawn:redm', function(model) SetVehicleOnGroundProperly(newVeh) else newVeh = CreatePed(modelHash, playerCoords, playerHeading, true, false) - Citizen.InvokeNative(0x77FF8D35EEC6BBC4, newVeh, 1, 0) --EquipMetaPedOutfitPreset - -- Citizen.InvokeNative(0x283978A15512B2FE, newVeh, true) --SetRandomOutfitVariation + -- Citizen.InvokeNative(0x77FF8D35EEC6BBC4, newVeh, 1, 0) --EquipMetaPedOutfitPreset + Citizen.InvokeNative(0x283978A15512B2FE, newVeh, true) --SetRandomOutfitVariation Citizen.InvokeNative(0x028F76B6E78246EB, playerPed, newVeh, -1) --SetPedOntoMount end