Dzsozi (h03) Posted December 12, 2014 Share Posted December 12, 2014 (edited) Hello community! I've got a script from my friend, and I edited it as GTA V's notifications: My only problem is that I got some problem with the maths, that I can't find, and I don't know how to fix the problem. I've tried several things, but none of them worked. It always had a little bug. The current version looks like this: I would be very thankful if someone could fix this for me! local sx, sy = guiGetScreenSize() --------------------- -- GTA V küldetés és telefon --------------------- local sx,sy = guiGetScreenSize () local font = "default-bold" local font2 = "clear" local headerSize = 1.25 local notificationTextSize = 1.05 local notificationWidth,notificationHeight = 256,128 local notificationHeaderX,notificationHeaderX2,notificationHeaderY,notificationHeaderY2 = 52,150,10,37 local notificationTextX,notificationTextX2,notificationTextY,notificationTextY2 = 10,256,50,118 local notificationIconSize = 32 local notificationIconX = 10 local notificationIconY = notificationHeaderY local notificationX = 50 * sx / sx local notificationStartY,notificationCenterY = sy - notificationHeight,sy/2 local notificationsOffset = 10 local notificationsList = {} local notificationsShowingTime = 1000 local notificationsRenderTime = 10000 local notificationsHidingTime = 1000 local notificationStartColor = { 255, 255, 255 } local notificationEndColor = { 0, 0, 0 } local priorityText = {} priorityText[1] = "Franklin" priorityText[2] = "Michael" priorityText[3] = "Trevor" priorityText[4] = "Simeon" priorityText[5] = "Lester" priorityText[6] = "Ron" priorityText[7] = "Dave" local notificationsToDelete = {} function dxDrawMissionNotification (text,priority) if text and priority then local sound = playSound("files/notification.mp3") local cTick = getTickCount () if notificationsList[1] then if notificationsList[1]["startTick"]+notificationsShowingTime > cTick then -- still showing cTick = notificationsList[1]["startTick"]+notificationsShowingTime end end local tab = {} tab["text"] = text tab["priority"] = priority tab["startTick"] = cTick table.insert (notificationsList,1,tab) end end addEvent ("onNewNotificationCreate",true) addEventHandler ("onNewNotificationCreate",getRootElement(), function (text,priority) dxDrawMissionNotification (text,priority) end ) function teszt() dxDrawMissionNotification ("aaaaaaaaaaaaaaaaaaaaaaaaaa", 3) setTimer(function() dxDrawMissionNotification ("aaaaaaaa", 4) setTimer(function() dxDrawMissionNotification ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 1) setTimer(function() dxDrawMissionNotification ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 5) end, 2000, 1) end, 2000, 1) end, 2000, 1) end addCommandHandler("teszt", teszt) function renderMissionNotifications () for k,v in ipairs(notificationsToDelete) do table.remove (notificationsList,v-k+1) end notificationsToDelete = {} if #notificationsList > 0 then local lowestY = 0 local n = 0 local cTick = getTickCount () local renderingY = nil for k,v in ipairs(notificationsList) do if cTick >= v["startTick"] then if n == 0 then local delay = cTick-v["startTick"] if delay <= notificationsShowingTime then local boxPadding = 10 local lineHeight = dxGetFontHeight( 1.05, "clear" ) local lineHeight2 = dxGetFontHeight( 1.25, "default-bold" ) local minimumWidth = 256 local lines2 = 0 local wordbreak2 = false local lineWidth2 = dxGetTextWidth( v["text"], 1.05, "clear" ) while ( lineWidth2 > minimumWidth ) do lineWidth2 = lineWidth2 - minimumWidth lines2 = lines2 + 1 wordbreak2 = true end local boxWidth, boxHeight = ( minimumWidth + ( boxPadding * 2 ) ), ( lineHeight2 + lines2 ) + ( lineHeight * ( lines2 + 1 ) ) + ( boxPadding * 2 )*2 local progress = delay/notificationsShowingTime local alpha = interpolateBetween ( 0,0,0, 200,0,0, progress*2,"Linear" ) local wr1, wg1, wb1 = unpack(notificationStartColor) local wr2, wg2, wb2 = unpack(notificationEndColor) local wr, wg, wb = interpolateBetween ( wr1, wg1, wb1, wr2, wg2, wb2, progress*2, "InOutBack") local currentY = sy/2 local renderY = currentY-boxHeight local textWidth, textHeight = notificationX + minimumWidth, renderY + lineHeight dxDrawRectangle(notificationX, renderY, boxWidth, boxHeight, tocolor(wr,wg,wb,alpha), true) dxDrawRectangle(notificationX+notificationIconX,renderY+notificationIconY,notificationIconSize,notificationIconSize, tocolor(wr,wg,wb,alpha), true) --kép dxDrawText (priorityText[v["priority"]], notificationX+notificationHeaderX, renderY+notificationHeaderY, notificationX+notificationHeaderX2, renderY+notificationHeaderY2, tocolor(255,255,255,alpha-50),headerSize,font,"left","center",false,false,true) dxDrawText (v["text"],notificationX+notificationTextX, renderY+notificationTextY, textWidth, textHeight,tocolor(255,255,255,alpha-50),notificationTextSize,font2,"left","top",false,wordbreak2,true) local criticalY = currentY-notificationsOffset-boxHeight if criticalY <= currentY then renderingY = currentY end else local boxPadding = 10 local lineHeight = dxGetFontHeight( 1.05, "clear" ) local lineHeight2 = dxGetFontHeight( 1.25, "default-bold" ) local minimumWidth = 256 local lines2 = 0 local wordbreak22 = false local lineWidth2 = dxGetTextWidth( v["text"], 1.05, "clear" ) while ( lineWidth2 > minimumWidth ) do lineWidth2 = lineWidth2 - minimumWidth lines2 = lines2 + 1 wordbreak2 = true end local boxWidth, boxHeight = ( minimumWidth + ( boxPadding * 2 ) ), ( lineHeight2 ) + ( lineHeight * ( lines2 + 1 ) ) + ( boxPadding * 2 )*2 renderingY = false local delay = delay-notificationsShowingTime local alpha = 200 if delay > notificationsRenderTime then local progress = (delay-notificationsRenderTime)/notificationsHidingTime alpha = interpolateBetween ( 200,0,0, 0,0,0, progress,"Linear" ) if progress >= 1 then table.insert (notificationsToDelete,k) end end local currentY = sy/2 renderY = currentY-boxHeight local textWidth, textHeight = notificationX + minimumWidth, renderY + lineHeight dxDrawRectangle(notificationX, renderY, boxWidth, boxHeight, tocolor(0,0,0,alpha), true) dxDrawImage (notificationX+notificationIconX,renderY+notificationIconY,notificationIconSize,notificationIconSize,"files/" .. v["priority"] .. ".png",0,0,0,tocolor(255,255,255,alpha),true) dxDrawText (priorityText[v["priority"]], notificationX+notificationHeaderX, renderY+notificationHeaderY, notificationX+notificationHeaderX2, renderY+notificationHeaderY2, tocolor(255,255,255,alpha),headerSize,font,"left","center",false,false,true) dxDrawText (v["text"],notificationX+notificationTextX, renderY+notificationTextY, textWidth, textHeight,tocolor(255,255,255,alpha),notificationTextSize,font2,"left","top",false,wordbreak2,true) end else local boxPadding = 10 local lineHeight = dxGetFontHeight( 1.05, "clear" ) local lineHeight2 = dxGetFontHeight( 1.25, "default-bold" ) local minimumWidth = 256 local lines2 = 0 local wordbreak2 = false local lineWidth2 = dxGetTextWidth( v["text"], 1.05, "clear" ) while ( lineWidth2 > minimumWidth ) do lineWidth2 = lineWidth2 - minimumWidth lines2 = lines2 + 1 wordbreak2 = true end local boxWidth, boxHeight = ( minimumWidth + ( boxPadding * 2 ) ), ( lineHeight2 ) + ( lineHeight * ( lines2 + 1 ) ) + ( boxPadding * 2 )*2 local delay = cTick-v["startTick"]-notificationsShowingTime local alpha = 200 if delay > notificationsRenderTime then local progress = (delay-notificationsRenderTime)/notificationsHidingTime alpha = interpolateBetween ( 200,0,0, 0,0,0, progress,"Linear" ) if progress >= 1 then table.insert (notificationsToDelete,k) end end local currentY = sy/2 if renderingY then currentY = renderingY - (notificationsOffset + boxHeight)*n elseif renderingY == false then currentY = sy/2 - (notificationsOffset + boxHeight)*n elseif renderingY == nil then currentY = sy/2 - (notificationsOffset + boxHeight)*(n-1) end renderY = currentY-boxHeight local textWidth, textHeight = notificationX + minimumWidth, renderY + lineHeight dxDrawRectangle(notificationX, renderY, boxWidth, boxHeight, tocolor(0,0,0,alpha), true) dxDrawImage (notificationX+notificationIconX,renderY+notificationIconY,notificationIconSize,notificationIconSize,"files/" .. v["priority"] .. ".png",0,0,0,tocolor(255,255,255,alpha),true) dxDrawText (priorityText[v["priority"]], notificationX+notificationHeaderX, renderY+notificationHeaderY, notificationX+notificationHeaderX2, renderY+notificationHeaderY2, tocolor(255,255,255,alpha),headerSize,font,"left","center",false,false,true) dxDrawText (v["text"],notificationX+notificationTextX, renderY+notificationTextY, textWidth, textHeight,tocolor(255,255,255,alpha),notificationTextSize,font2,"left","top",false,wordbreak2,true) end n = n+1 end end end end addEventHandler ("onClientRender",getRootElement(),renderMissionNotifications) Thank you for the help in advance! Edited December 19, 2014 by Guest Link to comment
Dzsozi (h03) Posted December 12, 2014 Author Share Posted December 12, 2014 Help please Link to comment
Anubhav Posted December 13, 2014 Share Posted December 13, 2014 None is answering means none knows how. Link to comment
Dzsozi (h03) Posted December 15, 2014 Author Share Posted December 15, 2014 Still waiting for help if someone knows the solution. Link to comment
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