DaBOSS54320

Bully LUA: Menu System

May 3rd, 2016
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.73 KB | None | 0 0
  1. function main()
  2.     -- Test table:
  3.     local testTable = {0,1,2,3} -- for testing the "Dynamic Number" option where the max selection is table size.
  4.    
  5.     -- Set up menus:
  6.     testMenu = {"Main Menu",1,{
  7.         {"Simple Function",function() PlayerAddMoney(10000) end},
  8.         {"Toggle Function",false,function(toggle)
  9.             if toggle then
  10.                 GameSetPedStat(gPlayer,20,200)
  11.             else
  12.                 GameSetPedStat(gPlayer,20,100)
  13.             end
  14.         end},
  15.         {"Number Function",1,1,5,function(num) TextPrintString("Number: "..num,3,2) end},
  16.         {"Option Function",1,{"SpudG","Rocket Launcher"},false,nil,function(weap)
  17.             if weap == 1 then
  18.                 PlayerSetWeapon(305,8)
  19.             elseif weap == 2 then
  20.                 PlayerSetWeapon(307,12)
  21.             end
  22.         end},
  23.         {"Sub Menu",1,{
  24.             {"Nothing"},
  25.         }},
  26.         {"Dynamic Number",1,1,testTable,function(num) TextPrintString("Number: "..num,3,2) end},
  27.     }}
  28.     menus = {testMenu}
  29.     menuActive = false
  30.    
  31.     -- Main loop:
  32.     while true do
  33.         -- Process menu:
  34.         if menuActive then
  35.             PlayerSetControl(0)
  36.             local menu = menus[table.getn(menus)]
  37.             local t = F_GetOptionType(menu[3][menu[2]])
  38.             local text = menu[1].."\n\n"
  39.             for i = menu[2] - 2,menu[2] + 2 do
  40.                 if i == menu[2] then
  41.                     text = text..">"
  42.                 end
  43.                 if i >= 1 and i <= table.getn(menu[3]) then
  44.                     local t = F_GetOptionType(menu[3][i])
  45.                     text = text..menu[3][i][1]
  46.                     if t == "toggle" then
  47.                         text = text.." ["..((menu[3][i][2] and "ON") or "OFF").."]"
  48.                     elseif t == "numopt" or t == "dynopt" then
  49.                         text = text.." <"..menu[3][i][2]..">"
  50.                     elseif t == "stropt" then
  51.                         text = text.." <"..menu[3][i][3][menu[3][i][2]]..">"
  52.                     end
  53.                 end
  54.                 text = text.."\n"
  55.             end
  56.             TextPrintString(text,0,1)
  57.             Wait(0)
  58.             if IsButtonBeingPressed(2,0) then
  59.                 SoundPlay2D("ButtonUp")
  60.                 menu[2] = menu[2] - 1
  61.                 if menu[2] < 1 then
  62.                     menu[2] = table.getn(menu[3])
  63.                 end
  64.             elseif IsButtonBeingPressed(3,0) then
  65.                 SoundPlay2D("ButtonUp")
  66.                 menu[2] = menu[2] + 1
  67.                 if menu[2] > table.getn(menu[3]) then
  68.                     menu[2] = 1
  69.                 end
  70.             elseif IsButtonBeingPressed(0,0) and type(menu[3][menu[2]][2]) == "number" then
  71.                 SoundPlay2D("ButtonUp")
  72.                 local minimum = (t == "stropt" and 1) or menu[3][menu[2]][3]
  73.                 local maximum = (t == "dynopt" and table.getn(menu[3][menu[2]][4])) or (t == "stropt" and table.getn(menu[3][menu[2]][3])) or menu[3][menu[2]][4]
  74.                 menu[3][menu[2]][2] = menu[3][menu[2]][2] - 1
  75.                 if menu[3][menu[2]][2] < minimum then
  76.                     menu[3][menu[2]][2] = maximum
  77.                 end
  78.                 if menu[3][menu[2]][5] then
  79.                     menu[3][menu[2]][5](menu[3][menu[2]][2])
  80.                 end
  81.             elseif IsButtonBeingPressed(1,0) and type(menu[3][menu[2]][2]) == "number" then
  82.                 SoundPlay2D("ButtonUp")
  83.                 local minimum = (t == "stropt" and 1) or menu[3][menu[2]][3]
  84.                 local maximum = (t == "dynopt" and table.getn(menu[3][menu[2]][4])) or (t == "stropt" and table.getn(menu[3][menu[2]][3])) or menu[3][menu[2]][4]
  85.                 menu[3][menu[2]][2] = menu[3][menu[2]][2] + 1
  86.                 if menu[3][menu[2]][2] > maximum then
  87.                     menu[3][menu[2]][2] = minimum
  88.                 end
  89.                 if menu[3][menu[2]][5] then
  90.                     menu[3][menu[2]][5](menu[3][menu[2]][2])
  91.                 end
  92.             elseif IsButtonBeingPressed(7,0) then
  93.                 SoundPlay2D("ButtonUp")
  94.                 if t == "simple" and menu[3][menu[2]][2] then
  95.                     menu[3][menu[2]][2]()
  96.                 elseif t == "toggle" then
  97.                     menu[3][menu[2]][2] = not menu[3][menu[2]][2]
  98.                     if menu[3][menu[2]][3] then
  99.                         menu[3][menu[2]][3](menu[3][menu[2]][2])
  100.                     end
  101.                 elseif t == "numopt" or t == "dynopt" or (t == "stropt" and not menu[3][menu[2]][4]) then
  102.                     local maximum = (t == "dynopt" and table.getn(menu[3][menu[2]][4])) or (t == "stropt" and table.getn(menu[3][menu[2]][3])) or menu[3][menu[2]][4]
  103.                     if menu[3][menu[2]][2] > maximum then
  104.                         menu[3][menu[2]][2] = maximum
  105.                     end
  106.                     if menu[3][menu[2]][6] and (t ~= "dynopt" or menu[3][menu[2]][2] >= menu[3][menu[2]][3]) then
  107.                         menu[3][menu[2]][6](menu[3][menu[2]][2])
  108.                     end
  109.                 elseif t == "stropt" then
  110.                     if menu[3][menu[2]][6] then
  111.                         menu[3][menu[2]][6](menu[3][menu[2]][3][menu[3][menu[2]][2]])
  112.                     end
  113.                 elseif t == "submen" then
  114.                     table.insert(menus,menu[3][menu[2]])
  115.                 end
  116.             elseif IsButtonBeingPressed(8,0) then
  117.                 SoundPlay2D("ButtonDown")
  118.                 if table.getn(menus) > 1 then
  119.                     table.remove(menus)
  120.                 else
  121.                     menuActive = false
  122.                     PlayerSetControl(1)
  123.                 end
  124.             end
  125.         else
  126.             Wait(0)
  127.             if IsButtonBeingPressed(3,0) then
  128.                 menuActive = true
  129.             end
  130.         end
  131.     end
  132. end
  133.  
  134. function F_GetOptionType(option)
  135.     if type(option[2]) == "function" then
  136.         return "simple"
  137.     elseif type(option[2]) == "boolean" then
  138.         return "toggle"
  139.     elseif type(option[3]) == "number" and type(option[4]) == "number" then
  140.         return "numopt"
  141.     elseif type(option[3]) == "number" and type(option[4]) == "table" then
  142.         return "dynopt"
  143.     elseif type(option[3]) == "table" and type(option[4]) == "boolean" then
  144.         return "stropt"
  145.     elseif type(option[2]) == "number" and type(option[3]) == "table" then
  146.         return "submen"
  147.     end
  148. end
  149.  
  150. -- STimeCycle functions:
  151. F_AttendedClass = function()
  152.   if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
  153.     return
  154.   end
  155.   SetSkippedClass(false)
  156.   PlayerSetPunishmentPoints(0)
  157. end
  158.  
  159. F_MissedClass = function()
  160.   if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
  161.     return
  162.   end
  163.   SetSkippedClass(true)
  164.   StatAddToInt(166)
  165. end
  166.  
  167. F_AttendedCurfew = function()
  168.   if not PedInConversation(gPlayer) and not MissionActive() then
  169.     TextPrintString("You got home in time for curfew", 4)
  170.   end
  171. end
  172.  
  173. F_MissedCurfew = function()
  174.   if not PedInConversation(gPlayer) and not MissionActive() then
  175.     TextPrint("TM_TIRED5", 4, 2)
  176.   end
  177. end
  178.  
  179. F_StartClass = function()
  180.   if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
  181.     return
  182.   end
  183.   F_RingSchoolBell()
  184.   local l_6_0 = PlayerGetPunishmentPoints() + GetSkippingPunishment()
  185. end
  186.  
  187. F_EndClass = function()
  188.   if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
  189.     return
  190.   end
  191.   F_RingSchoolBell()
  192. end
  193.  
  194. F_StartMorning = function()
  195.   F_UpdateTimeCycle()
  196. end
  197.  
  198. F_EndMorning = function()
  199.   F_UpdateTimeCycle()
  200. end
  201.  
  202. F_StartLunch = function()
  203.   if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
  204.     F_UpdateTimeCycle()
  205.     return
  206.   end
  207.   F_UpdateTimeCycle()
  208. end
  209.  
  210. F_EndLunch = function()
  211.   F_UpdateTimeCycle()
  212. end
  213.  
  214. F_StartAfternoon = function()
  215.   F_UpdateTimeCycle()
  216. end
  217.  
  218. F_EndAfternoon = function()
  219.   F_UpdateTimeCycle()
  220. end
  221.  
  222. F_StartEvening = function()
  223.   F_UpdateTimeCycle()
  224. end
  225.  
  226. F_EndEvening = function()
  227.   F_UpdateTimeCycle()
  228. end
  229.  
  230. F_StartCurfew_SlightlyTired = function()
  231.   F_UpdateTimeCycle()
  232. end
  233.  
  234. F_StartCurfew_Tired = function()
  235.   F_UpdateTimeCycle()
  236. end
  237.  
  238. F_StartCurfew_MoreTired = function()
  239.   F_UpdateTimeCycle()
  240. end
  241.  
  242. F_StartCurfew_TooTired = function()
  243.   F_UpdateTimeCycle()
  244. end
  245.  
  246. F_EndCurfew_TooTired = function()
  247.   F_UpdateTimeCycle()
  248. end
  249.  
  250. F_EndTired = function()
  251.   F_UpdateTimeCycle()
  252. end
  253.  
  254. F_Nothing = function()
  255. end
  256.  
  257. F_ClassWarning = function()
  258.   if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
  259.     return
  260.   end
  261.   local l_23_0 = math.random(1, 2)
  262. end
  263.  
  264. F_UpdateTimeCycle = function()
  265.   if not IsMissionCompleated("1_B") then
  266.     local l_24_0 = GetCurrentDay(false)
  267.     if l_24_0 < 0 or l_24_0 > 2 then
  268.       SetCurrentDay(0)
  269.     end
  270.   end
  271.   F_UpdateCurfew()
  272. end
  273.  
  274. F_UpdateCurfew = function()
  275.   local l_25_0 = shared.gCurfewRules
  276.   if not l_25_0 then
  277.     l_25_0 = F_CurfewDefaultRules
  278.   end
  279.   l_25_0()
  280. end
  281.  
  282. F_CurfewDefaultRules = function()
  283.   local l_26_0 = ClockGet()
  284.   if l_26_0 >= 23 or l_26_0 < 7 then
  285.     shared.gCurfew = true
  286.   else
  287.     shared.gCurfew = false
  288.   end
  289. end
Advertisement
Add Comment
Please, Sign In to add comment