Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function main()
- -- Test table:
- local testTable = {0,1,2,3} -- for testing the "Dynamic Number" option where the max selection is table size.
- -- Set up menus:
- testMenu = {"Main Menu",1,{
- {"Simple Function",function() PlayerAddMoney(10000) end},
- {"Toggle Function",false,function(toggle)
- if toggle then
- GameSetPedStat(gPlayer,20,200)
- else
- GameSetPedStat(gPlayer,20,100)
- end
- end},
- {"Number Function",1,1,5,function(num) TextPrintString("Number: "..num,3,2) end},
- {"Option Function",1,{"SpudG","Rocket Launcher"},false,nil,function(weap)
- if weap == 1 then
- PlayerSetWeapon(305,8)
- elseif weap == 2 then
- PlayerSetWeapon(307,12)
- end
- end},
- {"Sub Menu",1,{
- {"Nothing"},
- }},
- {"Dynamic Number",1,1,testTable,function(num) TextPrintString("Number: "..num,3,2) end},
- }}
- menus = {testMenu}
- menuActive = false
- -- Main loop:
- while true do
- -- Process menu:
- if menuActive then
- PlayerSetControl(0)
- local menu = menus[table.getn(menus)]
- local t = F_GetOptionType(menu[3][menu[2]])
- local text = menu[1].."\n\n"
- for i = menu[2] - 2,menu[2] + 2 do
- if i == menu[2] then
- text = text..">"
- end
- if i >= 1 and i <= table.getn(menu[3]) then
- local t = F_GetOptionType(menu[3][i])
- text = text..menu[3][i][1]
- if t == "toggle" then
- text = text.." ["..((menu[3][i][2] and "ON") or "OFF").."]"
- elseif t == "numopt" or t == "dynopt" then
- text = text.." <"..menu[3][i][2]..">"
- elseif t == "stropt" then
- text = text.." <"..menu[3][i][3][menu[3][i][2]]..">"
- end
- end
- text = text.."\n"
- end
- TextPrintString(text,0,1)
- Wait(0)
- if IsButtonBeingPressed(2,0) then
- SoundPlay2D("ButtonUp")
- menu[2] = menu[2] - 1
- if menu[2] < 1 then
- menu[2] = table.getn(menu[3])
- end
- elseif IsButtonBeingPressed(3,0) then
- SoundPlay2D("ButtonUp")
- menu[2] = menu[2] + 1
- if menu[2] > table.getn(menu[3]) then
- menu[2] = 1
- end
- elseif IsButtonBeingPressed(0,0) and type(menu[3][menu[2]][2]) == "number" then
- SoundPlay2D("ButtonUp")
- local minimum = (t == "stropt" and 1) or menu[3][menu[2]][3]
- 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]
- menu[3][menu[2]][2] = menu[3][menu[2]][2] - 1
- if menu[3][menu[2]][2] < minimum then
- menu[3][menu[2]][2] = maximum
- end
- if menu[3][menu[2]][5] then
- menu[3][menu[2]][5](menu[3][menu[2]][2])
- end
- elseif IsButtonBeingPressed(1,0) and type(menu[3][menu[2]][2]) == "number" then
- SoundPlay2D("ButtonUp")
- local minimum = (t == "stropt" and 1) or menu[3][menu[2]][3]
- 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]
- menu[3][menu[2]][2] = menu[3][menu[2]][2] + 1
- if menu[3][menu[2]][2] > maximum then
- menu[3][menu[2]][2] = minimum
- end
- if menu[3][menu[2]][5] then
- menu[3][menu[2]][5](menu[3][menu[2]][2])
- end
- elseif IsButtonBeingPressed(7,0) then
- SoundPlay2D("ButtonUp")
- if t == "simple" and menu[3][menu[2]][2] then
- menu[3][menu[2]][2]()
- elseif t == "toggle" then
- menu[3][menu[2]][2] = not menu[3][menu[2]][2]
- if menu[3][menu[2]][3] then
- menu[3][menu[2]][3](menu[3][menu[2]][2])
- end
- elseif t == "numopt" or t == "dynopt" or (t == "stropt" and not menu[3][menu[2]][4]) then
- 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]
- if menu[3][menu[2]][2] > maximum then
- menu[3][menu[2]][2] = maximum
- end
- if menu[3][menu[2]][6] and (t ~= "dynopt" or menu[3][menu[2]][2] >= menu[3][menu[2]][3]) then
- menu[3][menu[2]][6](menu[3][menu[2]][2])
- end
- elseif t == "stropt" then
- if menu[3][menu[2]][6] then
- menu[3][menu[2]][6](menu[3][menu[2]][3][menu[3][menu[2]][2]])
- end
- elseif t == "submen" then
- table.insert(menus,menu[3][menu[2]])
- end
- elseif IsButtonBeingPressed(8,0) then
- SoundPlay2D("ButtonDown")
- if table.getn(menus) > 1 then
- table.remove(menus)
- else
- menuActive = false
- PlayerSetControl(1)
- end
- end
- else
- Wait(0)
- if IsButtonBeingPressed(3,0) then
- menuActive = true
- end
- end
- end
- end
- function F_GetOptionType(option)
- if type(option[2]) == "function" then
- return "simple"
- elseif type(option[2]) == "boolean" then
- return "toggle"
- elseif type(option[3]) == "number" and type(option[4]) == "number" then
- return "numopt"
- elseif type(option[3]) == "number" and type(option[4]) == "table" then
- return "dynopt"
- elseif type(option[3]) == "table" and type(option[4]) == "boolean" then
- return "stropt"
- elseif type(option[2]) == "number" and type(option[3]) == "table" then
- return "submen"
- end
- end
- -- STimeCycle functions:
- F_AttendedClass = function()
- if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
- return
- end
- SetSkippedClass(false)
- PlayerSetPunishmentPoints(0)
- end
- F_MissedClass = function()
- if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
- return
- end
- SetSkippedClass(true)
- StatAddToInt(166)
- end
- F_AttendedCurfew = function()
- if not PedInConversation(gPlayer) and not MissionActive() then
- TextPrintString("You got home in time for curfew", 4)
- end
- end
- F_MissedCurfew = function()
- if not PedInConversation(gPlayer) and not MissionActive() then
- TextPrint("TM_TIRED5", 4, 2)
- end
- end
- F_StartClass = function()
- if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
- return
- end
- F_RingSchoolBell()
- local l_6_0 = PlayerGetPunishmentPoints() + GetSkippingPunishment()
- end
- F_EndClass = function()
- if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
- return
- end
- F_RingSchoolBell()
- end
- F_StartMorning = function()
- F_UpdateTimeCycle()
- end
- F_EndMorning = function()
- F_UpdateTimeCycle()
- end
- F_StartLunch = function()
- if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
- F_UpdateTimeCycle()
- return
- end
- F_UpdateTimeCycle()
- end
- F_EndLunch = function()
- F_UpdateTimeCycle()
- end
- F_StartAfternoon = function()
- F_UpdateTimeCycle()
- end
- F_EndAfternoon = function()
- F_UpdateTimeCycle()
- end
- F_StartEvening = function()
- F_UpdateTimeCycle()
- end
- F_EndEvening = function()
- F_UpdateTimeCycle()
- end
- F_StartCurfew_SlightlyTired = function()
- F_UpdateTimeCycle()
- end
- F_StartCurfew_Tired = function()
- F_UpdateTimeCycle()
- end
- F_StartCurfew_MoreTired = function()
- F_UpdateTimeCycle()
- end
- F_StartCurfew_TooTired = function()
- F_UpdateTimeCycle()
- end
- F_EndCurfew_TooTired = function()
- F_UpdateTimeCycle()
- end
- F_EndTired = function()
- F_UpdateTimeCycle()
- end
- F_Nothing = function()
- end
- F_ClassWarning = function()
- if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
- return
- end
- local l_23_0 = math.random(1, 2)
- end
- F_UpdateTimeCycle = function()
- if not IsMissionCompleated("1_B") then
- local l_24_0 = GetCurrentDay(false)
- if l_24_0 < 0 or l_24_0 > 2 then
- SetCurrentDay(0)
- end
- end
- F_UpdateCurfew()
- end
- F_UpdateCurfew = function()
- local l_25_0 = shared.gCurfewRules
- if not l_25_0 then
- l_25_0 = F_CurfewDefaultRules
- end
- l_25_0()
- end
- F_CurfewDefaultRules = function()
- local l_26_0 = ClockGet()
- if l_26_0 >= 23 or l_26_0 < 7 then
- shared.gCurfew = true
- else
- shared.gCurfew = false
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment