fivem scripting i'm working on a script and this is my config how would I make it so…
- User
fivem scripting i'm working on a script and this is my config how would I make it so drugMenu = { ['heroin'] = { [5] = {label = '5x Heroin Bricks [3,000,000]', price = 3000000, reward = 'drugbrick12', amount = 5}, [10] = {label = '10x Heroin Bricks [5,750,000]', price = 5750000, reward = 'drugbrick12', amount = 10}, [25] = {label = '25x Heroin Bricks [13,500,000]', price = 13500000, reward = 'drugbrick12', amount = 25} }, ['lsd'] = { [5] = {label = '5x LSD Sheets [1,500,000]', price = 1500000, reward = 'drugbrick6', amount = 5}, [10] = {label = '10x LSD Sheets [2,875,000]', price = 2875000, reward = 'drugbrick6', amount = 10}, [25] = {label = '25x LSD Sheets [6,750,000]', price = 6750000, reward = 'drugbrick6', amount = 25} } } I have a client menu that selects an option and then triggers an event what would be the best way to detect which option was selected and then do something
- Assistant
One way to detect which option was selected and then do something is to pass the option as a parameter when triggering the event.
For example, in your client menu, you could have something like:
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'drug_menu', { title = 'Select a drug:', align = 'top-left', elements = { {label = 'Heroin', value = 'heroin'}, {label = 'LSD', value = 'lsd'} } }, function(data, menu) TriggerServerEvent('myScript:sellDrug', data.current.value) -- pass selected option as parameter end, function(data, menu) menu.close() end)Then in your server script, you can capture the selected option as a parameter in the event handler function and use it to perform the desired action.
For example:
RegisterServerEvent('myScript:sellDrug') AddEventHandler('myScript:sellDrug', function(drugType) local drugs = drugMenu[drugType] -- get options for selected drug -- do something with the selected options -- for example, spawn a prop and give reward item when player buys an option end)Overall, the key is to pass the selected option as a parameter and use it to access the corresponding options in the config.
- User
standalone script
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.