Untitled
unknown
plain_text
2 years ago
2.5 kB
3
Indexable
using CitizenFX.Core; using CitizenFX.Core.Native; using System; using System.Collections.Generic; namespace EulenMenuExample { public class EulenMenu : BaseScript { private bool menuOpen = false; private int currentOption = 0; private List<string> options = new List<string> { "Opzione 1", "Opzione 2", "Opzione 3", "Opzione 4" }; public EulenMenu() { EventHandlers["onClientResourceStart"] += new Action<string>(OnClientResourceStart); } private void OnClientResourceStart(string resourceName) { if (API.GetCurrentResourceName() != resourceName) return; API.RegisterCommand("eulenmenu", new Action<int, List<object>, string>((source, args, raw) => { menuOpen = !menuOpen; API.SetNuiFocus(menuOpen, menuOpen); API.SendNuiMessage(@"{ ""type"": ""set_controls_state"", ""state"": """ + (menuOpen ? "true" : "false") + @""" }"); }), false); EventHandlers["__cfx_nui:keydown"] += new Action<dynamic>(OnKeyDown); } private void OnKeyDown(dynamic data) { switch (data.KeyCode) { case 245: // Up currentOption--; if (currentOption < 0) currentOption = options.Count - 1; API.SendNuiMessage(@"{ ""type"": ""update_option_index"", ""index"": """ + currentOption + @""" }"); break; case 244: // Down currentOption++; if (currentOption >= options.Count) currentOption = 0; API.SendNuiMessage(@"{ ""type"": ""update_option_index"", ""index"": """ + currentOption + @""" }"); break; case 246: // Select // Logic for option selected goes here break; case 177: // Back menuOpen = false; API.SetNuiFocus(menuOpen, menuOpen); API.SendNuiMessage(@"{ ""type"": ""set_controls_state"", ""state"": """ + (menuOpen ? "true" : "false") + @""" }"); break; } } } }
Editor is loading...