FadeCamera: Difference between revisions
Jump to navigation
Jump to search
(Undo revision 34876 by Prestege Stop trashing the wiki.) |
Qwe7769611 (talk | contribs) No edit summary |
||
(19 intermediate revisions by 13 users not shown) | |||
Line 2: | Line 2: | ||
__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 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. | 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. | ||
{{Note|The speed of the effect depends directly on the current gamespeed.}} | |||
==Syntax== | ==Syntax== | ||
Line 8: | Line 9: | ||
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 ] ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP||[[player]]:fadeCamera}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
* '''thePlayer:''' The player whose camera you wish to fade. | * '''thePlayer:''' The player whose camera you wish to fade. | ||
* '''fadeIn:''' Should the camera be faded in | * '''fadeIn:''' Should the camera be faded in or 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 amount of red in the color that the camera fades out to (0 - 255). Not required 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 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. | ||
Line 24: | Line 25: | ||
bool fadeCamera ( bool fadeIn, [ float timeToFade = 1.0, int red = 0, int green = 0, int blue = 0 ] ) | bool fadeCamera ( bool fadeIn, [ float timeToFade = 1.0, int red = 0, int green = 0, int blue = 0 ] ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP||Camera.fade}} | |||
===Required Arguments=== | ===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. | * '''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 amount of red in the color that the camera fades out to (0 - 255). Not required 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 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. | ||
Line 44: | Line 45: | ||
function addRednessOnDamage ( ) | function addRednessOnDamage ( ) | ||
fadeCamera ( source, false, 1.0, 255, 0, 0 ) -- fade the player's camera to red over a period of 1 second | fadeCamera ( source, false, 1.0, 255, 0, 0 ) -- fade the player's camera to red over a period of 1 second | ||
setTimer ( | setTimer ( fadeCameraDelayed, 500, 1, source ) -- don't let it go to opaque red, interrupt it after half a second and fade back to normal | ||
end | |||
addEventHandler ( "onPlayerDamage", root, addRednessOnDamage ) | |||
function fadeCameraDelayed(player) -- This function prevents debug warnings when the player disconnects while the timer is running. | |||
if (isElement(player)) then | |||
fadeCamera(player, true, 0.5) | |||
end | |||
end | end | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> | ||
==See Also== | ==See Also== | ||
{{ | {{Camera_functions}} | ||
[[hu:fadeCamera]] | |||
[[RO:fadeCamera]] | |||
[[zh-cn:fadeCamera]] |
Latest revision as of 02:38, 3 February 2021
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 [-]
Serverbool fadeCamera ( player thePlayer, bool fadeIn, [ float timeToFade = 1.0, int red = 0, int green = 0, int blue = 0 ] )
OOP Syntax Help! I don't understand this!
- Method: player:fadeCamera(...)
Required Arguments
- thePlayer: The player whose camera you wish to fade.
- fadeIn: Should the camera be faded in or 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 [-]
Clientbool fadeCamera ( bool fadeIn, [ float timeToFade = 1.0, int red = 0, int green = 0, int blue = 0 ] )
OOP Syntax Help! I don't understand this!
- Method: Camera.fade(...)
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 exampleWhen 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 ( fadeCameraDelayed, 500, 1, source ) -- don't let it go to opaque red, interrupt it after half a second and fade back to normal end addEventHandler ( "onPlayerDamage", root, addRednessOnDamage ) function fadeCameraDelayed(player) -- This function prevents debug warnings when the player disconnects while the timer is running. if (isElement(player)) then fadeCamera(player, true, 0.5) end end