Advertisement
glitchdetector

FiveM ShowPrompt system

Oct 16th, 2018
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.05 KB | None | 0 0
  1. local WARNING_BUTTONS = {
  2.     ["SELECT"] = {2^0, 201},
  3.     ["OK"] = {2^1, 201},
  4.     ["YES"] = {2^2, 201},
  5.     ["BACK"] = {2^3, 202},
  6.     ["CANCEL"] = {2^4, 202},
  7.     ["NO"] = {2^5, 202},
  8.     ["RETRY"] = {2^6, 203},
  9.     ["RESTART"] = {2^7, 203},
  10.     ["SKIP"] = {2^8, 203},
  11.     ["QUIT"] = {2^9, 202},
  12.     ["ADJUST"] = {2^10, 0},
  13.     ["BLANK"] = {2^11, 203},
  14.     ["SHARE"] = {2^12, 203},
  15.     ["SIGNIN"] = {2^13, 203},
  16.     ["CONTINUE"] = {2^14, 201},
  17.     ["ADJUST2"] = {2^15, 0},
  18.     ["SCROLL"] = {2^16, 0},
  19.     ["OVERWRITE"] = {2^17, 203},
  20.     ["SOCIALCLUB_SIGNUP"] = {2^18, 201},
  21.     ["CONFIRM2"] = {2^19, 201},
  22.     ["QUEUE"] = {2^20, 201},
  23.     ["RETRY_A"] = {2^21, 201},
  24.     ["BACK2"] = {2^22, 202},
  25.     ["SOCIALCLUB"] = {2^23, 201},
  26.     ["SPECTATE"] = {2^24, 203},
  27.     ["OK_B"] = {2^25, 202},
  28.     ["TRANSFER_CANCEL"] = {2^26, 202},
  29.     ["LOADING"] = {2^27, 0},
  30.     ["NO_RETURN_TO_GTAV"] = {2^28, 202},
  31.     ["CANCEL2"] = {2^29, 202},
  32.     ["BLANK2"] = {2^30, 0},
  33.     ["JOBS"] = {2^31, 0},
  34. }
  35.  
  36. for _, v in next, WARNING_BUTTONS do
  37.     v[1] = math.floor(v[1])
  38. end
  39.  
  40. local PROMPT_QUEUE = {}
  41.  
  42. function ShowPrompt(header, line1, line2, buttons)
  43.     table.insert(PROMPT_QUEUE, {header, line1, line2, buttons})
  44.     if #PROMPT_QUEUE > 1 then
  45.         -- print("Put prompt in queue")
  46.         return true
  47.     end
  48.     _sp(header, line1, line2, buttons)
  49. end
  50.  
  51. function _sp(header, line1, line2, buttons)
  52.     local funcs = {}
  53.     local inst_no = 0
  54.     for _, button in next, buttons do
  55.         local btn_data = WARNING_BUTTONS[button[1]]
  56.         if btn_data then
  57.             -- print("Button Data for " .. button[1] .. ": " .. json.encode(btn_data))
  58.             inst_no = inst_no + btn_data[1]
  59.             table.insert(funcs, {
  60.                 button[1],
  61.                 btn_data[2],
  62.                 button[2],
  63.             })
  64.         else
  65.             -- Button entry no existu
  66.         end
  67.     end
  68.     AddTextEntry("OMNI_PMT1", line1)
  69.     AddTextEntry("OMNI_PMT2", line2)
  70.     AddTextEntry("OMNI_PMTH", header)
  71.     if inst_no > 0 then
  72.         local _show = true
  73.         local _t = 0
  74.         local _w = 4
  75.         while _show or _w > 0 do
  76.             if _t > 2 and _show then
  77.                 for _, func in next, funcs do
  78.                     if IsControlJustPressed(2, func[2]) then
  79.                         -- print("Pressed " .. func[1])
  80.                         func[3]()
  81.                         _show = false
  82.                         _t = 0
  83.                         break
  84.                     end
  85.                 end
  86.             end
  87.             SetWarningMessage_3("OMNI_PMTH", "OMNI_PMT1", inst_no, "OMNI_PMT2", false, 0, 0, 0, false)
  88.             Wait(0)
  89.             _t = _t + 1
  90.             if not _show then
  91.                 _w = _w - 1
  92.             end
  93.         end
  94.     end
  95.     table.remove(PROMPT_QUEUE, 1)
  96.     if #PROMPT_QUEUE > 0 then
  97.         -- print("Next prompt in queue")
  98.         _sp(PROMPT_QUEUE[1][1], PROMPT_QUEUE[1][2], PROMPT_QUEUE[1][3], PROMPT_QUEUE[1][4])
  99.     end
  100. end
  101.  
  102. AddEventHandler("omni:prompt", function(header, line1, line2, _buttons)
  103.     local buttons = {}
  104.     for _, button in next, _buttons do
  105.         if button[2] == "" or not button[2] then
  106.             table.insert(buttons, {button[1], function() end})
  107.         else
  108.             table.insert(buttons, {button[1], function() TriggerEvent(button[2]) end})
  109.         end
  110.     end
  111.     ShowPrompt(header, line1, line2, buttons)
  112. end)
  113.  
  114. RegisterCommand("dv", function()
  115.     ShowPrompt("/dv", "You are about to delete your vehicle!", "Are you sure you want to do this?", {
  116.         {"YES", function() TriggerEvent("gd_utils:notify", "Deleted vehicle!") end},
  117.         {"NO", function() TriggerEvent("gd_utils:notify", "Did not delete vehicle") end},
  118.         {"LOADING", function() TriggerEvent("gd_utils:notify", "wtf") end},
  119.     })
  120. end, false)
  121. RegisterCommand("afk", function()
  122.     ShowPrompt("AFK", "You are currently Away From Keyboard", "Press Continue to resume gameplay", {
  123.         {"CONTINUE", function() TriggerEvent("gd_utils:notify", "Welcome back!") end},
  124.     })
  125. end, false)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement