FadeCamera: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (First argument of setTimer is now a function pointer, not a string)
mNo edit summary
Line 1: Line 1:
{{Server client function}}
__NOTOC__
__NOTOC__
This function will fade a player's camera to a color or back to normal over a specified time period. This will also effect the sound volume for the player (%50 faded = %50 volume, full fade = no sound). For clientside scripts you can perform 2 fade ins or fade outs in a row, but for serverside scripts you must use one then the other
This function will fade a player's camera to a color or back to normal over a specified time period. This will also effect the sound volume for the player (%50 faded = %50 volume, full fade = no sound). For clientside scripts you can perform 2 fade ins or fade outs in a row, but for serverside scripts you must use one then the other.


==Syntax==
==Syntax==
Line 8: Line 9:


===Required Arguments===
===Required Arguments===
* '''thePlayer:''' The player whos camera you wish to fade.
* '''thePlayer:''' The player whose camera you wish to fade.
* '''fadeIn:''' Should the camera be faded in our out? Pass ''true'' to fade the camera in, ''false'' to fade it out to a color.
* '''fadeIn:''' Should the camera be faded in our out? Pass ''true'' to fade the camera in, ''false'' to fade it out to a color.


===Optional Arguments===
===Optional Arguments===
* '''timeToFade''' The number of seconds it should take to fade.
* '''timeToFade:''' The number of seconds it should take to fade.
* '''red''' The ammount of red in the color that the camera fades out to (0 - 255). Not require for fading in.
* '''red:''' The amount of red in the color that the camera fades out to (0 - 255). Not required for fading in.
* '''green''' The ammount of green in the color that the camera fades out to (0 - 255). Not require for fading in.
* '''green:''' The amount of green in the color that the camera fades out to (0 - 255). Not required for fading in.
* '''blue''' The ammount of blue in the color that the camera fades out to (0 - 255). Not require for fading in.
* '''blue:''' The amount of blue in the color that the camera fades out to (0 - 255). Not required for fading in.


===Returns===
===Returns===
Returns ''true'' if the camera was faded succesfully, ''false'' if invalid arguments were passed to the function.
Returns ''true'' if the camera was faded successfully, ''false'' if invalid arguments were passed to the function.


==Example==
==Example==
This example fades a player called ''someguy'''s camera to red over a period of 2 seconds, then after half a second fade it back to normal again over a period of 1 second.
When a player gets damaged, place a quick fade-to-red effect on his screen.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
myPlayer = getPlayerFromNick ( "someguy" ) -- find a player called someguy to test this on
function onPlayerDamage ( )
fadeCamera ( myPlayer, false, 2.0, 255, 0, 0 ) -- fade the player's camera to red over a period of 2 seconds
      fadeCamera ( source, false, 1.0, 255, 0, 0 )         -- fade the player's camera to red over a period of 1 second
setTimer ( fadeCamera, 2500, 1, myPlayer, true, 1.0 ) -- set a timer to fade it back again in 2.5 seconds over 1 second
      setTimer ( fadeCamera, 500, 1, source, true, 0.5 )   -- don't let it go to opaque red, interrupt it after half a second and fade back to normal
end
addEventHandler ( "onPlayerDamage", getRootElement(), onPlayerDamage )
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Camera functions}}
{{Camera functions}}

Revision as of 12:41, 21 August 2007

This function will fade a player's camera to a color or back to normal over a specified time period. This will also effect the sound volume for the player (%50 faded = %50 volume, full fade = no sound). For clientside scripts you can perform 2 fade ins or fade outs in a row, but for serverside scripts you must use one then the other.

Syntax

bool fadeCamera ( player thePlayer, bool fadeIn, [ float timeToFade = 1.0, int red = 0, int green = 0, int blue = 0 ] )

Required Arguments

  • thePlayer: The player whose camera you wish to fade.
  • fadeIn: Should the camera be faded in our out? Pass true to fade the camera in, false to fade it out to a color.

Optional Arguments

  • timeToFade: The number of seconds it should take to fade.
  • red: The amount of red in the color that the camera fades out to (0 - 255). Not required for fading in.
  • green: The amount of green in the color that the camera fades out to (0 - 255). Not required for fading in.
  • blue: The amount of blue in the color that the camera fades out to (0 - 255). Not required for fading in.

Returns

Returns true if the camera was faded successfully, false if invalid arguments were passed to the function.

Example

When a player gets damaged, place a quick fade-to-red effect on his screen.

function onPlayerDamage ( )
      fadeCamera ( source, false, 1.0, 255, 0, 0 )         -- fade the player's camera to red over a period of 1 second
      setTimer ( fadeCamera, 500, 1, source, true, 0.5 )   -- don't let it go to opaque red, interrupt it after half a second and fade back to normal
end
addEventHandler ( "onPlayerDamage", getRootElement(), onPlayerDamage )

See Also