Zeus81

Zeus Lights & Shadows : User Guide

Jul 26th, 2013
3,850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 21.83 KB | None | 0 0
  1. # Zeus Lights & Shadows : User Guide v1.3
  2. =begin
  3.   Description :
  4.       This script allows you to display lights effects and shadows.
  5.       There are already a lot of scripts to do that, but my goal with this one
  6.       is to do something different.
  7.       Thus lights illuminate the night, ie you can set the screen tone to whole
  8.       black (-255) and lights will act like holes in a mask and will allow us to
  9.       see the map clearly.
  10.       The shadows on the other hand are not dynamic, lights generate no shadow,
  11.       shadows must be placed manually, much like on VXace, we can consider that
  12.       they are all shadows of the sun.
  13.       The shadows are not superposed (which is absurd), but merged.
  14.       The shadows are not above but below all, you can have the head passes in
  15.       front of a shadow, the character darken only when they walk in the shade.
  16.       The opacity of shadows declines with the brightness of the map,
  17.       ie no shade from the sun at night.
  18.       Auto shadows of VX and VXace are managed by this script.
  19.       There's also an option to disable them at the very beginning of the script.
  20.       The following commands are all to be used in scripts inserts.
  21.    
  22.   Log Change :
  23.     1.3 :
  24.       - new option to disable lights at the beginning of the script
  25.       - new option to disable shadows at the beginning of the script
  26.       - new option in events to prevent them from being darkened
  27.       - new option in shadows to setup if they should darken characters or not
  28.       - new option that allow to create lights/shadows without naming them
  29.         they will be named automatically with the id of their event
  30.       - fixed display bug related to scripts that change the game size during
  31.         game on map even if it's a nonsense
  32.       - fixed display bug related to shake screen
  33.     1.2 :
  34.       - fixed bug on XP
  35.       - added quick overview of functions below
  36.     1.1 :
  37.       - fixed bug related to region id on VXace
  38.      
  39.   Recommendations for use :
  40.       1/ player/vehicles vs events/map
  41.           The script allow us to link lights/shadows to player, vehicles, events
  42.           or directly to map.
  43.           Those associated with player/vehicles are saved from a map to another,
  44.           we need to initialize them once and they will remain until we decide to
  45.           remove them.
  46.           However for events/maps it's the opposite, lights/shadows are deleted
  47.           every time we transfer from a map, we must ensure that they are reset
  48.           every time we enter the map.
  49.       2/ initialization
  50.           I've created a special command that allow to automatically execute
  51.           scripts on events loading, we use it like this :
  52.             Comment: <setup>
  53.             Script: ...lights/shadows initialization scripts...
  54.             Comment: </setup>
  55.           All that lies between the <setup> tags will be executed automatically
  56.           (and only) when loading the page (even if it's supposed to be triggered
  57.           by the action button).
  58.           Actually if you want you can put anything other than scripts between
  59.           these two tags, just avoid the commands that are waiting for
  60.           completion​​/validation (like messages) otherwise your game will explode.
  61.           We can initialize all our lights from a single event if we want to,
  62.           that said if we decide to link our light to an event perhaps it would
  63.           be more convenient to have the initialization done directly within.
  64.           If an event have several pages only commands in the active page will
  65.           be executed.
  66.    
  67.   Overview :
  68.     - light(key).setup(filename)
  69.     - light(key).chara_id = n
  70.     - light(key).clear
  71.     - light(key).active
  72.     - light(key).set_pos(x, y, duration)
  73.     - light(key).set_origin(x, y, duration)
  74.     - light(key).set_parallax(x, y, duration)
  75.     - light(key).set_opacity(opacity, duration)
  76.     - light(key).set_color(red, green, blue, alpha, duration)
  77.     - light(key).set_zoom(zoom, duration)
  78.     - light(key).set_flicker(variance, refresh_rate, duration)
  79.     - light(key).set_angle(angle, duration)
  80.     - light(key).set_wave(amp, length, speed, duration)
  81.     - light(key).visible = true ou false
  82.     - light(key).blend_type = 0 ou 1 ou 2
  83.     - light(key).directions = n
  84.     - light(key).patterns = n
  85.     - light(key).anime_rate = n
  86.     - shadow(key).setup(filename)
  87.     - shadow(key).setup(width, height)
  88.     - shadow(key).chara_id = n
  89.     - shadow(key).clear
  90.     - shadow(key).active
  91.     - shadow(key).set_pos(x, y, duration)
  92.     - shadow(key).set_origin(x, y, duration)
  93.     - shadow(key).set_parallax(x, y, duration)
  94.     - shadow(key).set_opacity(opacity, duration)
  95.     - shadow(key).set_color(red, green, blue, alpha, duration)
  96.     - shadow(key).set_zoom(zoom, duration)
  97.     - shadow(key).visible = true ou false
  98.     - shadow(key).directions = n
  99.     - shadow(key).patterns = n
  100.     - shadow(key).anime_rate = n
  101.     - shadow(key).shadowable = true or false
  102.     - set_shadowable(value, chara_id)
  103.    
  104.   Lights :
  105.     - light(key).setup(filename)
  106.             Initializes a new light.
  107.         key = an identifier for our light, each light must have a name of its own.
  108.             We reuses its identifier whenever we want to change a light.
  109.             We can put no key, the script will then generate one automatically
  110.             taking the id of the event that runs the script, for example "event5".
  111.             This can be useful if for example we put a light in an event and we
  112.             want to do copy/paste, rather than having to change the name in each
  113.             copy we can put no key and let the script name them.
  114.         filename = the file name used for the light.
  115.             The extension is not mandatory.
  116.             The file must be in the Pictures folder, you can use subfolders if
  117.             you want with / as separators.
  118.             The light must be black with transparent backgrounds,
  119.             it's important for the internal workings of the script.
  120.             To add color to the light It's explained below.
  121.         Example :
  122.             light("light 1").setup("torch.png") # new light
  123.             light.setup("torch.png") # new light without name
  124.            
  125.     - light(key).chara_id = n
  126.             Allows to link a light to a character (event, player, vehicle).
  127.             It has several effects, light will automatically follow its character.
  128.             The light will synchronize direction and animation if possible.
  129.             If associated with an event the light will disappear if the event is
  130.             transparent, erased, or if it has no active page (aka if the
  131.             conditions of any of its pages are met).
  132.         n = id of the character on which to display the light.
  133.             If we put 0 the light will not follow any character, it will have
  134.             coordinates related to map.
  135.             If we put a number > 0, the light will follow the corresponding event.
  136.             If we put @event_id it means "this event", which runs the script.
  137.             If we put -1 the light will follow the player.
  138.             If we put -2, -3, -4, it's for followers. (VXace only)
  139.             If we put -5, -6, -7, it's for vehicles (VX & VXace only)
  140.             respectively boat, ship and airship.
  141.             Default value is 0.
  142.         Example :
  143.             light("light 1").chara_id = -1 # links light to player
  144.            
  145.     - light(key).clear
  146.             Delete the light.
  147.         Example :
  148.             light("light 1").clear
  149.            
  150.     - light(key).active
  151.             Return true or false weither the light is exists or not.
  152.             It's made ​​to be used in conditions.
  153.         Example :
  154.             light("light 1").active == true # does the light exists ?
  155.             light("light 1").active == false # the light have been deleted ?
  156.        
  157.     - light(key).set_pos(x, y, duration)
  158.             If there is no chara_id the coordinates of the light will be defined
  159.             relative to the left corner of the map.
  160.             If there is a chara_id the coordinates of the light will automatically
  161.             be those from the selected character, this function will then be used
  162.             to define an offset.
  163.         x = x coordinate in pixels
  164.         y = y coordinate in pixels
  165.         duration = transition time in number of frames.
  166.             The coordinates will change between the current value and the
  167.             required on the given duration.
  168.             It can afford to meke the light move.
  169.             0 = no transition.
  170.             We can omit this argument, which will put its value to 0.
  171.             It will be the same everywhere so I won't repeat.
  172.         Example :
  173.             light("light 1").set_pos(128, 256, 60) # set_pos with 60 frames transition
  174.             light("light 1").set_pos(128, 256) # set_pos without transition
  175.            
  176.     - light(key).set_origin(x, y, duration)
  177.             Change the origin of the image.
  178.         x = x coordinate of center of the image as a percentage.
  179.             0 = leftmost.
  180.             100 = rightmost.
  181.             Default value is 50.
  182.         y = y coordinate of center of the image as a percentage.
  183.             0 = topmost.
  184.             100 = bottommost.
  185.             Default value is 50.
  186.         Example :
  187.             light("light 1").set_origin(0, 0) # Origin to top-left corner
  188.            
  189.     - light(key).set_parallax(x, y, duration)
  190.             This option allows you to manage the level of anchor of the light on
  191.             the map, ie when the map scrolls the light scroll at different speeds.
  192.             By default values ​​are 1, which means that lights scroll at the same
  193.             speed as the map.
  194.             If we put 2 the lights will scroll twice faster than the map.
  195.             If we put 0 the lights will no longer scroll, as if they were
  196.             anchored to the screen.
  197.             You can also put decimals like 0.5 to scroll slower or negative
  198.             numbers to reverse the direction of scrolling.
  199.             However, this is only for lights affiliated to the map,
  200.             if the light follows a character this option won't work.
  201.         x = horizontal anchor.
  202.             Default value is 1.
  203.         y = vertical anchor.
  204.             Default value is 1.
  205.         Example :
  206.             light("light 1").set_parallax(0, 0) # light anchored to screen
  207.            
  208.     - light(key).set_opacity(opacity, duration)
  209.             Changes the opacity of the light, which will have the effect of
  210.             making it shines less on day and lights less at night too.
  211.             If we just want to make it shine less days while illuminating well
  212.             at night we should lower the alpha component of the color.
  213.         opacity = percentage between 0 and 100.
  214.             Default value is 100.
  215.         Example :
  216.             light("light 1").set_opacity(75, 60)
  217.            
  218.     - light(key).set_color(red, green, blue, alpha, duration)
  219.             Applies a color to the light.
  220.             We can have a null color (with all values to 0), the light will be
  221.             invisible on the day, and will only prevent the screen from darkening
  222.             at night (no color).
  223.             To have a black light or who darkened the screen it will be necessary
  224.             to change the blend_type (see below).
  225.         red, green, blue = numbers between 0 and 255.
  226.             These are the components of the color.
  227.             Default value is 0.
  228.         alpha = number between 0 and 255.
  229.             This is the transparency of the color but here it rather is the
  230.             brightness of our light.
  231.             Default value is 255 = 100%.
  232.         Example :
  233.             light("light 1").set_color(255, 0, 0, 255) # => red light
  234.            
  235.     - light(key).set_zoom(zoom, duration)
  236.             Changes the zoom of the light.
  237.         zoom = a percentage.
  238.             Default value is 100.
  239.         Examples :
  240.             light("light 1").set_zoom(200) # => zoom to 200% instant
  241.             light("light 1").set_zoom(200, 60) # => zoom to 200% on 60 frames
  242.            
  243.     - light(key).set_flicker(variance, refresh_rate, duration)
  244.             Makes the light flicker as fire.
  245.             The effect is achieved by changing the zoom randomly.
  246.         variance = amplitude of the flicker in percentage of zoom.
  247.             It must be a number greater than 0.
  248.             It is better to put small numbers.
  249.             Default value is 0 = disabled.
  250.         refresh_rate = interval between each change in number of frames.
  251.             Generally the more the variance is high the more the interval should
  252.             be large to avoid any epileptic thing.
  253.             Default value is 4.
  254.         Example :
  255.             light("light 1").set_flicker(2, 4)
  256.            
  257.     - light(key).set_angle(angle, duration)
  258.             Makes the light rotate...
  259.             It works but only for daylights.
  260.         angle = number of degrees.
  261.             You can also put a negative number.
  262.             Note that if we make a 360° rotation and we want to do another again
  263.             it won't do anything, since we're already at 360° we must either
  264.             go to 720° or reset the value to 0 before trying to return it to 360.
  265.         Example :
  266.             light("light 1").set_angle(360, 60) # => do a barrel roll
  267.            
  268.     - light(key).set_wave(amp, length, speed, duration)
  269.             Makes the light waving.
  270.             It works but only for daylights.
  271.         amp = amplitude (horizontal) of the wave in number of pixels.
  272.             It must be a number greater than 0.
  273.             Default value is 0 = disabled.
  274.         length = length (vertical) of the wave in number of pixels.
  275.             Default value is 180.
  276.         speed = speed of the wave.
  277.             Default value is 360.
  278.         Example :
  279.             light("light 1").set_wave(4, 180, 360, 60)
  280.            
  281.     - light(key).visible = true or false
  282.             Used to hide a light without losing its settings, it can always be useful.
  283.             Default value is true.
  284.         Example :
  285.             light("light 1").visible = false
  286.            
  287.     - light(key).blend_type = 0 or 1 or 2
  288.             Changes the blending of the light.
  289.             If 0 => Normal
  290.             If 1 => Addition
  291.             If 2 => Subtraction
  292.             Default value is 1.
  293.         Example :
  294.             light("light 1").blend_type = 2
  295.            
  296.     - light(key).directions = n
  297.             It is possible to have directional lights, to make flashlights eg.
  298.             This means that when you put a light on a character, the light will
  299.             take the same direction as the character.
  300.             The script can support characters with 2, 4 or 8 directions.
  301.         n = the number of directions.
  302.             The file must be designed for this purpose, it works like a sheet of
  303.             characters, there must have all directions in the same file, one
  304.             above the other in the same order as characters.
  305.             Default value is 1.
  306.         Example :
  307.             light("light 1").directions = 4
  308.            
  309.     - light(key).patterns = n
  310.             As for directions lights can have animations which are synchronized
  311.             with the animation of their character.
  312.             The idea is the same.
  313.         n = the number of animations.
  314.             Here animations should be aligned horizontally in the file as for
  315.             character sheets.
  316.             Default value is 1.
  317.         Example :
  318.             light("light 1").patterns = 4
  319.            
  320.     - light(key).anime_rate = n
  321.             This option can automatically animate the light (Stepping anim somehow).
  322.         n = interval between each animation in number of frames.
  323.             The more it's high the more the animation is slow.
  324.             Default value is 0 = disabled.
  325.         Example :
  326.             light("light 1").anime_rate = 10
  327.      
  328.   Shadows :
  329.            
  330.     - shadow(key).setup(filename)
  331.             Initializes a new shadow.
  332.         key = an identifier for our shadow.
  333.             Works exactly the same way as the lights.
  334.         filename = the file name used for the shadow.
  335.             Here unlike the lights one can colorize the shadows directly in the
  336.             file if needed (although in general the shadows are black).
  337.             Images shadows should not be transparent but full, transparency of
  338.             shadows is handled automatically by the script according to the
  339.             ambient lighting.
  340.         Example :
  341.             shadow("shadow 1").setup("shad.png") # new shadow
  342.             shadow.setup("shad.png") # new shadow without name
  343.            
  344.     - shadow(key).setup(width, height)
  345.             Initializes a new shade without using an image.
  346.             If you need a simple rectangular shade that is simpler and more
  347.             efficient to do like that rather than to create and use images.
  348.         width = the width of the shadow in pixels.
  349.         height = the height of the shadow in pixels.
  350.         Example :
  351.             shadow("shadow 1").setup(32, 96) # new shadow 32x96px size
  352.            
  353.     - shadow(key).chara_id = n
  354.             Allows to link a light to a character (event, player, vehicle).
  355.             The idea is the same as for the lights.
  356.             However Caution, character's shadows cannot darken other characters,
  357.             if you want shadows under which we can pass they must be linked to
  358.             the map.
  359.         n = id of the character under which to display the shadow.
  360.             Works exactly the same way as the light.
  361.         Example :
  362.             shadow("shadow 1").chara_id = -1 # lie l'ombre au héros
  363.            
  364.     - shadow(key).clear
  365.             Works exactly the same way as the light.
  366.         Example :
  367.             shadow("shadow 1").clear # delete shadow
  368.            
  369.     - shadow(key).active
  370.             Works exactly the same way as the light.
  371.         Example :
  372.             shadow("shadow 1").active == true # does the shadow exists ?
  373.        
  374.     - shadow(key).set_pos(x, y, duration)
  375.             Works exactly the same way as the light.
  376.         Example :
  377.             shadow("shadow 1").set_pos(128, 256, 60) # set_pos with 60 frames transition
  378.            
  379.     - shadow(key).set_origin(x, y, duration)
  380.             Change the origin of the image.
  381.             By default, the origin is always at the center as for lights.
  382.             When a shadow is placed on a character it's often better that way
  383.             but usually when we want to put one on the map, we do it relative to
  384.             its upper left corner, so do not forget to change the origin !
  385.         x = x coordinate of center of the image as a percentage.
  386.         y = y coordinate of center of the image as a percentage.
  387.         Example :
  388.             shadow("shadow 1").set_origin(0, 0) # Origin to top-left corner
  389.            
  390.     - shadow(key).set_parallax(x, y, duration)
  391.             Works exactly the same way as the light.
  392.         Example :
  393.             shadow("shadow 1").set_parallax(0, 0) # shadow anchored to screen
  394.            
  395.     - shadow(key).set_opacity(opacity, duration)
  396.             Changes the opacity of the shadow, opacity is already handled
  397.             automatically by the script so it's not much use, but if for some
  398.             reason there's need to lower the opacity of a shadow in particular
  399.             it's possible.
  400.             This option only works if you use an image for the shadow,
  401.             otherwise you should do with the alpha channel of the color.
  402.         opacity = percentage between 0 and 100.
  403.             Default value is 100.
  404.         Example :
  405.             shadow("shadow 1").set_opacity(75, 60)
  406.            
  407.     - shadow(key).set_color(red, green, blue, alpha, duration)
  408.             Set the color of the shadows when not using image.
  409.         red, green, blue = numbers between 0 and 255.
  410.             These are the components of the color.
  411.             Default value is 0 = black.
  412.         alpha = number between 0 and 255.
  413.             It is the opacity of our shadow.
  414.             Default value is 255 = 100%.
  415.         Example :
  416.             shadow("shadow 1").set_color(0, 255, 0, 255) # => green shadow
  417.            
  418.     - shadow(key).set_zoom(zoom, duration)
  419.             Works exactly the same way as the light.
  420.         Example :
  421.             shadow("shadow 1").set_zoom(200) # => zoom to 200% instant
  422.            
  423.     - shadow(key).visible = true or false
  424.             Works exactly the same way as the light.
  425.         Example :
  426.             shadow("shadow 1").visible = false
  427.            
  428.     - shadow(key).directions = n
  429.             Works exactly the same way as the light.
  430.         Example :
  431.             shadow("shadow 1").directions = 4
  432.            
  433.     - shadow(key).patterns = n
  434.             Works exactly the same way as the light.
  435.         Example :
  436.             shadow("shadow 1").patterns = 4
  437.            
  438.     - shadow(key).anime_rate = n
  439.             Works exactly the same way as the light.
  440.         Example :
  441.             shadow("shadow 1").anime_rate = 10
  442.            
  443.     - shadow(key).shadowable = true or false
  444.             Defines whether a shadow should darken characters or not.
  445.             For shadows linked with characters it's important to make them not
  446.             darken, otherwise the linked character will be darkened all the time.
  447.             Default value is true.
  448.         Example :
  449.             shadow("shadow 1").shadowable = false
  450.            
  451.     - set_shadowable(value, chara_id)
  452.             Defines if a character can be darkened or not.
  453.         value = true or false
  454.             Default value is true.
  455.         chara_id = id of the character on which change this option.
  456.             If we put nothing it means "this event", which runs the script,
  457.             as @event_id.
  458.         Example :
  459.             set_shadowable(false, -1) # prevent the player from being darkened
  460.             set_shadowable(false) # prevent "this event" from being darkened
  461. =end
Advertisement
Add Comment
Please, Sign In to add comment