downight Posted February 23, 2014 Posted February 23, 2014 Hi, I want to bind this (it's original, without bind): local SCREEN_WIDTH, SCREEN_HEIGHT = guiGetScreenSize() local name, author, lastTimePlayed, spawnPointCount, playedCount, modename local startTick local enabled = false local drawTime = 10000 local month = {"January","February","March","April","May","June","July","August","September","October","November","December"} function timestampToDate(stamp) local time = getRealTime(stamp) return string.format("%d %s %02d:%02d",time.monthday,month[time.month+1],time.hour,time.minute) end function handleMapInfo(mapInfo) name = mapInfo.name or "Unknown" author = mapInfo.author or "Unknown" lastTimePlayed = timestampToDate(mapInfo.lastTimePlayed) or "Unknown" spawnPointCount = tostring(mapInfo.spawnPointCount) playedCount = tostring(mapInfo.playedCount or "Unknown") modename = mapInfo.modename ~= "Destruction derby" and mapInfo.modename or "DD / DM" startTick = getTickCount() if not enabled then addEventHandler("onClientRender",getRootElement(),handleOnRender) enabled = true end end addEvent("onClientMapStarting",true) addEventHandler("onClientMapStarting",getRootElement(),handleMapInfo) function handleOnRender() local time = getTickCount() - startTick local alphaFactor if time < 1000 then alphaFactor = time / 1000 elseif time >= 1000 and time < drawTime + 1000 then alphaFactor = 1 elseif time >= drawTime + 1000 and time < drawTime + 2000 then alphaFactor = 1 - (time - (drawTime + 1000)) / 1000 elseif time >= drawTime + 2000 then enabled = false removeEventHandler("onClientRender",getRootElement(),handleOnRender) return end local maxLabelWidth = 81 local nameWidth = dxGetTextWidth(name,1,"default-bold") local authorWidth = dxGetTextWidth(author) + maxLabelWidth local lastTimePlayedWidth = dxGetTextWidth(lastTimePlayed) + maxLabelWidth local spawnPointCountWidth = dxGetTextWidth(spawnPointCount) + maxLabelWidth local playedCountWidth = dxGetTextWidth(playedCount) + maxLabelWidth local modenameWidth = dxGetTextWidth(modename) + maxLabelWidth local width = math.max(nameWidth,authorWidth,lastTimePlayedWidth,spawnPointCountWidth,playedCountWidth,modenameWidth) + 10 local height = 100 local x = SCREEN_WIDTH - width local y = SCREEN_HEIGHT / 1.3 - height / 1.3 dxDrawRectangle(x,y,width,20,tocolor(0,0,0,255*alphaFactor)) dxDrawRectangle(x,y + 20,width,height - 20,tocolor(0,0,0,200*alphaFactor)) dxDrawText(name,x,y,x+width,y+20,tocolor(97,255,19*alphaFactor),1,"default-bold","center","center") dxDrawText("Author:\nTipo:\nSpawnpoints:\ntimes played:\nlast time:",x+5,y+20,0,0,tocolor(97,255,19*alphaFactor),1,"default-bold") dxDrawText(string.format("%s\n%s\n%s\n%s\n%s",author,modename,spawnPointCount,playedCount,lastTimePlayed),x+5+maxLabelWidth,y+20,0,0,tocolor(255,255,255*alphaFactor)) end The script is shown when the map is started so it shows you proper map information: but when I tried to bind it as letter "m", It shows the "default" info (should be the same as the image above): I don't know what's going on
iPrestege Posted February 23, 2014 Posted February 23, 2014 Yes that's because you removed the 'onClientMapStarting' Event as i think because the 'mapInfo' return nil . Try this : local SCREEN_WIDTH, SCREEN_HEIGHT = guiGetScreenSize() local name, author, lastTimePlayed, spawnPointCount, playedCount, modename local startTick local enabled = false local drawTime = 10000 local month = {"January","February","March","April","May","June","July","August","September","October","November","December"} function timestampToDate(stamp) local time = getRealTime(stamp) return string.format("%d %s %02d:%02d",time.monthday,month[time.month+1],time.hour,time.minute) end function handleMapInfo(mapInfo) ReturnInfo = mapInfo end addEvent("onClientMapStarting",true) addEventHandler("onClientMapStarting",getRootElement(),handleMapInfo) bindKey ( "m","down", function ( ) if not ReturnInfo then return end name = ReturnInfo.name or "Unknown" author = ReturnInfo.author or "Unknown" lastTimePlayed = timestampToDate(ReturnInfo.lastTimePlayed) or "Unknown" spawnPointCount = tostring(ReturnInfo.spawnPointCount) playedCount = tostring(ReturnInfo.playedCount or "Unknown") modename = ReturnInfo.modename ~= "Destruction derby" and ReturnInfo.modename or "DD / DM" startTick = getTickCount() if not enabled then addEventHandler("onClientRender",getRootElement(),handleOnRender) enabled = true else enabled = false removeEventHandler("onClientRender",getRootElement(),handleOnRender) end end ) function handleOnRender() local time = getTickCount() - startTick local alphaFactor if time < 1000 then alphaFactor = time / 1000 elseif time >= 1000 and time < drawTime + 1000 then alphaFactor = 1 elseif time >= drawTime + 1000 and time < drawTime + 2000 then alphaFactor = 1 - (time - (drawTime + 1000)) / 1000 elseif time >= drawTime + 2000 then enabled = false removeEventHandler("onClientRender",getRootElement(),handleOnRender) return end local maxLabelWidth = 81 local nameWidth = dxGetTextWidth(name,1,"default-bold") local authorWidth = dxGetTextWidth(author) + maxLabelWidth local lastTimePlayedWidth = dxGetTextWidth(lastTimePlayed) + maxLabelWidth local spawnPointCountWidth = dxGetTextWidth(spawnPointCount) + maxLabelWidth local playedCountWidth = dxGetTextWidth(playedCount) + maxLabelWidth local modenameWidth = dxGetTextWidth(modename) + maxLabelWidth local width = math.max(nameWidth,authorWidth,lastTimePlayedWidth,spawnPointCountWidth,playedCountWidth,modenameWidth) + 10 local height = 100 local x = SCREEN_WIDTH - width local y = SCREEN_HEIGHT / 1.3 - height / 1.3 dxDrawRectangle(x,y,width,20,tocolor(0,0,0,255*alphaFactor)) dxDrawRectangle(x,y + 20,width,height - 20,tocolor(0,0,0,200*alphaFactor)) dxDrawText(name,x,y,x+width,y+20,tocolor(97,255,19*alphaFactor),1,"default-bold","center","center") dxDrawText("Author:\nTipo:\nSpawnpoints:\ntimes played:\nlast time:",x+5,y+20,0,0,tocolor(97,255,19*alphaFactor),1,"default-bold") dxDrawText(string.format("%s\n%s\n%s\n%s\n%s",author,modename,spawnPointCount,playedCount,lastTimePlayed),x+5+maxLabelWidth,y+20,0,0,tocolor(255,255,255*alphaFactor)) end
downight Posted February 24, 2014 Author Posted February 24, 2014 It works man THANK YOU but I forgot to add that I want it when the map starts also lol... e/ I just enabled both scripts and does the job good lolz so you don't have to make one out of two no more I guess
manawydan Posted February 24, 2014 Posted February 24, 2014 (edited) sorry Edited February 24, 2014 by Guest "Querer não é poder, mas tentar é avançar"!
Moderators Citizen Posted February 24, 2014 Moderators Posted February 24, 2014 startResource or include resource in meta.xml? He already fixed the problem (by doing code duplication ) The rEvolution is coming ...
iPrestege Posted February 25, 2014 Posted February 25, 2014 It works man THANK YOU but I forgot to add that I want it when the map starts also lol...e/ I just enabled both scripts and does the job good lolz so you don't have to make one out of two no more I guess You're welcome.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now