qaisjp Posted August 4, 2011 Share Posted August 4, 2011 Fades an element (supports only vehicles, peds and gui's) local debug = { e = function(s) outputDebugString(s, 2) end, i = outputDebugString, w = function(s) outputDebugString(s, 1) end } local DIFFERENCE = 0.5 local supportedElements = { ["vehicle"] = true, ["ped"] = true } function fadeElement(ele, way) -- way true for in, false for out local allow = false local gui = false local alphG = false local alphS = false if supportedElements[getElementType(ele)] then allow = true alphG = getElementAlpha alphS = setElementAlpha elseif string.find(getElementType(ele), "gui") then allow = true alphG = guiGetAlpha alphS = guiSetAlpha end if not allow then debug.w("Invalid argument(1, 'element') @ fadeElement. Specified element is not allowed") else if way then while alphaG(ele) < 255 then alphaS(ele,alphaG(ele)+DIFFERENCE) end elseif not way then while alphaG(ele) > 0 then alphaS(ele, alphaG(ele)-DIFFERENCE) end end end end Please help create this code, fix bugs and make it better for the community to use! -- Arran gave tip for the guiSetAlpha/guiGetAlpha thingymajig. Link to comment
Arran Posted August 4, 2011 Share Posted August 4, 2011 This is something I made to fade windows in 1 of my scripts, might help you: Note that its not time based so for people with low FPS it takes ages for the GUI to load (bad) it should be time based and if you wanted to fade out one you do fadingGUI[window] = true and to fade in: fadingInGUI[window] = true local GLP = getLocalPlayer() fadingGUI = {} fadingInGUI = {} function fadeGUI() for ent, ind in pairs(fadingGUI) do local newalpha = guiGetAlpha(ent) - 0.025 if (newalpha <= 0) then guiSetAlpha(ent, 0) guiSetVisible(ent, false) fadingGUI[ent] = nil else guiSetAlpha(ent, newalpha) end if (fadingInGUI[ent]) then fadingInGUI[ent] = nil end end for ent, ind in pairs(fadingInGUI) do guiSetVisible(ent, true) guiBringToFront(ent, true) local newalpha = guiGetAlpha(ent) + 0.025 if (newalpha >= 0.95) then guiSetAlpha(ent, 0.95) fadingInGUI[ent] = nil else guiSetAlpha(ent, newalpha) end end end addEventHandler("onClientRender", root, fadeGUI) Link to comment
Castillo Posted August 4, 2011 Share Posted August 4, 2011 You have many typos in your script, like using 'then' when it should be 'do', also calling a variable alphaG but your variable was alphG. function fadeElement(ele, way) -- way true for in, false for out local allow = false local gui = false local alphaG = false local alphaS = false if supportedElements[getElementType(ele)] then allow = true alphaG = getElementAlpha alphaS = setElementAlpha elseif string.find(getElementType(ele), "gui") then allow = true alphaG = guiGetAlpha alphaS = guiSetAlpha end if not allow then debug.w("Invalid argument(1, 'element') @ fadeElement. Specified element is not allowed") else if way then while alphaG(ele) < 255 do alphaS(ele,alphaG(ele)+DIFFERENCE) end elseif not way then while alphaG(ele) > 0 do alphaS(ele, alphaG(ele)-DIFFERENCE) end end end end P.S: This script will do a infinite running script. Edit: Using repeat until won't make a infinite running script. function fadeElement(ele, way) -- way true for in, false for out local allow = false local gui = false local alphaG = false local alphaS = false if supportedElements[getElementType(ele)] then allow = true alphaG = getElementAlpha alphaS = setElementAlpha elseif string.find(getElementType(ele), "gui") then allow = true alphaG = guiGetAlpha alphaS = guiSetAlpha end if not allow then debug.w("Invalid argument(1, 'element') @ fadeElement. Specified element is not allowed") else if way then repeat alphaS(ele,alphaG(ele)+DIFFERENCE) until alphaG(ele) < 255 elseif not way then repeat alphaS(ele, alphaG(ele)-DIFFERENCE) until alphaG(ele) > 0 do end end end end But, I don't understand why it doesn't set the alpha, it set's once then again to 1. 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