local topsFont = dxCreateFont( "font.ttf") -- -- toptimes_client.lua -- Created = {} CToptimes = {} CToptimes.__index = CToptimes CToptimes.instances = {} g_Settings = {} serverInfo = {} px = 0 sX,sY = guiGetScreenSize() toptimes = { anim = 360, size = {380,160}, mapname = "N/A", label = {"","","","","","","","","","",""}, time = {"","","","","","","","","","",""}, data = {"","","","","","","","","","",""}, country = {"","","","","","","","","","",""}, personal = {false,pos = 9,name="",time="",data="",country=""}, state = false, animState = "closed", tick = getTickCount() } function drawToptimesIntreface() if toptimes.animState == "closed" then local tick = getTickCount() - toptimes.tick local progress = tick/1000 toptimes.anim = interpolateBetween(0,0,0,390,0,0,progress,"InOutBack") else local tick = getTickCount() - toptimes.tick local progress = tick/1000 toptimes.anim = interpolateBetween(390,0,0,0,0,0,progress,"OutBounce") end local clanColor = {220,20,60} if toptimes.state then local sX = sX+toptimes.anim dxDrawRectangle(sX-toptimes.size[1]-10,(sY/2)-(toptimes.size[2]),toptimes.size[1],200/8,tocolor(232,31,31,200)) dxDrawText(toptimes.mapname,sX-toptimes.size[1]-10,(sY/2)-(toptimes.size[2]),sX-10,(sY/2)-(toptimes.size[2])+(200/8),tocolor(255,255,255,255),1,topsFont,"center","center",true) dxDrawRectangle(sX-toptimes.size[1]-10,(sY/2)-(toptimes.size[2])+(200/8),toptimes.size[1],toptimes.size[2],tocolor(15,15,15,150)) for i=1,8 do dxDrawText(i..") "..toptimes.label[i],sX-toptimes.size[1]+(toptimes.size[1]*0.03)-10,(sY/2)-(toptimes.size[2])+(200/8)+((i-1)*20),sX-(toptimes.size[1]*0.1)-10,(sY/2)-(toptimes.size[2])+(200/8)+((i)*20),tocolor(255,255,255,255),1,topsFont,"left","center",true,false,false,true) dxDrawText(toptimes.time[i],sX-toptimes.size[1]+(toptimes.size[1]*0.52)-10,(sY/2)-(toptimes.size[2])+(200/8)+((i-1)*20),sX-(toptimes.size[1]*0.1)-10,(sY/2)-(toptimes.size[2])+(200/8)+((i)*20),tocolor(255,255,255,255),1,topsFont,"left","center",true,false,false,true) dxDrawText(toptimes.data[i],sX-toptimes.size[1]+(toptimes.size[1]*0.75)-10,(sY/2)-(toptimes.size[2])+(200/8)+((i-1)*20),sX-(toptimes.size[1]*0.1)-10,(sY/2)-(toptimes.size[2])+(200/8)+((i)*20),tocolor(255,255,255,255),1,topsFont,"left","center",true,false,false,true) if toptimes.country[i] ~= "" then if fileExists(":admin/client/images/flags/"..toptimes.country[i]..".png") then dxDrawImage(sX-toptimes.size[1]+(toptimes.size[1]*0.93)-10,(sY/2)-(toptimes.size[2])+(200/8)+((i-1)*20)+3,16,11,":admin/client/images/flags/"..toptimes.country[i]..".png",tocolor(255,255,255,255)) end end end if toptimes.personal[1] then dxDrawRectangle(sX-toptimes.size[1]-10,(sY/2)+(200/8),toptimes.size[1],30,tocolor(15,15,15,150)) dxDrawLine(sX-toptimes.size[1],(sY/2)+(200/8),sX-20,(sY/2)+(200/8),tocolor(141,182,205,255)) dxDrawText("#8DB6CD"..toptimes.personal.pos..") #FFFFFF "..toptimes.personal.name,sX-toptimes.size[1]+(toptimes.size[1]*0.03)-10,(sY/2)+(200/8),sX-(toptimes.size[1]*0.1)-10,(sY/2)+(200/8)+30,tocolor(255,255,255,255),1,topsFont,"left","center",true,false,false,true) dxDrawText(toptimes.personal.time,sX-toptimes.size[1]+(toptimes.size[1]*0.52)-10,(sY/2)+(200/8),sX-(toptimes.size[1]*0.1)-10,(sY/2)+(200/8)+30,tocolor(255,255,255,255),1,topsFont,"left","center",true,false,false,true) dxDrawText(toptimes.personal.data,sX-toptimes.size[1]+(toptimes.size[1]*0.75)-10,(sY/2)+(200/8),sX-(toptimes.size[1]*0.1)-10,(sY/2)+(200/8)+30,tocolor(255,255,255,255),1,topsFont,"left","center",true,false,false,true) if toptimes.personal.country ~= "" then if fileExists(":admin/client/images/flags/"..toptimes.personal.country..".png") then dxDrawImage(sX-toptimes.size[1]+(toptimes.size[1]*0.93)-10,(sY/2)-(toptimes.size[2])+(200/8)+((i-1)*20)+3,16,11,":admin/client/images/flags/"..toptimes.personal.country..".png",tocolor(255,255,255,255)) end end end end end addEventHandler("onClientRender",getRootElement(),drawToptimesIntreface) function toggleToptimes() if toptimes.animState == "open" then closeToptimes() else openToptimes() end end bindKey("F5","down",toggleToptimes) function openToptimes() if toptimes.state and toptimes.animState == "closed" then toptimes.tick = getTickCount() toptimes.animState = "open" end end function closeToptimes() if toptimes.state and toptimes.animState == "open" then toptimes.tick = getTickCount() toptimes.animState = "closed" end end --------------------------------------------------------------------------- -- Client -- Handle events from Race -- -- This is the 'interface' from Race -- --------------------------------------------------------------------------- addEventHandler('onClientResourceStart', g_ResRoot, function() triggerServerEvent('onLoadedAtClient_tt', g_Me) topTimePersonalLabel = false chatBlock = false end ) addEvent('onClientMapStarting', true) addEventHandler('onClientMapStarting', getRootElement(), function(mapinfo) outputDebug( 'TOPTIMES', 'onClientMapStarting' ) if g_CToptimes then g_CToptimes:onMapStarting(mapinfo) chatBlock = false end end ) addEvent('onClientMapStopping', true) addEventHandler('onClientMapStopping', getRootElement(), function() outputDebug( 'TOPTIMES', 'onClientMapStopping' ) if g_CToptimes then g_CToptimes:onMapStopping() end end ) addEvent('onClientPlayerFinish', true) addEventHandler('onClientPlayerFinish', getRootElement(), function() outputDebug( 'TOPTIMES', 'onClientPlayerFinish' ) if g_CToptimes then openToptimes() setTimer(closeToptimes,5000,1) end end ) addEvent('onClientSetMapName', true) addEventHandler('onClientSetMapName', getRootElement(), function(manName) if g_CToptimes then g_CToptimes:setWindowTitle(manName) end end ) function updateSettings(settings, playeradmin) end --------------------------------------------------------------------------- -- -- CToptimes:create() -- -- -- --------------------------------------------------------------------------- function CToptimes:create() local id = #CToptimes.instances + 1 CToptimes.instances[id] = setmetatable( { id = id, hasTimes = false }, self ) return CToptimes.instances[id] end function CToptimes:setWindowTitle( mapName ) toptimes.mapname = mapName end function string.findIgnoreCase(haystack,needle) return string.find(string.lower(haystack),string.lower(needle),1,true) end function CToptimes:onMapStarting(mapinfo) self:setWindowTitle( mapinfo.name ) self.hasTimes = false -- table.dump(mapinfo) -- if self.startshow then --if mapinfo.name and string.findIgnoreCase(mapinfo.name,"[DM]") then for _,e in pairs(getElementsByType("racepickup") or {}) do local t = getElementData(e,"type") if t and t == "vehiclechange" then local v = getElementData(e,"vehicle") if v and tonumber(v) == 425 then self.hasTimes = true break end end end --end if self.hasTimes then self:doToggleToptimes( true ) openToptimes() setTimer(closeToptimes,5000,1) else self:doToggleToptimes( false ) closeToptimes() end end function CToptimes:onMapStopping() self:setWindowTitle( '' ) closeToptimes() end function CToptimes:doAutoShow() self.bAutoShow = true self:updateShow() end function CToptimes:updateShow(bOn) self:enableToptimeUpdatesFromServer(bOn) end function CToptimes:enableToptimeUpdatesFromServer( bOn ) triggerServerEvent('onClientRequestToptimesUpdates', g_Me, bOn, self.clientRevision ) end function CToptimes:doOnServerSentToptimes( data, serverRevision, playerPosition ) toptimes.personal[1] = false for i=1,8 do toptimes.label[i] = data[i].playerName local timeText = data[i].timeText if timeText:sub(1,1) == '0' then timeText = ' ' .. timeText:sub(2) end toptimes.time[i] = timeText toptimes.data[i] = string.sub(tostring(data[i].dateRecorded),1,10) toptimes.country[i] = data[i].country