Jump to content

Helpful function to use fadeCamera in smooth way


FIY9AL

Recommended Posts

Server Side:

function eyeBlink(fadeoutTime, waitTime, fadeinTime, player)
    -- fading time must be in seconds, waiting time must be in milliseconds.
    fadeCamera(player, false, fadeoutTime, 0, 0, 0)
    function fadeIn()
        fadeCamera(player, true, fadeinTime, 0, 0, 0)
    end
    setTimer(fadeIn, waitTime, 1)
end

To use it just write:

eyeBlink(0.5, 500, 0.5, player)

Have a nice day .

Edited by FIY9AL
Link to comment

Hello FIY9AL,

I think this is a working function, cool! What you could improve though is setting the internal fadeIn function to be a local function, like this:

    local function fadeIn()
        fadeCamera(player, true, fadeinTime, 0, 0, 0)
    end

Then the function does not leak to the global namespace.

If we were to discuss the user friendliness, I could argue that you'd reorder function arguments so that player is the first argument and then default the waitTime and fadeinTime argument to be the same as fadeoutTime (of course multiply waitTime by 1000 to get ms time). This is because then you could simply write:

eyeBlink(player, 0.5)

 

  • Like 1
Link to comment
2 minutes ago, The_GTA said:

Hello FIY9AL,

I think this is a working function, cool! What you could improve though is setting the internal fadeIn function to be a local function, like this:


    local function fadeIn()
        fadeCamera(player, true, fadeinTime, 0, 0, 0)
    end

Then the function does not leak to the global namespace.

If we were to discuss the user friendliness, I could argue that you'd reorder function arguments so that player is the first argument and then default the waitTime and fadeinTime argument to be the same as fadeoutTime (of course multiply waitTime by 1000 to get ms time). This is because then you could simply write:


eyeBlink(player, 0.5)

 

Nice job upgrading my function i will use it, thank you for your time ?

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