Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ui_timetosave = 5000 -- Time to save after a setting gets changed, get's reset if another setting gets saved in the same time, see saveTime() --
- Exp_Funct = { -- Exported functions
- ["trafficsensor"] = {
- res = "race_traffic_sensor",
- ["true"] = 'exports["race_traffic_sensor"].showTrafficSensor()',
- ["false"] = 'exports["race_traffic_sensor"].hideTrafficSensor()'},
- ["checkpointdelay"] = {
- res = "race_delay_indicator",
- ["true"] = 'exports["race_delay_indicator"].showCPDelays()',
- ["false"] = 'exports["race_delay_indicator"].hideCPDelays()'},
- ["chatbubbles"] = {
- res = "chaticon",
- ["true"] = 'exports["chaticon"].showChaticon()',
- ["false"] = 'exports["chaticon"].hideChaticon()'},
- ["floatingmessages"] = {
- res = "messages",
- ["true"] = 'exports["messages"].showFloatMessages()',
- ["false"] ='exports["messages"].hideFloatMessages()'},
- ["timeleft"] = {
- ["true"] = 'timeleft_on()',
- ["false"] = 'timeleft_off()'},
- ["fpscounter"] = {
- res = "fpstabandonscreen",
- ["true"] = 'exports["fpstabandonscreen"].e_showFPS()',
- ["false"] = 'exports["fpstabandonscreen"].e_hideFPS()'},
- ["customnametags"] = {
- ["true"] = 'CustomNameTags_on',
- ["false"] = 'CustomNameTags_off'},
- ["speed-o-metermode"] = {
- res = "digitalspeedometer",
- [1] = 'exports["digitalspeedometer"].setKMH()',
- [2] = 'exports["digitalspeedometer"].setMPH()',
- [3] = 'exports["digitalspeedometer"].setNone()'},
- ["hudmode"] = {
- res = "racesphud",
- [1] = 'exports["racesphud"].e_showNewhud()',
- [2] = 'exports["racesphud"].e_showSPhud()',
- [3] = 'exports["racesphud"].e_showOldhud()'},
- ["speclist"] = {
- res = "spectatorslist",
- ["true"] = 'exports["spectatorslist"].specliston()',
- ["false"] = 'exports["spectatorslist"].speclistoff()'},
- ["zonename"] = {
- res = "showarea",
- ["true"] = 'exports["showarea"].zoneon()',
- ["false"] = 'exports["showarea"].zoneoff()'},
- ["coins"] = {
- res = "scoringsystem",
- ["true"] = 'exports["scoringsystem"].showcoins()',
- ["false"] = 'exports["scoringsystem"].hidecoins()'},
- ["gear"] = {
- res = "gearsdisplay",
- ["true"] = 'exports["gearsdisplay"].gearon()',
- ["false"] = 'exports["gearsdisplay"].gearoff()'},
- ["clockdate"] = {
- res = "realtimeanddate",
- ["true"] = 'exports["realtimeanddate"].showtimedate()',
- ["false"] = 'exports["realtimeanddate"].hidetimedate()'},
- ["players"] = {
- res = "onlineplayers",
- ["true"] = 'exports["onlineplayers"].showplayers()',
- ["false"] = 'exports["onlineplayers"].hideplayers()'},
- ["playerpos"] = {
- res = "playerposition",
- ["true"] = 'exports["playerposition"].showpos()',
- ["false"] = 'exports["playerposition"].hidepos()'},
- ["nextmap"] = {
- res = "nextmap",
- ["true"] = 'exports["nextmap"].shownextmap()',
- ["false"] = 'exports["nextmap"].hidenextmap()'},
- ["siteinfo"] = {
- res = "siteinfo",
- ["true"] = 'exports["siteinfo"].showinfo()',
- ["false"] = 'exports["siteinfo"].hideinfo()'},
- ["top1bar"] = {
- res = "race_toptimes",
- ["true"] = 'exports["race_toptimes"].showtopbar()',
- ["false"] = 'exports["race_toptimes"].hidetopbar()'},
- ["classicprogressbar"] = {
- res = "raceprogressbar",
- ["true"] = 'exports["raceprogressbar"].onswitch()',
- ["false"] = 'exports["raceprogressbar"].offswitch()'},
- ["modernprogressbar"] = {
- res = "race",
- ["true"] = 'exports["race"].shownewbar()',
- ["false"] = 'exports["race"].hidenewbar()'},
- ["gtavradar"] = {
- res = "gtavradar",
- ["true"] = 'exports["gtavradar"].radaron()',
- ["false"] = 'exports["gtavradar"].radaroff()'},
- }
- -- Reapply settings when one of these resources (re)starts
- local UI_reApplyTimer = false
- -- Add resource name here when used
- local resetResource = {"race_sphud","speed-o-meter","fpstabandonscreen","race_sphud","messages","gus","race_delay_indicator","mapratings","race_traffic_sensor","race_rank","race"}
- addEventHandler("onClientResourceStart",root,
- function(res)
- local resName = getResourceName(res)
- for _,rn in ipairs(resetResource) do
- if rn == resName then
- -- Timer system so no settings spam
- if isTimer(UI_reApplyTimer) then killTimer(UI_reApplyTimer) end
- UI_reApplyTimer = setTimer(function() updateUIgui() executeHUDSettings() end,5000,1)
- break
- end
- end
- end
- )
- UI = { -- Default settings--
- ["trafficsensor"] = true ,
- ["checkpointdelay"] = true ,
- ["chatbubbles"] = true ,
- ["floatingmessages"] = true ,
- ["fpscounter"] = true ,
- ["customnametags"] = true ,
- ["speed-o-metermode"] = 1 ,
- ["hudmode"] = 1 ,
- ["timeleft"] = true ,
- ["speclist"] = true ,
- ["zonename"] = true ,
- ["coins"] = true ,
- ["gear"] = true ,
- ["clockdate"] = true ,
- ["players"] = true ,
- ["playerpos"] = true ,
- ["nextmap"] = true ,
- ["siteinfo"] = true ,
- ["top1bar"] = true ,
- ["classicprogressbar"] = true ,
- ["modernprogressbar"] = true ,
- ["gtavradar"] = true ,
- }
- -- speed-o-metermode: 1 = "km/h", 2="mph", 3="none"
- -- hudmode: 1 = new HUD, 2 = sphud, 3 = old hud
- function ui_ClickHandler()
- if source == GUIEditor.button[5] then
- exports["vehiclelights"].startGui()
- elseif source == GUIEditor.button[6] then
- exports["carcolorpicker"].openColorPicker()
- elseif source == GUIEditor.button[7] then
- exports["paintjobs"].startGui()
- elseif source == GUIEditor.button[8] then
- exports["neon"].hideGui()
- elseif source == GUIEditor.button[9] then
- exports["skins"].sendOpenRequestForServer()
- elseif source == GUIEditor.button[10] then
- exports["raceprogressbar"].toggleGui()
- elseif source == GUIEditor.button[11] then
- exports["raceplayerstatsgui"].toggleStatsWindow()
- -- Toggle Traffic Sensor
- elseif source == GUIEditor.checkbox[7] then
- saveTime()
- if guiCheckBoxGetSelected( source ) then
- exports["race_traffic_sensor"].showTrafficSensor()
- UI["trafficsensor"] = true
- else
- exports["race_traffic_sensor"].hideTrafficSensor()
- UI["trafficsensor"] = false
- end
- -- Toggle CP Delays
- elseif source == GUIEditor.checkbox[10] then
- saveTime()
- if guiCheckBoxGetSelected( source ) then
- exports["race_delay_indicator"].showCPDelays()
- UI["checkpointdelay"] = true
- else
- exports["race_delay_indicator"].hideCPDelays()
- UI["checkpointdelay"] = false
- end
- -- Toggle Float messages
- elseif source == GUIEditor.checkbox[12] then
- saveTime()
- if guiCheckBoxGetSelected( source ) then
- exports["messages"].showFloatMessages()
- UI["floatingmessages"] = true
- else
- exports["messages"].hideFloatMessages()
- UI["floatingmessages"] = false
- end
- -- Toggle Custom NameTags
- elseif source == customNameTagsCheckBox then
- saveTime()
- if guiCheckBoxGetSelected( source ) then
- triggerEvent("toggleNameTags",root,true)
- UI["customnametags"] = true
- else
- triggerEvent("toggleNameTags",root,false)
- UI["customnametags"] = false
- end
- -- Toggle SpecList
- elseif source == GUIEditor.checkbox[99] then
- saveTime()
- if guiCheckBoxGetSelected( source ) then
- exports["spectatorslist"].specliston()
- UI["speclist"] = true
- else
- exports["spectatorslist"].speclistoff()
- UI["speclist"] = false
- end
- -- Toggle Zone Info
- elseif source == GUIEditor.checkbox[98] then
- saveTime()
- if guiCheckBoxGetSelected( source ) then
- exports["showarea"].zoneon()
- UI["zonename"] = true
- else
- exports["showarea"].zoneoff()
- UI["zonename"] = false
- end
- -- Toggle KnightCoins Window
- elseif source == GUIEditor.checkbox[97] then
- saveTime()
- if guiCheckBoxGetSelected( source ) then
- exports["scoringsystem"].showcoins()
- UI["coins"] = true
- else
- exports["scoringsystem"].hidecoins()
- UI["coins"] = false
- end
- -- Toggle Current Gear Display
- elseif source == GUIEditor.checkbox[96] then
- saveTime()
- if guiCheckBoxGetSelected( source ) then
- exports["gearsdisplay"].gearon()
- UI["gear"] = true
- else
- exports["gearsdisplay"].gearoff()
- UI["gear"] = false
- end
- -- Toggle Clock/Date Display
- elseif source == GUIEditor.checkbox[95] then
- saveTime()
- if guiCheckBoxGetSelected( source ) then
- exports["realtimeanddate"].showtimedate()
- UI["clockdate"] = true
- else
- exports["realtimeanddate"].hidetimedate()
- UI["clockdate"] = false
- end
- -- Toggle Player Count Display
- elseif source == GUIEditor.checkbox[94] then
- saveTime()
- if guiCheckBoxGetSelected( source ) then
- exports["onlineplayers"].showplayers()
- UI["players"] = true
- else
- exports["onlineplayers"].hideplayers()
- UI["players"] = false
- end
- -- Toggle FPS & Ping Display
- elseif source == GUIEditor.checkbox[15] then
- saveTime()
- if guiCheckBoxGetSelected( source ) then
- exports["fpstabandonscreen"].e_showFPS()
- UI["fpscounter"] = true
- else
- exports["fpstabandonscreen"].e_hideFPS()
- UI["fpscounter"] = false
- end
- -- Toggle Player Position Box
- elseif source == GUIEditor.checkbox[93] then
- saveTime()
- if guiCheckBoxGetSelected( source ) then
- exports["playerposition"].showpos()
- UI["playerpos"] = true
- else
- exports["playerposition"].hidepos()
- UI["playerpos"] = false
- end
- -- Toggle Next Map Window
- elseif source == GUIEditor.checkbox[92] then
- saveTime()
- if guiCheckBoxGetSelected( source ) then
- exports["nextmap"].shownextmap()
- UI["nextmap"] = true
- else
- exports["nextmap"].hidenextmap()
- UI["nextmap"] = false
- end
- -- Toggle Site/IRC Info
- elseif source == GUIEditor.checkbox[91] then
- saveTime()
- if guiCheckBoxGetSelected( source ) then
- exports["siteinfo"].showinfo()
- UI["siteinfo"] = true
- else
- exports["siteinfo"].hideinfo()
- UI["siteinfo"] = false
- end
- -- Toggle Top1 Bar
- elseif source == GUIEditor.checkbox[90] then
- saveTime()
- if guiCheckBoxGetSelected( source ) then
- exports["race_toptimes"].showtopbar()
- UI["top1bar"] = true
- else
- exports["race_toptimes"].hidetopbar()
- UI["top1bar"] = false
- end
- -- Toggle Classic Progressbar
- elseif source == GUIEditor.checkbox[89] then
- saveTime()
- if guiCheckBoxGetSelected( source ) then
- exports["raceprogressbar"].onswitch()
- UI["classicprogressbar"] = true
- else
- exports["raceprogressbar"].offswitch()
- UI["classicprogressbar"] = false
- end
- -- Toggle Modern Progressbar
- elseif source == GUIEditor.checkbox[88] then
- saveTime()
- if guiCheckBoxGetSelected( source ) then
- exports["race"].shownewbar()
- UI["modernprogressbar"] = true
- else
- exports["race"].hidenewbar()
- UI["modernprogressbar"] = false
- end
- -- Toggle GTA V Radar
- elseif source == GUIEditor.checkbox[87] then
- saveTime()
- if guiCheckBoxGetSelected( source ) then
- exports["gtavradar"].radaron()
- UI["gtavradar"] = true
- else
- exports["gtavradar"].radaroff()
- UI["gtavradar"] = false
- end
- end
- end
- addEventHandler("onClientGUIClick", resourceRoot, ui_ClickHandler)
- function ui_ComboBoxHandler(comboBox)
- if comboBox == GUIEditor.combobox[1] then
- saveTime()
- local theID = guiComboBoxGetSelected( comboBox )
- local theText = guiComboBoxGetItemText( comboBox, theID )
- if theText == "New" then
- if isTimer(HudOverrideTimer) then
- killTimer(HudOverrideTimer)
- end
- setTimer( sphudOverride, 2000, 1)
- exports["racesphud"].e_showNewhud()
- UI["hudmode"] = 1
- elseif theText == "SP" then
- if isTimer(HudOverrideTimer) then
- killTimer(HudOverrideTimer)
- end
- setTimer( sphudOverride, 2000, 1)
- exports["racesphud"].e_showSPhud()
- UI["hudmode"] = 2
- elseif theText == "Old" then
- if isTimer(HudOverrideTimer) then
- killTimer(HudOverrideTimer)
- end
- setTimer( sphudOverride, 2000, 1)
- exports["racesphud"].e_showOldhud()
- UI["hudmode"] = 3
- end
- -- Speed - o - meter mode combobox
- elseif comboBox == GUIEditor.combobox[2] then
- saveTime()
- local theID = guiComboBoxGetSelected( comboBox )
- local theText = guiComboBoxGetItemText( comboBox, theID )
- if theText == "KM/h" then
- exports["digitalspeedometer"].setKMH()
- UI["speed-o-metermode"] = 1
- elseif theText == "MPh" then
- exports["digitalspeedometer"].setMPH()
- UI["speed-o-metermode"] = 2
- elseif theText == "None" then
- exports["digitalspeedometer"].setNone()
- UI["speed-o-metermode"] = 3
- end
- end
- end
- addEventHandler("onClientGUIComboBoxAccepted", resourceRoot, ui_ComboBoxHandler)
- function sphudOverride() -- sphud overrides toggleGCInfo and enableFPS
- for f, u in pairs(Exp_Funct) do
- if UI[f] then
- if Exp_Funct[f]["true"] then
- local executeFunction = loadstring(Exp_Funct[f]["true"])
- executeFunction()
- -- elseif tostring(f) == "speed-o-metermode" then --set speed-o-meter mode
- -- local theNumber = UI[f]
- -- local executeFunction = loadstring(Exp_Funct[f][theNumber])
- -- executeFunction()
- -- outputChatBox("Set Speedometer to "..tostring(theNumber))
- end
- end
- end
- end
- function saveTime()
- if isTimer( theSaveTimer ) then
- killTimer( theSaveTimer )
- end
- theSaveTimer = setTimer(saveUISettings, ui_timetosave, 1)
- end
- function saveUISettings()
- UIxml = xmlLoadFile( "/settings/uisettings.xml" )
- for f, u in pairs(UI) do
- local theChild = xmlFindChild( UIxml, f, 0 )
- if not theChild then
- local theNewChild = xmlCreateChild( UIxml, tostring(f) )
- xmlNodeSetValue( theNewChild, tostring(u) )
- else
- local theValue = xmlNodeSetValue( theChild, tostring(u) )
- end
- end
- outputChatBox("Your Preferences Were Saved")
- xmlSaveFile( UIxml )
- xmlUnloadFile( UIxml )
- end
- function loadUISettings()
- UIxml = xmlLoadFile( "/settings/uisettings.xml" )
- if not UIxml then
- UIxml = xmlCreateFile( "/settings/uisettings.xml", "settings" )
- for f, u in pairs(UI) do
- local theChild = xmlCreateChild( UIxml, f )
- xmlNodeSetValue( theChild, tostring(u) )
- end
- end
- for f, u in pairs(UI) do -- load settings to UI table
- local theChild = xmlFindChild( UIxml, f, 0 )
- local theValue = xmlNodeGetValue( theChild )
- if isBoolean(theValue) then
- UI[f] = toBoolean(theValue)
- else
- UI[f] = tonumber(theValue)
- end
- end
- xmlSaveFile( UIxml )
- xmlUnloadFile( UIxml )
- updateUIgui()
- executeHUDSettings()
- end
- addEventHandler("onClientResourceStart", resourceRoot, loadUISettings)
- function executeHUDSettings()
- local precheck = "if not (getResourceFromName(Exp_Funct['hudmode'].res) and getResourceState(getResourceFromName(Exp_Funct['hudmode'].res))=='running') then return outputDebugString('settings: hudmode not running', 2) end; "
- local executeHud = loadstring(precheck .. Exp_Funct["hudmode"][tonumber(UI["hudmode"])])
- setTimer(executeHud,2000,1)
- setTimer(executeUISettings, 3000, 1)
- end
- function executeUISettings()
- for f, u in pairs(UI) do
- local precheck = string.format("if Exp_Funct['%s'].res and getResourceFromName(Exp_Funct['%s'].res) and getResourceState(getResourceFromName(Exp_Funct['%s'].res))~='running' then return end; ", f, f, f)
- if f == "speed-o-metermode" then -- exception for number based setting
- if Exp_Funct[f].res and getResourceFromName(Exp_Funct[f].res) and getResourceState(getResourceFromName(Exp_Funct[f].res))~='running' then
- -- outputDebugString('settings: ' .. f .. ' res not running', 2)
- else
- local executeFunction = loadstring(precheck .. Exp_Funct["speed-o-metermode"][tonumber(UI["speed-o-metermode"])])
- executeFunction()
- end
- elseif f ~= "hudmode" and f ~= "customnametags" then
- if Exp_Funct[f].res and not (getResourceFromName(Exp_Funct[f].res) and getResourceState(getResourceFromName(Exp_Funct[f].res))=='running') then
- -- outputDebugString('settings: ' .. f .. ' res not running', 2)
- else
- local executeSetting = loadstring(Exp_Funct[f][tostring(UI[f])])
- executeSetting()
- end
- elseif f == "customnametags" then
- triggerEvent("toggleNameTags",root,toBoolean(u))
- end
- end
- end
- function updateUIgui() -- Updates the GUI to the settings that loaded --
- for f, u in pairs(UI) do
- if f == "rankboard" then
- if u then
- guiCheckBoxSetSelected( GUIEditor.checkbox[5], true )
- else
- guiCheckBoxSetSelected( GUIEditor.checkbox[5], false )
- end
- elseif f == "trafficsensor" then
- if u then
- guiCheckBoxSetSelected( GUIEditor.checkbox[7], true )
- else
- guiCheckBoxSetSelected( GUIEditor.checkbox[7], false )
- end
- elseif f == "checkpointdelay" then
- if u then
- guiCheckBoxSetSelected( GUIEditor.checkbox[10], true )
- else
- guiCheckBoxSetSelected( GUIEditor.checkbox[10], false )
- end
- elseif f == "chatbubbles" then
- if u then
- guiCheckBoxSetSelected( GUIEditor.checkbox[11], true )
- else
- guiCheckBoxSetSelected( GUIEditor.checkbox[11], false )
- end
- elseif f == "floatingmessages" then
- if u then
- guiCheckBoxSetSelected( GUIEditor.checkbox[12], true )
- else
- guiCheckBoxSetSelected( GUIEditor.checkbox[12], false )
- end
- elseif f == "fpscounter" then
- if u then
- guiCheckBoxSetSelected( GUIEditor.checkbox[15], true )
- else
- guiCheckBoxSetSelected( GUIEditor.checkbox[15], false )
- end
- elseif f == "customnametags" then
- if toBoolean(u) then
- guiCheckBoxSetSelected(customNameTagsCheckBox,true)
- else
- guiCheckBoxSetSelected(customNameTagsCheckBox,false)
- end
- elseif f == "speed-o-metermode" then
- guiComboBoxSetSelected( GUIEditor.combobox[2], tonumber(u)-1 )
- elseif f == "hudmode" then
- guiComboBoxSetSelected( GUIEditor.combobox[1], tonumber(u)-1 )
- elseif f == "speclist" then
- if u then
- guiCheckBoxSetSelected( GUIEditor.checkbox[99], true )
- else
- guiCheckBoxSetSelected( GUIEditor.checkbox[99], false )
- end
- elseif f == "zonename" then
- if u then
- guiCheckBoxSetSelected( GUIEditor.checkbox[98], true )
- else
- guiCheckBoxSetSelected( GUIEditor.checkbox[98], false )
- end
- elseif f == "coins" then
- if u then
- guiCheckBoxSetSelected( GUIEditor.checkbox[97], true )
- else
- guiCheckBoxSetSelected( GUIEditor.checkbox[97], false )
- end
- elseif f == "gear" then
- if u then
- guiCheckBoxSetSelected( GUIEditor.checkbox[96], true )
- else
- guiCheckBoxSetSelected( GUIEditor.checkbox[96], false )
- end
- elseif f == "clockdate" then
- if u then
- guiCheckBoxSetSelected( GUIEditor.checkbox[95], true )
- else
- guiCheckBoxSetSelected( GUIEditor.checkbox[95], false )
- end
- elseif f == "players" then
- if u then
- guiCheckBoxSetSelected( GUIEditor.checkbox[94], true )
- else
- guiCheckBoxSetSelected( GUIEditor.checkbox[94], false )
- end
- elseif f == "playerpos" then
- if u then
- guiCheckBoxSetSelected( GUIEditor.checkbox[93], true )
- else
- guiCheckBoxSetSelected( GUIEditor.checkbox[93], false )
- end
- elseif f == "nextmap" then
- if u then
- guiCheckBoxSetSelected( GUIEditor.checkbox[92], true )
- else
- guiCheckBoxSetSelected( GUIEditor.checkbox[92], false )
- end
- elseif f == "siteinfo" then
- if u then
- guiCheckBoxSetSelected( GUIEditor.checkbox[91], true )
- else
- guiCheckBoxSetSelected( GUIEditor.checkbox[91], false )
- end
- elseif f == "top1bar" then
- if u then
- guiCheckBoxSetSelected( GUIEditor.checkbox[90], true )
- else
- guiCheckBoxSetSelected( GUIEditor.checkbox[90], false )
- end
- elseif f == "classicprogressbar" then
- if u then
- guiCheckBoxSetSelected( GUIEditor.checkbox[89], true )
- else
- guiCheckBoxSetSelected( GUIEditor.checkbox[89], false )
- end
- elseif f == "modernprogressbar" then
- if u then
- guiCheckBoxSetSelected( GUIEditor.checkbox[88], true )
- else
- guiCheckBoxSetSelected( GUIEditor.checkbox[88], false )
- end
- elseif f == "gtavradar" then
- if u then
- guiCheckBoxSetSelected( GUIEditor.checkbox[87], true )
- else
- guiCheckBoxSetSelected( GUIEditor.checkbox[87], false )
- end
- end
- end
- end
- addEvent('onClientMapStarting')
- function setTimeLeftonMapStart()
- if UI["timeleft"] then
- setTimer(function()
- timeleft_on()
- end,2000,1)
- end
- end
- addEventHandler("onClientMapStarting", root, setTimeLeftonMapStart)
- function timeleft_on()
- triggerEvent('onClientCall_race', getResourceRootElement( getResourceFromName('race')), 'showGUIComponents', 'timeleft', 'timeleftbg')
- end
- function timeleft_off()
- triggerEvent('onClientCall_race', getResourceRootElement( getResourceFromName('race')), 'hideGUIComponents', 'timeleft', 'timeleftbg')
- end
- -- util --
- function toBoolean(str)
- if str == "true" then return true end
- if str == "false" then return false end
- if str == true then return true end
- if str == false then return false end
- end
- function isBoolean(str)
- if str == nil then return false end
- if str == "false" then return true end
- if str == "true" then return true end
- if str == false then return true end
- if str == true then return true end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement