Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- CHALKBOARD - UI FRAMEWORK (V1.1)
- -- AUTHOR : ALTAMURENZA
- --[[
- CURRENT FEATURES
- [X] MOD MENU
- [X] QUESTIONARE
- [X] PRINT
- ---> AUTHOR NOTES <---
- any suggestion, bug report, or criticism you can DM me
- on discord or drop your comment in any video of my
- youtube channel.
- suggested version to run with:
- - scholarship edition (pc)
- - anniversary edition (android)
- preview:
- - scholarship edition : https://imgur.com/YWopSWP
- - anniversary edition : https://imgur.com/9rngVWu
- pastebin : pastebin.com/u/Altamurenza
- youtube : youtube.com/c/Altamurenza
- ]]
- ImportScript("SInitGl_data.lua")
- -------------------------------------------------------------------------------
- -- ONE-TOUCH SETTINGS
- -------------------------------------------------------------------------------
- -- shared variables
- shared.CB_Active = false
- shared.CB_Timer = GetTimer()
- shared.CB_Database = {}
- shared.currentMG = nil
- -- global functions
- _G.CB_TypeCheck = function(F, T)
- local S = {
- [1] = "st",
- [2] = "nd",
- [3] = "rd",
- }
- if type(T) == "table" then
- for I, V in ipairs(T) do
- if type(V[1]) ~= V[2] then
- return "- "..(type(F) == "string" and F or "unknown").." -\n\nexpected "..I..""..(S[I] or "th").." argument of type "..V[2]..", got "..type(V[1])
- end
- end
- else
- return "- CB_TypeCheck -\n\nexpected 2"..S[2].." argument of type table, got "..type(T)
- end
- return nil
- end
- _G.CB_IsRunning = function()
- return shared.CB_Active
- end
- _G.CB_IsSafe = function()
- local SAFE = true
- for INT, CODE in ipairs({"MATH", "ART", "CHEM", "MUSIC", "LAWNMOWING", "KEEPUPS", "SHOOT", "ARCADE", "LOCK", "SOCCERP", "BALLTOSS", "STRIKER", "DUNKTANK"}) do
- if MG_IsRunning(CODE) then
- SAFE = false; break
- end
- end
- return SAFE
- end
- _G.CB_MustExit = function()
- if PlayerGetHealth() < 1 or shared.CB_ForceStop or not MinigameIsActive() then
- return true
- end
- if PedIsValid(PedGetGrappleTargetPed(gPlayer)) then
- for INT, NODE in ipairs({"Punishment_Hold", "Tonfa_Impale", "EarGrab", "Adult_Takedown"}) do
- if PedMePlaying(PedGetGrappleTargetPed(gPlayer), NODE) then
- return true
- end
- end
- end
- return false
- end
- _G.CB_ForceStop = function()
- if CB_IsRunning() then
- shared.CB_ForceStop = true
- end
- end
- _G.CB_Register = function(BUTTON, BUTTON_OPTION, BUTTON_OPTION_VAL, TABLE, OPTION)
- local ERROR_MSG = CB_TypeCheck("CB_Register", {
- {BUTTON, "number"}, {BUTTON_OPTION, "number"}, {BUTTON_OPTION_VAL, "number"}, {TABLE, "table"}, {OPTION, "number"}
- })
- if type(ERROR_MSG) ~= "string" then
- if type(shared.CB_Database[BUTTON]) ~= "table" then
- shared.CB_Database[BUTTON] = {}
- end
- BUTTON_OPTION_VAL = (BUTTON_OPTION > 0 and BUTTON_OPTION_VAL < 1) and 1 or BUTTON_OPTION_VAL
- local METHOD = BUTTON_OPTION > 2 and 0 or BUTTON_OPTION
- if type(shared.CB_Database[BUTTON][METHOD]) == "table" then
- if BUTTON_OPTION > 0 and BUTTON_OPTION_VAL > 0 and shared.CB_Database[BUTTON][METHOD].Time ~= nil then
- shared.CB_Database[BUTTON][METHOD].Time = (BUTTON_OPTION == 1 and BUTTON_OPTION_VAL > 2) and 2 or shared.CB_Database[BUTTON][METHOD].Time
- end
- else
- shared.CB_Database[BUTTON][METHOD] = {}
- if BUTTON_OPTION > 0 and BUTTON_OPTION_VAL > 0 then
- shared.CB_Database[BUTTON][METHOD].Time = (BUTTON_OPTION == 1 and BUTTON_OPTION_VAL > 2) and 2 or BUTTON_OPTION_VAL
- end
- end
- if type(shared.CB_Database[BUTTON][METHOD].Table) ~= "table" then
- shared.CB_Database[BUTTON][METHOD].Table = {}
- end
- for I = 1, table.getn(TABLE) do
- table.insert(shared.CB_Database[BUTTON][METHOD].Table, TABLE[I])
- end
- if type(shared.CB_Database[BUTTON][METHOD].Option) ~= "number" then
- shared.CB_Database[BUTTON][METHOD].Option = OPTION
- end
- else
- TextPrintString(ERROR_MSG, 5, 2)
- end
- end
- _G.CB_Start = function(T, S, W, R)
- MinigameCreate("MATH", false)
- while not MinigameIsReady() do
- Wait(0)
- end
- PlayerWeaponHudLock(true)
- HUDSaveVisibility()
- HUDClearAllElements()
- MinigameStart()
- ClassMathSetNumQuestions(99999999)
- if type(S) == "boolean" then
- if S then
- _G.ClassMathSetEquation("'"..T.."'", 4, 4, W, "", "", R)
- else
- _G.ClassMathSetEquation(T, 4, 3, "", W, R, "")
- end
- elseif type(S) == "table" then
- _G.ClassMathSetEquation(T, unpack(S))
- end
- ClassMathSetTimer(99999999)
- MinigameEnableHUD(true)
- end
- _G.CB_End = function(T)
- ClassMathFinished()
- while MinigameIsActive() do
- Wait(0)
- end
- HUDRestoreVisibility()
- PlayerWeaponHudLock(false)
- MinigameEnableHUD(false)
- if shared.currentMG == nil then
- MinigameDestroy()
- for INT, CODE in ipairs({"2_R11_Chad", "2_R11_Bryce", "2_R11_Justin", "2_R11_Parker", "2_R11_Random"}) do
- if MissionActiveSpecific(CODE) then
- HUDSetFightStyle()
- break
- end
- end
- end
- if shared.CB_ForceStop then
- shared.CB_ForceStop = nil
- end
- if T then
- _G.TERMINATE_NAV = true
- end
- shared.CB_Active = false
- end
- _G.CB_Run = function(B, M, T)
- if CB_IsRunning() == false and CB_IsSafe() then
- -- create MG
- CB_Start(shared.CB_Database[B][M].Table[shared.CB_Database[B][M].Option].Name, true, "PREV", "NEXT")
- -- new thread
- _G.CB_Nav = function()
- local BUTTON, METHOD, TIMER, EXIT = B, M, T, false
- while true do
- if CB_IsRunning() then
- -- next
- if ClassMathValidAnswer() then
- shared.CB_Database[BUTTON][METHOD].Option = shared.CB_Database[BUTTON][METHOD].Option + 1 > table.getn(shared.CB_Database[BUTTON][METHOD].Table) and 1 or shared.CB_Database[BUTTON][METHOD].Option + 1
- while shared.CB_Database[BUTTON][METHOD].Table[shared.CB_Database[BUTTON][METHOD].Option].Name == "" do
- shared.CB_Database[BUTTON][METHOD].Option = shared.CB_Database[BUTTON][METHOD].Option + 1 > table.getn(shared.CB_Database[BUTTON][METHOD].Table) and 1 or shared.CB_Database[BUTTON][METHOD].Option + 1
- end
- _G.ClassMathSetEquation("'"..shared.CB_Database[BUTTON][METHOD].Table[shared.CB_Database[BUTTON][METHOD].Option].Name.."'", 4, 4, "PREV", "", "", "NEXT")
- shared.CB_Timer = GetTimer() + (TIMER * 1000)
- end
- -- prev
- if ClassMathInvalidAnswer() then
- shared.CB_Database[BUTTON][METHOD].Option = shared.CB_Database[BUTTON][METHOD].Option - 1 < 1 and table.getn(shared.CB_Database[BUTTON][METHOD].Table) or shared.CB_Database[BUTTON][METHOD].Option - 1
- while shared.CB_Database[BUTTON][METHOD].Table[shared.CB_Database[BUTTON][METHOD].Option].Name == "" do
- shared.CB_Database[BUTTON][METHOD].Option = shared.CB_Database[BUTTON][METHOD].Option - 1 < 1 and table.getn(shared.CB_Database[BUTTON][METHOD].Table) or shared.CB_Database[BUTTON][METHOD].Option - 1
- end
- _G.ClassMathSetEquation("'"..shared.CB_Database[BUTTON][METHOD].Table[shared.CB_Database[BUTTON][METHOD].Option].Name.."'", 4, 4, "PREV", "", "", "NEXT")
- shared.CB_Timer = GetTimer() + (TIMER * 1000)
- end
- -- confirm
- if shared.CB_Timer < GetTimer() and not EXIT then
- if shared.CB_Database[BUTTON][METHOD].Table[shared.CB_Database[BUTTON][METHOD].Option].Func then
- local CONFIRM = CB_Ask("# CONFIRM SELECTION #", "NO", "YES")
- if type(CONFIRM) == "number" and CONFIRM == 1 and type(shared.CB_Database[BUTTON][METHOD].Table[shared.CB_Database[BUTTON][METHOD].Option].Func) == "function" then
- shared.CB_Database[BUTTON][METHOD].Table[shared.CB_Database[BUTTON][METHOD].Option].Func(shared.CB_Database[BUTTON][METHOD].Table, shared.CB_Database[BUTTON][METHOD].Option)
- EXIT = true
- else
- if type(CONFIRM) == "number" then
- local RETURN = CB_Ask("# EXIT OR RETURN #", "EXIT", "RETURN")
- if type(RETURN) == "number" and RETURN == 1 then
- shared.CB_Timer = GetTimer() + (TIMER * 1000)
- else
- EXIT = true
- end
- else
- EXIT = true
- end
- end
- else
- EXIT = true
- end
- end
- -- exit
- if CB_MustExit() or EXIT then
- CB_End(true)
- end
- else
- break
- end
- Wait(0)
- end
- end
- -- set shared var
- shared.CB_Timer = GetTimer() + (T * 1000)
- shared.CB_Active = true
- -- set selection
- shared.CB_Thread = CreateThread("CB_Nav")
- else
- SoundPlay2D("WrongBtn")
- end
- end
- _G.CB_Ask = function(T, W, R)
- -- answer
- local FINAL_ANSWER = nil
- -- start up
- local LAST_QUESTION = nil
- if not CB_IsRunning() then
- CB_Start(T, false, W, R)
- shared.CB_Active = true
- else
- LAST_QUESTION = ClassMathGetEquation()
- _G.ClassMathSetEquation(T, 4, 3, "", W, R, "")
- end
- -- create loop
- while true do
- Wait(0)
- if CB_IsRunning() then
- if ClassMathValidAnswer() then
- FINAL_ANSWER = 1; break
- end
- if ClassMathInvalidAnswer() then
- FINAL_ANSWER = 0; break
- end
- if CB_MustExit() then
- break
- end
- else
- break
- end
- end
- -- exit / go back
- if LAST_QUESTION ~= nil and table.getn(LAST_QUESTION) > 0 then
- _G.ClassMathSetEquation(unpack(LAST_QUESTION))
- else
- CB_End()
- end
- -- return
- return FINAL_ANSWER
- end
- _G.CB_Quiz = function(T, S, R)
- -- checking arguments
- local ERROR = CB_TypeCheck("CB_Quiz", {{T, "table"}, {S, "number"}, {R, "boolean"}})
- if type(ERROR) ~= "string" then
- if CB_IsRunning() == false and CB_IsSafe() then
- -- randoming quiz
- if R == true then
- local TT = {}
- for I = 1, table.getn(T) do
- table.insert(TT, T[I])
- end
- local NT = {}
- repeat
- local I = math.random(1, table.getn(TT))
- if TT[I] then table.insert(NT, TT[I]); table.remove(TT, I) end
- Wait(0)
- until table.getn(TT) <= 0
- T = NT
- end
- -- setup
- local O, A = {}, false
- CB_Start(T[S].Question, {table.getn(T[S].Choice), T[S].Answer, unpack(T[S].Choice)})
- -- loop
- while true do
- Wait(0)
- if not MinigameIsActive() then break end
- if ClassMathValidAnswer() then
- O[S], A = true, true
- end
- if ClassMathInvalidAnswer() then
- O[S], A = false, true
- end
- if A then
- S = S + 1
- if S > table.getn(T) then
- break
- end
- _G.ClassMathSetEquation(T[S].Question, table.getn(T[S].Choice), T[S].Answer, unpack(T[S].Choice))
- A = false
- end
- end
- -- cleanup
- CB_End()
- -- report
- local C = 0
- for I = 1, table.getn(O) do
- if O[I] then
- C = C + 1
- end
- end
- return tonumber(string.format("%.1f", (C / table.getn(T)) * 100))
- else
- SoundPlay2D("WrongBtn")
- end
- else
- TextPrintString(ERROR, 5, 2)
- end
- return nil
- end
- _G.CB_Print = function(T, S)
- -- checking arguments
- local ERROR = CB_TypeCheck("CB_Print", {{T, "string"}, {S, "number"}})
- if type(ERROR) ~= "string" then
- if CB_IsRunning() == false and CB_IsSafe() and S > 0.0 then
- -- start
- local TIMER, COUNT = GetTimer(), S
- CB_Start(T, {3, 2, "", "< "..string.format("%.1f", COUNT).."s >", ""})
- -- loop
- while true do
- Wait(0)
- if TIMER + 100 < GetTimer() then
- COUNT = COUNT - 0.1
- _G.ClassMathSetEquation(T, 3, 2, "", "< "..string.format("%.1f", COUNT).."s >", "")
- TIMER = GetTimer()
- end
- if COUNT <= 0.0 or ClassMathValidAnswer() or not MinigameIsActive() then
- break
- end
- end
- -- end
- CB_End()
- else
- SoundPlay2D("WrongBtn")
- end
- else
- TextPrintString(ERROR, 5, 2)
- end
- end
- _G.CBP = _G.ClothingBuildPlayer
- _G.ClothingBuildPlayer = function()
- -- main thread
- if not shared.CB_Coroutine then
- _G.CB_Coroutine = function()
- local YIELD = false
- local Wait = function(MS)
- if YIELD == true then coroutine.yield(MS)
- else
- _G.Wait(MS)
- end
- end
- while true do
- local THREAD, STATUS, RESULT = coroutine.create(
- function()
- local BUTTON = {}
- for ID = 0, 15 do
- if ID == 9 then
- if type(_G.ClassMusicSetPlayers) == "function" then
- BUTTON[9] = {GetTimer(), GetTimer(), GetTimer()}
- end
- else
- BUTTON[ID] = {GetTimer(), GetTimer(), GetTimer()}
- end
- end
- BUTTON[24] = {GetTimer(), GetTimer(), GetTimer()}
- while true do
- Wait(0)
- if not CB_IsRunning() then
- for B, T in pairs(BUTTON) do
- if IsButtonBeingPressed(B, 0) and type(shared.CB_Database[B]) == "table" then
- if type(shared.CB_Database[B][0]) == "table" then
- CB_Run(B, 0, 3)
- else
- if T[1] and GetTimer() < T[1] + 500 then
- if type(shared.CB_Database[B][1]) == "table" and shared.CB_Database[B][1].Time == 1 then
- CB_Run(B, 1, 3)
- end
- if T[2] and GetTimer() < T[2] + 500 then
- if type(shared.CB_Database[B][1]) == "table" and shared.CB_Database[B][1].Time == 2 then
- CB_Run(B, 1, 3)
- end
- else
- T[2] = GetTimer()
- end
- else
- T[1] = GetTimer()
- end
- end
- end
- if IsButtonPressed(B, 0) and type(shared.CB_Database[B]) == "table" then
- if type(shared.CB_Database[B][2]) == "table" and shared.CB_Database[B][2].Time then
- if T[3] + (shared.CB_Database[B][2].Time * 1000) <= GetTimer() then
- CB_Run(B, 2, 3); T[3] = GetTimer()
- end
- end
- else
- T[3] = GetTimer()
- end
- end
- if _G.TERMINATE_NAV and shared.CB_Thread then
- TerminateThread(shared.CB_Thread); shared.CB_Thread = nil
- _G.TERMINATE_NAV = false
- end
- end
- end
- end
- )
- while coroutine.status(THREAD) == "suspended" do
- YIELD = true
- if YIELD == true then
- STATUS, RESULT = coroutine.resume(THREAD)
- end
- YIELD = false
- _G.Wait(RESULT)
- end
- end
- end
- shared.CB_Coroutine = CreateThread("CB_Coroutine")
- end
- -- do function!
- _G.CBP()
- end
- -------------------------------------------------------------------------------
- -- FLEXIBLE SETTINGS
- -------------------------------------------------------------------------------
- shared.CBUI_Database = {}
- _G.CBUI_Show = function(TIME)
- if not CBUI_IsActive() then
- MinigameCreate("MATH", false)
- repeat
- Wait(0)
- until MinigameIsReady()
- shared.CBUI_Database.STR_Time = TIME or 4
- HUDSaveVisibility()
- HUDClearAllElements()
- MinigameStart()
- ClassMathSetNumQuestions(99999999)
- CBUI_Update()
- ClassMathSetTimer(99999999)
- MinigameEnableHUD(true)
- shared.CBUI_Active = true
- else
- SoundPlay2D("WrongBtn")
- end
- end
- _G.CBUI_1 = function()
- if CBUI_IsActive() then
- if CBUI_ExitViaSpace() then
- CBUI_Close()
- return true
- end
- return ClassMathValidAnswer()
- end
- return false
- end
- _G.CBUI_Select = function()
- if CBUI_IsActive() then
- return shared.CBUI_Database.Time < GetTimer()
- end
- return false
- end
- _G.CBUI_0 = function()
- if CBUI_IsActive() then
- return ClassMathInvalidAnswer()
- end
- return false
- end
- _G.CBUI_Close = function()
- if CBUI_IsActive() then
- ClassMathFinished()
- while MinigameIsActive() do
- Wait(0)
- end
- HUDRestoreVisibility()
- MinigameEnableHUD(false)
- MinigameDestroy()
- shared.CBUI_Database.Text = nil
- shared.CBUI_Database.Option = nil
- shared.CBUI_Database.OptionTrue = nil
- shared.CBUI_Database.Time = nil
- shared.CBUI_Active = false
- end
- end
- _G.CBUI_Update = function()
- if shared.CBUI_Database.Text or shared.CBUI_Database.Option then
- local TEXT = shared.CBUI_Database.Text or ""
- local OPTION = type(shared.CBUI_Database.Option) == "table" and {
- table.getn(shared.CBUI_Database.Option), shared.CBUI_Database.OptionTrue, unpack(shared.CBUI_Database.Option)
- } or {3, 2, "", "", ""}
- ClassMathSetEquation(TEXT, unpack(OPTION))
- shared.CBUI_Database.Time = GetTimer() + (shared.CBUI_Database.STR_Time * 1000)
- else
- SoundPlay2D("WrongBtn")
- end
- end
- _G.CBUI_SetText = function(TEXT)
- shared.CBUI_Database.Text = TEXT
- if CBUI_IsActive() then
- CBUI_Update()
- end
- end
- _G.CBUI_GetText = function()
- return shared.CBUI_Database.Text or ""
- end
- _G.CBUI_SetOption = function(TABLE, TRUE_ID)
- if table.getn(TABLE) >= 3 and TRUE_ID <= table.getn(TABLE) then
- shared.CBUI_Database.Option, shared.CBUI_Database.OptionTrue = TABLE, TRUE_ID
- if CBUI_IsActive() then
- CBUI_Update()
- end
- else
- SoundPlay2D("WrongBtn")
- end
- end
- _G.CBUI_GetOption = function()
- return shared.CBUI_Database.Option and shared.CBUI_Database.Option, shared.CBUI_Database.OptionTrue or {"", "", ""}, 2
- end
- _G.CBUI_IsActive = function()
- return shared.CBUI_Active or false
- end
- _G.CBUI_ExitViaSpace = function()
- return not MinigameIsActive()
- end
- -------------------------------------------------------------------------------
- -- EXECUTABLE & TRIGGER
- -------------------------------------------------------------------------------
- _G.ClassMathGetEquation = function()
- return shared.gClassMathLastEquation or {}
- end
- _G.CMSE = _G.ClassMathSetEquation
- _G.ClassMathSetEquation = function(A, B, C, D, E, F, G, H)
- shared.gClassMathLastEquation = {A, B, C, D, E, F, G, H}
- -- do function!
- _G.CMSE(A, B, C, D, E, F, G, H)
- end
- _G.MG_IsRunning = function(CODE)
- return (type(shared.currentMG) == "string" and shared.currentMG == CODE) and true or false
- end
- _G.MGC = _G.MinigameCreate
- _G.MinigameCreate = function(CODE, TF)
- -- stopping CB
- if CB_IsRunning() then
- CB_ForceStop()
- repeat
- Wait(0)
- until shared.CB_Thread == nil
- end
- -- new condition
- if CODE ~= "MATH" then
- shared.currentMG = CODE
- end
- -- do function!
- _G.MGC(CODE, TF)
- end
- _G.MGD = _G.MinigameDestroy
- _G.MinigameDestroy = function()
- -- reset condition
- if shared.currentMG ~= nil then
- shared.currentMG = nil
- end
- -- do function!
- _G.MGD()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement