Jump to content

[HELP] Looping through images


..:D&G:..

Recommended Posts

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
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
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
    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 xD 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

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 by Guest
Link to comment

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
    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
    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 xD

Link to comment

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

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
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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...