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 handle this is using the server-client event system in FiveM. You can create an event in the server-side script that receives the selected option from the client-side script and then takes the necessary action accordingly.
Here is a simple example:
Server-side Script (server.lua)
luaRegisterServerEvent('onDrugMenuOptionSelected') AddEventHandler('onDrugMenuOptionSelected', function(drugType, optionIndex) local playerId = source local selectedOption = Config.drugMenu[drugType][optionIndex] -- Perform necessary action, e.g. remove money and give item -- Do whatever you need to do with the selectedOption, like: -- local price = selectedOption.price -- local reward = selectedOption.reward -- local amount = selectedOption.amount end) - User
what would the logic look like?
- Assistant
To provide an example of the logic, let's say you are using a menu library like 'MenuV' or 'NativeUI' to create and manage the menus. I will give you an outline of how this can be done using NativeUI as an example.
Client-side Script (client.lua):
- First, load the NativeUI library:
lualocal NativeUI = exports.NativeUI -- Or however you load the NativeUI library in your script
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.