Dzejki Posted January 15, 2014 Share Posted January 15, 2014 Hello guys. I just want to know how i can do such a thing: If someone spamming with call notification function I want to change next notification position. I don't want them all in same position. And when the oldest notification disappears, rest changing position. How can I do that? local screen_x, screen_y = guiGetScreenSize() local info = {} function showInfo (type, text) if type and text then local path, path_ if type == "warning" then path, path_ = "images/info_r.png", "images/warning.png" elseif type == "info" then path, path_ = "images/info_g.png", "images/info.png" end local y = 50 if #info > 1 then y = #info * 50 else y = 50 end info[#info + 1] = guiCreateStaticImage(((screen_x - (screen_x * 0.5))/2) - 20, screen_y - y, screen_x * 0.5, 35, path, false) guiCreateStaticImage((screen_x * 0.5) * 0.1, 5, 25, 25, path_, false, info[#info + 1]) guiSetAlpha(info[#info + 1], 0.7) local label = guiCreateLabel(((screen_x * 0.5) * 0.1) + 35, 10, (screen_x * 0.5) - (((screen_x * 0.5) * 0.1) + 35), 35, text, false, info[#info + 1]) guiSetFont(label, guiCreateFont("fonts/Idealist.ttf", 12)) move(info[#info + 1], ((screen_x - (screen_x * 0.5))/2) - 20, screen_y - 50, (screen_x - (screen_x * 0.5))/2, screen_y - 50, 2) setTimer( function () for k,v in ipairs(info) do if v == info[1] then alpha(info[1], 0.7, 0, 0.3) else local x, y = guiGetPosition(v, false) info[1] = info[2] info[2] = info[3] info[3] = nil move(v, x, y, x, y - 50, 0.5) end end end , 3000, 1) end end I did sth like that but I think that my thinking going bad way. And all code I did has no sense. But anyway, help me, please. Ah, and move and alpha functions look like this (they r working good): function move(guiElement, posx, posy, newx, newy, interpTime) if guiElement then if posx and posy and newx and newy then local startTick = getTickCount() interpTime = interpTime * 1000 addEventHandler("onClientRender", root, function() local currTime = getTickCount() - startTick local progress = currTime / interpTime if progress <= 1 then local interpPosX, interpPosY = interpolateBetween(posx, posy, 0, newx, newy, 0, progress, "OutBack", 0, 0, 1) guiSetPosition(guiElement, interpPosX, interpPosY, false) end end) end end end function alpha(guiElement, interpStart, interpStop, interpTime) if guiElement then local startTick = getTickCount() interpTime = interpTime * 1000 addEventHandler("onClientRender", root, function() local currTime = getTickCount() - startTick local progress = currTime / interpTime if progress <= 1 then local interpAlpha = interpolateBetween(interpStart, 0, 0, interpStop, 0, 0, progress, "Linear") guiSetAlpha(guiElement,interpAlpha) end end) end end Link to comment
Moderators IIYAMA Posted January 16, 2014 Moderators Share Posted January 16, 2014 By using the array variable multiplying by the distance between the text. Required: table.remove 50 pixels between the text. newPosition = positionY -(50* array) Link to comment
Dzejki Posted January 16, 2014 Author Share Posted January 16, 2014 How I can define this array? Link to comment
Moderators IIYAMA Posted January 16, 2014 Moderators Share Posted January 16, 2014 for k,v in ipairs(info) do Link to comment
Dzejki Posted January 16, 2014 Author Share Posted January 16, 2014 setTimer( function () for k,v in ipairs(info) do if k == 1 then alpha(info[1], 0.7, 0, 0.3) else local x, y = guiGetPosition(v, false) info[1] = info[2] info[2] = info[3] move(v, x, y, x, y + (50 * k), 0.5) end end end , 3000, 1) I did sth like this but every notifications moving down, the oldest doesn't disappear. They all moving and changing alpha same time. Other problem is that each notfication's position is higher and higher, it looks like this: http://snag.gy/awQll.jpg Full code: function showInfo (type, text) if type and text then local path, path_ if type == "warning" then path, path_ = "images/info_r.png", "images/warning.png" elseif type == "info" then path, path_ = "images/info_g.png", "images/info.png" end local y = 50 if #info > 1 then y = #info * 50 else y = 50 end info[#info + 1] = guiCreateStaticImage(((screen_x - (screen_x * 0.5))/2) - 20, screen_y - y, screen_x * 0.5, 35, path, false) guiCreateStaticImage((screen_x * 0.5) * 0.1, 5, 25, 25, path_, false, info[#info + 1]) guiSetAlpha(info[#info + 1], 0.7) local label = guiCreateLabel(((screen_x * 0.5) * 0.1) + 35, 10, (screen_x * 0.5) - (((screen_x * 0.5) * 0.1) + 35), 35, text, false, info[#info + 1]) guiSetFont(label, guiCreateFont("fonts/Idealist.ttf", 12)) move(info[#info + 1], ((screen_x - (screen_x * 0.5))/2) - 20, screen_y - 50, (screen_x - (screen_x * 0.5))/2, screen_y - 50, 2) setTimer( function () for k,v in ipairs(info) do if k == 1 then alpha(info[1], 0.7, 0, 0.3) else local x, y = guiGetPosition(v, false) info[1] = info[2] info[2] = info[3] move(v, x, y, x, y + (50 * k), 0.5) end end end , 3000, 1) end end Link to comment
Moderators IIYAMA Posted January 16, 2014 Moderators Share Posted January 16, 2014 Because you forgot to save the future time and forgot to remove it and to delete the elements. Link to comment
Dzejki Posted January 16, 2014 Author Share Posted January 16, 2014 You meant table.remove(k)? I'll check it. @Edit: Nah, i don't understand. My worst side is tables nad I don't understand it at all. Link to comment
..:D&G:.. Posted January 16, 2014 Share Posted January 16, 2014 I think u are trying to do something like this : https://community.multitheftauto.com/index.php?p= ... ls&id=6919 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