FadeCamera: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
Line 1: Line 1:
{{Server client function}}
{{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 affect 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==
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool fadeCamera ( player thePlayer, bool fadeIn, [ float timeToFade = 1.0, int red = 0, int green = 0, int blue = 0 ] )
bool fadeCamera ( player thePlayer, bool fadeIn, [ float timeToFade = 1.0, int red = 0, int green = 0, int blue = 0 ] )
Line 17: Line 18:
* '''green:''' The amount of green 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.
* '''blue:''' The amount of blue in the color that the camera fades out to (0 - 255). Not required for fading in.
</section>
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
bool fadeCamera ( bool fadeIn, [ float timeToFade = 1.0, int red = 0, int green = 0, int blue = 0 ] )
</syntaxhighlight>
===Required Arguments===
* '''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.
</section>


===Returns===
===Returns===
Line 22: Line 39:


==Example==
==Example==
<section name="Server example" class="server" show="true">
When a player gets damaged, place a quick fade-to-red effect on his screen.
When a player gets damaged, place a quick fade-to-red effect on his screen.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
Line 30: Line 48:
addEventHandler ( "onPlayerDamage", getRootElement(), addRednessOnDamage )
addEventHandler ( "onPlayerDamage", getRootElement(), addRednessOnDamage )
</syntaxhighlight>
</syntaxhighlight>
</section>


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

Revision as of 20:13, 7 February 2008

This function will fade a player's camera to a color or back to normal over a specified time period. This will also affect 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

Click to collapse [-]
Server
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.
Click to collapse [-]
Client
bool fadeCamera ( bool fadeIn, [ float timeToFade = 1.0, int red = 0, int green = 0, int blue = 0 ] )

Required Arguments

  • 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

Click to collapse [-]
Server example

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

function addRednessOnDamage ( )
      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(), addRednessOnDamage )

See Also