Skip to content

Commit

Permalink
feat(menu/vehicle): added redm shortcuts to veh spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed Apr 25, 2023
1 parent a43978c commit a7fc974
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 41 deletions.
4 changes: 2 additions & 2 deletions docs/dev_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 8 additions & 37 deletions nui/src/components/MainPage/MainPageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -582,7 +553,7 @@ export const MainPageList: React.FC = () => {
// onSelect: handleSpawnWeapon,
// },
],
[playerMode, teleportMode, vehicleMode, healMode, serverCtx]
[playerMode, teleportMode, vehicleMode, healMode, serverCtx, isRedm]
);

return (
Expand Down
70 changes: 70 additions & 0 deletions nui/src/utils/vehicleSpawnDialogHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { arrayRandom } from './miscUtils';

type ShortcutDataType = {
easterEgg: string | false;
default: string[]
}
type ShortcutsDataType = Record<string, ShortcutDataType>

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,
})
4 changes: 2 additions & 2 deletions resource/menu/client/cl_vehicle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit a7fc974

Please sign in to comment.