Advertisement
hhjfdgdfgdfg

vorp menu

Apr 4th, 2024
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.02 KB | None | 0 0
  1. VORP MENU
  2. Create a menu using an API
  3. Client side
  4. lua
  5. -- on the top of your client side
  6. local VORPMenu = {} -- local
  7.  
  8. TriggerEvent("vorp_menu:getData",function(cb)
  9. VORPMenu = cb
  10. end)
  11. API
  12. lua
  13. -- close all menus before opening another
  14. ---@type function
  15. VORPMenu.CloseAll()
  16. Create Menu
  17. lua
  18. -- function or event
  19. function OpenMenu(any,any)
  20.  
  21. VORPMenu.CloseAll()
  22.  
  23. -- * table * --
  24. MenuElements = {
  25. -- * elements * --
  26. -- by default you need to set these 3
  27.  
  28. {
  29. label = "name",
  30. value = "value",
  31. desc = "description"
  32. }
  33. -------------------------
  34.  
  35. -- to use slider set in this format
  36. {
  37. label = "name",
  38. value = 0,
  39. desc = "description",
  40. type = "slider",
  41. min = 0,
  42. max = 10,
  43. hop = 1
  44. }
  45. -------------------------
  46.  
  47. -- you can add extra definded arguments
  48. {
  49. label = "name",
  50. value = "value",
  51. desc = "description",
  52. itemHeight = "4vh" -- this will allow to change the height of only this element
  53. }
  54. -------------------------
  55.  
  56. -- alternatively you can add extra non definded arguments to use as you need
  57. {
  58. label = "name",
  59. value = "value",
  60. desc = "description",
  61. ---@param any <table,string,number>
  62. info = any --(optional)
  63. info2 = { --(optional)
  64. this = "string",
  65. that = 111,
  66. etc = table,
  67. extra = Convert -- function
  68. }
  69. }
  70. -------------------------
  71. }
  72.  
  73. -- * open menu * --
  74.  
  75. VORPMenu.Open("default",GetCurrentResourceName(),"vorp_menu_OpenMenu", -- unique namespace
  76.  
  77. {
  78. title = "menu title",
  79. subtext = "menu sub text",
  80. align = "align", -- top-right , top-center , top-left
  81. elements = MenuElements, -- elements needed
  82. lastmenu = "function name", -- if you wish to go back to the previous menu , or remove (optional)
  83. itemHeight = "4vh", -- set all elements to this height if they are not definded in the element (optional)
  84. },
  85.  
  86.  
  87. function(data, menu)
  88. -- to go back to lastmenu if any
  89. if (data.current == "backup") then --(optional)
  90. -- params last function need
  91. return _G[data.trigger](any,any) -- or the function of the last menu
  92. end
  93.  
  94. -- get any of the params you definded in the elements
  95. if data.current.value == "value" then
  96. -- do code
  97. end
  98.  
  99. if data.current.info == "param" then
  100. -- do code
  101. return menu.close()
  102.  
  103. -- modify elements or create
  104. end
  105.  
  106. end,function(data,menu) --(optional)
  107. -- if theres no previous menu close menu on backspace press
  108. menu.close()
  109. end)
  110.  
  111. end
  112. Update a value from an element
  113. lua
  114. -- if you know the index you can change values on the go
  115. ---@param index number
  116. ---@param value string
  117. ---@param newValue string
  118. menu.setElement(index, value, newValue)
  119. menu.refresh() -- refresh the menu so changes are added
  120. Find an index or value from all elements made
  121. lua
  122. for index , value in pairs(menu.data.elements)
  123. if value.value == "value" then
  124. menu.setElement(index, value, newValue)
  125. menu.refresh()
  126. break
  127. end
  128. end
  129. Set new elements by removing old
  130. lua
  131. -- this will remove all other elements and add only this one
  132. replaceElements = {
  133. {
  134. label = "label",
  135. value = "open",
  136. desc = "description"
  137. }
  138. --ad more
  139. }
  140. menu.setElements(replaceElements)
  141. menu.refresh()
  142. add a new element to the table already made
  143. lua
  144. -- this will add a new element without removing old elements
  145. menu.addNewElement({
  146. label = "label",
  147. value = "open",
  148. desc = "description"
  149. })
  150. menu.refresh()
  151. remove an element by index
  152. lua
  153. -- remove a single element by its index
  154. ---@param index number
  155. ---@param loop boolean you can use this when you loop through several elements and remove all indexes
  156. local loop = true
  157. for index,value in pairs(menu.data.elements) then
  158. -- if you have several elements that you need to removed called open leave `loop` true or set false
  159. if value.value = "open" then
  160. menu.removeElementByIndex(index,loop)
  161. if not loop then break end
  162. end
  163. end
  164. menu.refresh()
  165. remove an element by its value
  166. lua
  167. -- remove a single element by its index
  168. ---@param index number
  169. ---@param loop boolean you can use this when you loop through several elements and remove all indexes
  170. local loop = true
  171. for index,value in pairs(menu.data.elements) then
  172. -- if you have several elements that you need to remove called open leave `loop` true or set false
  173. if value.value = "open" then
  174. menu.removeElementByValue(value.value,loop)
  175. if not loop then break end
  176. end
  177. end
  178. menu.refresh()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement