..:D&G:.. Posted March 25, 2016 Share Posted March 25, 2016 Hey, I want to do this cool intro for a project server I am working on. I don't really know how to loop through a series of pictures without repeating them. Here is what I managed to do till now: local ap = 0 local apmode = true function testBackground() if apmode == true then if ap < 255 then ap = ap + 5 else ap = 255 end else if ap > 0 then ap = ap - 5 else ap = 0 end end dxDrawImage(s[1]*0/1440,s[2]*0/900, s[1]*1440/1440,s[2]*900/900, ":Main/files/images/menu_bg1.jpg", 0, 0, 0, tocolor(255, 255, 255, ap),false) end I have 6 image files that go like this: "menu_bg1.jpg, menu_bg2.jpg, menu_bg3.jpg, etc" and at the start, the image will have a fade out effect, and what I want to do is have the current image fade in and disappear after 5 seconds, and the new image should fade out and appear clearly (255 alpha) on the screen. Thanks. Link to comment
Dimos7 Posted March 25, 2016 Share Posted March 25, 2016 local images ={ {"Main/files/images/menu_bg1.jpg", 1}, {"Main/files/images/menu_bg2.jpg", 2}, {"Main/files/images/menu_bg3.jpg", 3}, {"Main/files/images/menu_bg4.jpg", 4}, {"Main/files/images/menu_bg5.jpg", 5}, {"Main/files/images/menu_bg6.jpg", 6} } local ap = 0 local apmode = true function testBackground() if apmode == true then if ap < 255 then ap = ap + 5 else ap = 255 end else if ap > 0 then ap = ap - 5 else ap = 0 end end for i = 1 , #images do dxDrawImage(s[1]*0/1440,s[2]*0/900, s[1]*1440/1440,s[2]*900/900, images[i], 0, 0, 0, tocolor(255, 255, 255, ap),false) end end Link to comment
..:D&G:.. Posted March 25, 2016 Author Share Posted March 25, 2016 It says it gets a table instead of the image path Link to comment
Captain Cody Posted March 25, 2016 Share Posted March 25, 2016 local images ={ {"Main/files/images/menu_bg1.jpg"}, {"Main/files/images/menu_bg2.jpg"}, {"Main/files/images/menu_bg3.jpg"}, {"Main/files/images/menu_bg4.jpg"}, {"Main/files/images/menu_bg5.jpg"}, {"Main/files/images/menu_bg6.jpg"} } Meh? Link to comment
..:D&G:.. Posted March 25, 2016 Author Share Posted March 25, 2016 local images ={ {"Main/files/images/menu_bg1.jpg"}, {"Main/files/images/menu_bg2.jpg"}, {"Main/files/images/menu_bg3.jpg"}, {"Main/files/images/menu_bg4.jpg"}, {"Main/files/images/menu_bg5.jpg"}, {"Main/files/images/menu_bg6.jpg"} } Meh? Still gets the table "images" instead of its content Link to comment
Captain Cody Posted March 25, 2016 Share Posted March 25, 2016 local images ={ "Main/files/images/menu_bg1.jpg", "Main/files/images/menu_bg2.jpg", "Main/files/images/menu_bg3.jpg", "Main/files/images/menu_bg4.jpg", "Main/files/images/menu_bg5.jpg", "Main/files/images/menu_bg6.jpg" } Eh? Link to comment
..:D&G:.. Posted March 25, 2016 Author Share Posted March 25, 2016 local images ={ "Main/files/images/menu_bg1.jpg", "Main/files/images/menu_bg2.jpg", "Main/files/images/menu_bg3.jpg", "Main/files/images/menu_bg4.jpg", "Main/files/images/menu_bg5.jpg", "Main/files/images/menu_bg6.jpg" } Eh? Yeah, I had a closer look at the table and noticed that it had the paths inside tables But I don't know how to make the images to change every 5 seconds. I never used this "for i = 1, #images do" thing and I don't know how it works.. Link to comment
Captain Cody Posted March 25, 2016 Share Posted March 25, 2016 (edited) Try for i,v in pairs (images) do image = v end But you'd have to figure out a way to add in a pause. Orrr time = 500 'Change it' i = 0 setTimer(setImage,time,#images,i + 1) function setImage (current) image = images[current] if current = #image then i = 0 end end Edited March 25, 2016 by Guest Link to comment
Captain Cody Posted March 25, 2016 Share Posted March 25, 2016 /\ Try that, added something to reset it once it gets to the end. Link to comment
..:D&G:.. Posted March 25, 2016 Author Share Posted March 25, 2016 Sooo, I did this yeah... local ap = 0 local apmode = true time = 5000 i = 0 local images ={ ":Main/files/images/menu_bg1.jpg", ":Main/files/images/menu_bg2.jpg", ":Main/files/images/menu_bg3.jpg", ":Main/files/images/menu_bg4.jpg", ":Main/files/images/menu_bg5.jpg", ":Main/files/images/menu_bg6.jpg" } function testBackground(current) if apmode == true then if ap < 255 then ap = ap + 5 else ap = 255 end else if ap > 0 then ap = ap - 5 else ap = 0 end end image = images[current] if current == #image then i = 0 end dxDrawImage(s[1]*0/1440,s[2]*0/900, s[1]*1440/1440,s[2]*900/900, image, 0, 0, 0, tocolor(255, 255, 255, ap),false) end setTimer(testBackground,time,#images,i + 1) But it doesn't get the image It kinda looks weird that "current" isn't defined anywhere, but maybe it's something I don't know.. Link to comment
Captain Cody Posted March 25, 2016 Share Posted March 25, 2016 The last part of set timer defines current. And I'll run a quick test on it and see if I can figure out the issue Link to comment
Captain Cody Posted March 25, 2016 Share Posted March 25, 2016 This is indeed outputting the image. I threw in outputChatBox(image) and it is indeed outputting the image file path. So it's something wrong on your side. But for some reason it is only outputting the first image. I'll fix it and post code Link to comment
..:D&G:.. Posted March 25, 2016 Author Share Posted March 25, 2016 I think I know why it's not working... It's because I took off onClientRender so that it doesn't create 100 of renders. Link to comment
Captain Cody Posted March 25, 2016 Share Posted March 25, 2016 Well atm it is not adding onto i for some reason. Link to comment
..:D&G:.. Posted March 25, 2016 Author Share Posted March 25, 2016 Well atm it is not adding onto i for some reason. Managed to make it add, by adding this in the code: i = i+1 Link to comment
Captain Cody Posted March 25, 2016 Share Posted March 25, 2016 local ap = 0 local apmode = true local images ={ ":Main/files/images/menu_bg1.jpg", ":Main/files/images/menu_bg2.jpg", ":Main/files/images/menu_bg3.jpg", ":Main/files/images/menu_bg4.jpg", ":Main/files/images/menu_bg5.jpg", ":Main/files/images/menu_bg6.jpg" } function testBackground(current) if apmode == true then if ap < 255 then ap = ap + 5 else ap = 255 end else if ap > 0 then ap = ap - 5 else ap = 0 end end image = images[current] if current == 6 then current = 0 end -- outputChatBox(image) dxDrawImage(s[1]*0/1440,s[2]*0/900, s[1]*1440/1440,s[2]*900/900, image, 0, 0, 0, tocolor(255, 255, 255, ap),false) ia = current + 1 timer = setTimer(testBackground,500,1,ia) end testBackground(1) Try that. Link to comment
..:D&G:.. Posted March 25, 2016 Author Share Posted March 25, 2016 local ap = 0 local apmode = true local images ={ ":Main/files/images/menu_bg1.jpg", ":Main/files/images/menu_bg2.jpg", ":Main/files/images/menu_bg3.jpg", ":Main/files/images/menu_bg4.jpg", ":Main/files/images/menu_bg5.jpg", ":Main/files/images/menu_bg6.jpg" } function testBackground(current) if apmode == true then if ap < 255 then ap = ap + 5 else ap = 255 end else if ap > 0 then ap = ap - 5 else ap = 0 end end image = images[current] if current == 6 then current = 0 end -- outputChatBox(image) dxDrawImage(s[1]*0/1440,s[2]*0/900, s[1]*1440/1440,s[2]*900/900, image, 0, 0, 0, tocolor(255, 255, 255, ap),false) ia = current + 1 timer = setTimer(testBackground,500,1,ia) end testBackground(1) Try that. Oh gosh, I did that before and I ended up creating 100 of timers and crashed the server Link to comment
..:D&G:.. Posted March 25, 2016 Author Share Posted March 25, 2016 The pictures just flash on the screen for like half a second. If you want I can give you the server details and you can have a look. Link to comment
Captain Cody Posted March 25, 2016 Share Posted March 25, 2016 Oh wait time = 5000 local ap = 0 local apmode = true local images ={ ":Main/files/images/menu_bg1.jpg", ":Main/files/images/menu_bg2.jpg", ":Main/files/images/menu_bg3.jpg", ":Main/files/images/menu_bg4.jpg", ":Main/files/images/menu_bg5.jpg", ":Main/files/images/menu_bg6.jpg" } function testBackground(current) if apmode == true then if ap < 255 then ap = ap + 5 else ap = 255 end else if ap > 0 then ap = ap - 5 else ap = 0 end end image = images[current] if current == 6 then current = 0 end -- outputChatBox(image) dxDrawImage(s[1]*0/1440,s[2]*0/900, s[1]*1440/1440,s[2]*900/900, image, 0, 0, 0, tocolor(255, 255, 255, ap),false) ia = current + 1 if isTimer (timer) then KillTimer(timer) end timer = nil timer = setTimer(testBackground,time,1,ia) end testBackground(1) This checks if timer is still there if so kills it and sets it to nil, then creates a new one. - And fixed your flashing timer was not defined. WAIT nvm, lemme hurry up and script something to fix that. Link to comment
Captain Cody Posted March 25, 2016 Share Posted March 25, 2016 Try this time = 5000 local ap = 0 local apmode = true local images ={ ":Main/files/images/menu_bg1.jpg", ":Main/files/images/menu_bg2.jpg", ":Main/files/images/menu_bg3.jpg", ":Main/files/images/menu_bg4.jpg", ":Main/files/images/menu_bg5.jpg", ":Main/files/images/menu_bg6.jpg" } function testBackground(current) if apmode == true then if ap < 255 then ap = ap + 5 else ap = 255 end else if ap > 0 then ap = ap - 5 else ap = 0 end end image = images[current] if current == 6 then current = 0 end ia = current + 1 if isTimer (timer) then KillTimer(timer) end timer = nil timer = setTimer(testBackground,time,1,ia) end testBackground(1) function createImage() dxDrawImage(s[1]*0/1440,s[2]*0/900, s[1]*1440/1440,s[2]*900/900, image, 0, 0, 0, tocolor(255, 255, 255, ap),false) end addEventHandler("onClientRender",root,createImage) The timer defines the image, and the settings The onClientRender creates the actual image. Link to comment
..:D&G:.. Posted March 25, 2016 Author Share Posted March 25, 2016 Well it kinda works, but the images don't fade in and out as they should... And their alpha is like 50, I can barely see them, lol Link to comment
Captain Cody Posted March 25, 2016 Share Posted March 25, 2016 So you want them to fade in / out?, easy enough. Link to comment
..:D&G:.. Posted March 25, 2016 Author Share Posted March 25, 2016 So you want them to fade in / out?, easy enough. Well, this was supposed to do that: if apmode == true then if ap < 255 then ap = ap + 5 else ap = 255 end else if ap > 0 then ap = ap - 5 else ap = 0 end end It fades out at the first image, then nothing, it just changed to the next image. Link to comment
Captain Cody Posted March 25, 2016 Share Posted March 25, 2016 I'm trying to fix that atm. Link to comment
Captain Cody Posted March 25, 2016 Share Posted March 25, 2016 Not tested at all, may need some ajusting. But time = 50000 local ap = 0 local apmode = true local images ={ ":Main/files/images/menu_bg1.jpg", ":Main/files/images/menu_bg2.jpg", ":Main/files/images/menu_bg3.jpg", ":Main/files/images/menu_bg4.jpg", ":Main/files/images/menu_bg5.jpg", ":Main/files/images/menu_bg6.jpg" } function testBackground(current) setTimer(triggerAlpha,time-10000,1) setTimer(setAlpha,5000,2,true) image = images[current] if current == 6 then current = 0 end ia = current + 1 if isTimer (timer) then KillTimer(timer) end timer = nil timer = setTimer(testBackground,time,1,ia) end testBackground(1) function triggerAlpha () setAlpha (false) setTimer(setAlpha,5000,1,false) end function setAlpha (increase) if not apmode then return end app = ap if increase then ap = app + 50 else ap = app - 50 end end function createImage() dxDrawImage(s[1]*0/1440,s[2]*0/900, s[1]*1440/1440,s[2]*900/900, image, 0, 0, 0, tocolor(255, 255, 255, ap),false) end addEventHandler("onClientRender",root,createImage) Should be quite easy to ajust the timers for fading in / fading out if you set the right values. 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