Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Light script question and tint question

I am using a script I found on the internet that has to do with lighting. I'll post the script here in a min. The problem I am having with it is that fact if I use the same light source in the script in more than one spot the 2nd place I use it the script doesn't work. Can anyone tell me why? Here is the script.

Code:
#==============================================================================

# â–  Light Effects VX 1.1

#     5.21.2008

#------------------------------------------------------------------------------

#  Script by: Kylock (originally for RMXP by Near Fantastica)

#==============================================================================

#   To make an event glow, give it a Comment: with any of the supported light

# modes.

#   The SWITCH setting below will disable light effects from updating with the

# switch is on.

#==============================================================================

# ● Change Log

#------------------------------------------------------------------------------

# 1.0 - Original Release

# 1.1 - New light modes added: LIGHT2, TORCH, TORCH2

#     - Changed sprite blend mode to ADD (looks slightly better)

#     - Fire-based lights are now red in color

#==============================================================================

# ● Light Modes

#------------------------------------------------------------------------------

#   GROUND - Medium steady white light.

#   FIRE   - Large red light with a slight flicker.

#   LIGHT  - Small steady white light.

#   LIGHT2 - X-Large steady white light.

#   TORCH  - X-Large red light with a heavy flicker.

#   TORCH2 - X-Large red light with a sleight flicker.

#==============================================================================

 

class Spriteset_Map

  alias les_spriteset_map_initalize initialize

  alias les_spriteset_map_dispose dispose

  alias les_spriteset_map_update update

  def initialize

    @light_effects = []

    setup_lights

    les_spriteset_map_initalize

    update

  end

  def dispose

    les_spriteset_map_dispose

    for effect in @light_effects

      effect.light.dispose

    end

    @light_effects = []

  end

  def update

    les_spriteset_map_update

    update_light_effects

  end

  def setup_lights

    for event in $game_map.events.values

      next if event.list == nil

      for i in 0...event.list.size

        if event.list[i].code == 108 and event.list[i].parameters == ["GROUND"]

          type = "GROUND"

          light_effects = Light_Effect.new(event,type)

          light_effects.light.zoom_x = 2

          light_effects.light.zoom_y = 2

          light_effects.light.opacity = 100

          @light_effects.push(light_effects)

        end

        if event.list[i].code == 108 and event.list[i].parameters == ["FIRE"]

          type = "FIRE"

          light_effects = Light_Effect.new(event,type)

          light_effects.light.zoom_x = 300 / 100.0

          light_effects.light.zoom_y = 300 / 100.0

          light_effects.light.opacity = 100

          @light_effects.push(light_effects)

        end

        if event.list[i].code == 108 and event.list[i].parameters == ["LIGHT"]

          type = "LIGHT"

          light_effects = Light_Effect.new(event,type)

          light_effects.light.zoom_x = 1

          light_effects.light.zoom_y = 1

          light_effects.light.opacity = 150

          @light_effects.push(light_effects)

        end

        if event.list[i].code == 108 and event.list[i].parameters == ["LIGHT2"]

          type = "LIGHT2"

          light_effects = Light_Effect.new(event,type)

          light_effects.light.zoom_x = 6

          light_effects.light.zoom_y = 6

          light_effects.light.opacity = 150

          @light_effects.push(light_effects)

        end

        if event.list[i].code == 108 and event.list[i].parameters == ["TORCH"]

          type = "TORCH"

          light_effects = Light_Effect.new(event,type)

          light_effects.light.zoom_x = 6

          light_effects.light.zoom_y = 6

          light_effects.light.opacity = 150

          @light_effects.push(light_effects)

        end

        if event.list[i].code == 108 and event.list[i].parameters == ["TORCH2"]

          type = "TORCH2"

          light_effects = Light_Effect.new(event,type)

          light_effects.light.zoom_x = 6

          light_effects.light.zoom_y = 6

          light_effects.light.opacity = 150

          @light_effects.push(light_effects)

        end

      end

    end

    for effect in @light_effects

      case effect.type

      when "GROUND"

        effect.light.x = (effect.event.real_x - 400 - $game_map.display_x) / 8

        effect.light.y = (effect.event.real_y - 400 - $game_map.display_y) / 8

        effect.light.blend_type = 1

      when "FIRE"

        effect.light.x = (effect.event.real_x - 600 - $game_map.display_x) / 8 + rand(6) - 3

        effect.light.y = (effect.event.real_y - 600 - $game_map.display_y) / 8 + rand(6) - 3

        effect.light.tone = Tone.new(255,-100,-255,   0)

        effect.light.blend_type = 1

      when "LIGHT"

        effect.light.x = (-0.25 / 2 * $game_map.display_x) + (effect.event.x * 32) - 15

        effect.light.y = (-0.25 / 2 * $game_map.display_y) + (effect.event.y * 32) - 15

        effect.light.blend_type = 1

      when "LIGHT2"

        effect.light.x = (effect.event.real_x - 1200 - $game_map.display_x) / 8 - 20

        effect.light.y = (effect.event.real_y - 1200 - $game_map.display_y) / 8

        effect.light.blend_type = 1

      when "TORCH"

        effect.light.x = (effect.event.real_x - 1200 - $game_map.display_x) / 8 - 20

        effect.light.y = (effect.event.real_y - 1200 - $game_map.display_y) / 8

        effect.light.tone = Tone.new(255,-100,-255,   0)

        effect.light.blend_type = 1

      when "TORCH2"

        effect.light.x = (effect.event.real_x - 1200 - $game_map.display_x) / 8 - 20

        effect.light.y = (effect.event.real_y - 1200 - $game_map.display_y) / 8

        effect.light.tone = Tone.new(255,-100,-255,   0)

        effect.light.blend_type = 1

      end

    end

  end

  def update_light_effects

    if $game_switches[1]

      for effect in @light_effects

        next if effect.type == "FIRE" || effect.type == "TORCH"

        effect.light.visible = false

      end

    else

      for effect in @light_effects

        next if effect.type == "FIRE" || effect.type == "TORCH"

        effect.light.visible = true

      end

    end

    for effect in @light_effects

      case effect.type

      when "GROUND"

        effect.light.x = (effect.event.real_x - 400 - $game_map.display_x) / 8

        effect.light.y = (effect.event.real_y - 400 - $game_map.display_y) / 8

      when "FIRE"

        effect.light.x = (effect.event.real_x - 600 - $game_map.display_x) / 8 + rand(6) - 3

        effect.light.y = (effect.event.real_y - 600 - $game_map.display_y) / 8 + rand(6) - 3

        effect.light.opacity = rand(10) + 90

      when "LIGHT"

        effect.light.x = (-0.25 / 2 * $game_map.display_x) + (effect.event.x * 32) - 15

        effect.light.y = (-0.25 / 2 * $game_map.display_y) + (effect.event.y * 32) - 15

      when "LIGHT2"

        effect.light.x = (effect.event.real_x - 1200 - $game_map.display_x) / 8 - 20

        effect.light.y = (effect.event.real_y - 1200 - $game_map.display_y) / 8

      when "TORCH"

        effect.light.x = (effect.event.real_x - 1200 - $game_map.display_x) / 8 - 20 + rand(20) - 10

        effect.light.y = (effect.event.real_y - 1200 - $game_map.display_y) / 8 + rand(20) - 10

        effect.light.opacity = rand(30) + 70

      when "TORCH2"

        effect.light.x = (effect.event.real_x - 1200 - $game_map.display_x) / 8 - 20

        effect.light.y = (effect.event.real_y - 1200 - $game_map.display_y) / 8

        effect.light.opacity = rand(10) + 90

      end

    end

  end

end

 

class Light_Effect

  attr_accessor :light

  attr_accessor :event

  attr_accessor :type

  def initialize(event, type)

    @light = Sprite.new

    @light.bitmap = Cache.picture("le.png")

    @light.visible = true

    @light.z = 1000

    @event = event

    @type = type

  end

end

I have the picture uploaded and it works the first time I do it but the 2nd time it doesn't. Also in the same places I have an event that changes the tint of the screen and have another one that tints it back to normal on the regular map.. is there a better way of doing it so that when you are in the places I want tinted it is tinted then when you go to leave it automatically changes it back or did I do the right thing by putting another tint event in the world.

EDIT*

Ok I figured out the lighting thing.. it's because I am using an old saved game to test my scripts and since I changed the data in the new version it isn't the same in the old save file. If I start a new game and put the starting point outside my 2nd cave and go in it works fine. Still have the question about the tint event though :)

I love when I figure something out heh :)
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top