Help - Search - Members - Calendar
Full Version: Light puzzle event
RPG RPG Revolution Forums > Game Engines > RPG Maker XP Discussion
xxVSxx
Hi

I'm trying to do puzzle with this Near Fantastica Light Effect Script.
Here is the idea:

Click to view attachment

When Actor hits a switch it should light up some of the crystals but I can't get that working.
Light Effect script works fine but adding switch to control lights are a bit difficult. I can't get it working.
Is there any way to do this? It should be just a simple light switch.

CODE
# ? Light Effects
#================================
# ?By: Near Fantastica
#   Date: 28.06.05
#   Version: 3
#================================
#==========INSTRUCTIONS==========

#The first Comment event command in an event should read "Light Effects".  The
#comment event command immediately following it should read "Ground", "Fire",
#"Lamppost", "LeftLantern", or "RightLantern".
#================================
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 == ["Light Effects"]
         type = event.list[i+1].parameters.to_s
         case type.upcase!
         when "GROUND"
           light_effects = Light_Effect.new(event,type)
           light_effects.light.zoom_x = 200 / 100.0
           light_effects.light.zoom_y = 200 / 100.0
           light_effects.light.opacity = 51
           @light_effects.push(light_effects)
         when "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 = 85
           @light_effects.push(light_effects)
         when "LAMPPOST"
           light_effects = Light_Effect.new(event,"LEFT LAMP POST")
           light_effects.light.opacity = 51
           @light_effects.push(light_effects)
           light_effects = Light_Effect.new(event,"RIGHT LAMP POST")
           light_effects.light.opacity = 51
           @light_effects.push(light_effects)
         when "LEFTLANTERN"
           light_effects = Light_Effect.new(event,type)
           light_effects.light.opacity = 150
           @light_effects.push(light_effects)
         when "RIGHTLANTERN"
           light_effects = Light_Effect.new(event,type)
           light_effects.light.opacity = 150
           @light_effects.push(light_effects)
         end
       end
     end
   end
   for effect in @light_effects
     case effect.type
     when "GROUND"
       effect.light.x = (effect.event.real_x - 200 - $game_map.display_x) / 4
       effect.light.y = (effect.event.real_y - 200 - $game_map.display_y) / 4
     when "FIRE"
       effect.light.x = (effect.event.real_x - 300 - $game_map.display_x) / 4
       effect.light.y = (effect.event.real_y - 300 - $game_map.display_y) / 4
     when "LEFT LAMP POST"
       effect.light.x = (-0.25 * $game_map.display_x) + (effect.event.x * 32) - 5
       effect.light.y = (-0.25 * $game_map.display_y) + (effect.event.y * 32) - 15
     when "RIGHT LAMP POST"
       effect.light.x = (-0.25 * $game_map.display_x) + (effect.event.x * 32) - 25
       effect.light.y = (-0.25 * $game_map.display_y) + (effect.event.y * 32) - 15
     when "LEFTLANTERN"
       effect.light.x = (-0.25 * $game_map.display_x) + (effect.event.x * 32) - 20
       effect.light.y = (-0.25 * $game_map.display_y) + (effect.event.y * 32) - 5
     when "RIGHTLANTERN"
       effect.light.x = (-0.25 * $game_map.display_x) + (effect.event.x * 32) - 10
       effect.light.y = (-0.25 * $game_map.display_y) + (effect.event.y * 32) - 5
     end
   end
end
#--------------------------------------------------------------
def update_light_effects
   for effect in @light_effects
     next if not in_range?(effect.event)
     case effect.type
     when "GROUND"
       effect.light.x = (effect.event.real_x - 200 - $game_map.display_x) / 4
       effect.light.y = (effect.event.real_y - 200 - $game_map.display_y) / 4
     when "FIRE"
       effect.light.x = (effect.event.real_x - 300 - $game_map.display_x) / 4
       effect.light.y = (effect.event.real_y - 300 - $game_map.display_y) / 4
     when "LEFT LAMP POST"
       effect.light.x = (-0.25 * $game_map.display_x) + (effect.event.x * 32) - 5
       effect.light.y = (-0.25 * $game_map.display_y) + (effect.event.y * 32) - 15
     when "RIGHT LAMP POST"
       effect.light.x = (-0.25 * $game_map.display_x) + (effect.event.x * 32) - 25
       effect.light.y = (-0.25 * $game_map.display_y) + (effect.event.y * 32) - 15
     when "LEFTLANTERN"
       effect.light.x = (-0.25 * $game_map.display_x) + (effect.event.x * 32) - 20
       effect.light.y = (-0.25 * $game_map.display_y) + (effect.event.y * 32) - 5
     when "RIGHTLANTERN"
       effect.light.x = (-0.25 * $game_map.display_x) + (effect.event.x * 32) - 10
       effect.light.y = (-0.25 * $game_map.display_y) + (effect.event.y * 32) - 5
     end
   end
end
#--------------------------------------------------------------
def in_range?(object)
   screne_x = $game_map.display_x
   screne_x -= 256
   screne_y = $game_map.display_y
   screne_y -= 256
   screne_width = $game_map.display_x
   screne_width += 2816
   screne_height = $game_map.display_y
   screne_height += 2176
   return false if object.real_x <= screne_x
   return false if object.real_x >= screne_width
   return false if object.real_y <= screne_y
   return false if object.real_y >= screne_height
   return true
end
end

#================================
# ? Light Effects Class
#================================

class Light_Effect
#--------------------------------------------------------------
attr_accessor :light
attr_accessor :event
attr_accessor :type
#--------------------------------------------------------------
def initialize(event, type)
   @light = Sprite.new
   @light.bitmap = RPG::Cache.picture("LE.PNG")
   @light.visible = true
   @light.z = 1000
   @event = event
   @type = type
end
end
yamina-chan
As far as I can tell it won't work with this script. Either the effect is called right away or not at all. (Which is a bit odd)
Then again, I see no real purpose for this script in the first place. In my opinion it would be easier to just call the graphic (for it really just is one single, still graphic) by event if needed. Or make a custom glow for the event and add it to a character set an activate that. Which then could even be animated if wished.
Is it really necessary to use the script?
Night_Runner
Try this:

CODE
# ? Light Effects
#================================
# ?By: Near Fantastica
#   Date: 28.06.05
#   Version: 3
# ?Edited By: Night_Runner
#   Date: 20.03.12
#   For: xxVSxx
#    @> http://www.rpgrevolution.com/forums/index.php?showtopic=55806
#================================
#==========INSTRUCTIONS==========

#The first Comment event command in an event should read "Light Effects".  The
#comment event command immediately following it should read "Ground", "Fire",
#"Lamppost", "LeftLantern", or "RightLantern".
#The edit allows new events to become lights if a new page becomes active,
#and the new page has the characteristic string in the comment command.
#================================
class Spriteset_Map
#--------------------------------------------------------------
alias les_spriteset_map_initalize initialize
alias les_spriteset_map_dispose dispose
alias les_spriteset_map_update update
#--------------------------------------------------------------
def initialize
   setup_lights
   les_spriteset_map_initalize
   update
end
#--------------------------------------------------------------
def dispose
   les_spriteset_map_dispose
   dispose_lights
end
#--------------------------------------------------------------
def update
   if $game_temp.refresh_spritemap
     $game_temp.refresh_spritemap = false
     dispose_lights
     setup_lights
   end
   les_spriteset_map_update
   update_light_effects
end
#--------------------------------------------------------------
def setup_lights
   $game_temp.refresh_spritemap = false
   @light_effects = []
   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 == ["Light Effects"]
         type = event.list[i+1].parameters.to_s.upcase
         case type
         when "GROUND"
           light_effects = Light_Effect.new(event,type)
           light_effects.light.zoom_x = 200 / 100.0
           light_effects.light.zoom_y = 200 / 100.0
           light_effects.light.opacity = 51
           @light_effects.push(light_effects)
         when "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 = 85
           @light_effects.push(light_effects)
         when "LAMPPOST"
           light_effects = Light_Effect.new(event,"LEFT LAMP POST")
           light_effects.light.opacity = 51
           @light_effects.push(light_effects)
           light_effects = Light_Effect.new(event,"RIGHT LAMP POST")
           light_effects.light.opacity = 51
           @light_effects.push(light_effects)
         when "LEFTLANTERN"
           light_effects = Light_Effect.new(event,type)
           light_effects.light.opacity = 150
           @light_effects.push(light_effects)
         when "RIGHTLANTERN"
           light_effects = Light_Effect.new(event,type)
           light_effects.light.opacity = 150
           @light_effects.push(light_effects)
         end
       end
     end
   end
   for effect in @light_effects
     case effect.type
     when "GROUND"
       effect.light.x = (effect.event.real_x - 200 - $game_map.display_x) / 4
       effect.light.y = (effect.event.real_y - 200 - $game_map.display_y) / 4
     when "FIRE"
       effect.light.x = (effect.event.real_x - 300 - $game_map.display_x) / 4
       effect.light.y = (effect.event.real_y - 300 - $game_map.display_y) / 4
     when "LEFT LAMP POST"
       effect.light.x = (-0.25 * $game_map.display_x) + (effect.event.x * 32) - 5
       effect.light.y = (-0.25 * $game_map.display_y) + (effect.event.y * 32) - 15
     when "RIGHT LAMP POST"
       effect.light.x = (-0.25 * $game_map.display_x) + (effect.event.x * 32) - 25
       effect.light.y = (-0.25 * $game_map.display_y) + (effect.event.y * 32) - 15
     when "LEFTLANTERN"
       effect.light.x = (-0.25 * $game_map.display_x) + (effect.event.x * 32) - 20
       effect.light.y = (-0.25 * $game_map.display_y) + (effect.event.y * 32) - 5
     when "RIGHTLANTERN"
       effect.light.x = (-0.25 * $game_map.display_x) + (effect.event.x * 32) - 10
       effect.light.y = (-0.25 * $game_map.display_y) + (effect.event.y * 32) - 5
     end
   end
end
def dispose_lights
   for effect in @light_effects
     effect.light.dispose
   end
   @light_effects = []
end
#--------------------------------------------------------------
def update_light_effects
   for effect in @light_effects
     next if not in_range?(effect.event)
     case effect.type
     when "GROUND"
       effect.light.x = (effect.event.real_x - 200 - $game_map.display_x) / 4
       effect.light.y = (effect.event.real_y - 200 - $game_map.display_y) / 4
     when "FIRE"
       effect.light.x = (effect.event.real_x - 300 - $game_map.display_x) / 4
       effect.light.y = (effect.event.real_y - 300 - $game_map.display_y) / 4
     when "LEFT LAMP POST"
       effect.light.x = (-0.25 * $game_map.display_x) + (effect.event.x * 32) - 5
       effect.light.y = (-0.25 * $game_map.display_y) + (effect.event.y * 32) - 15
     when "RIGHT LAMP POST"
       effect.light.x = (-0.25 * $game_map.display_x) + (effect.event.x * 32) - 25
       effect.light.y = (-0.25 * $game_map.display_y) + (effect.event.y * 32) - 15
     when "LEFTLANTERN"
       effect.light.x = (-0.25 * $game_map.display_x) + (effect.event.x * 32) - 20
       effect.light.y = (-0.25 * $game_map.display_y) + (effect.event.y * 32) - 5
     when "RIGHTLANTERN"
       effect.light.x = (-0.25 * $game_map.display_x) + (effect.event.x * 32) - 10
       effect.light.y = (-0.25 * $game_map.display_y) + (effect.event.y * 32) - 5
     end
   end
end
#--------------------------------------------------------------
def in_range?(object)
   screne_x = $game_map.display_x
   screne_x -= 256
   screne_y = $game_map.display_y
   screne_y -= 256
   screne_width = $game_map.display_x
   screne_width += 2816
   screne_height = $game_map.display_y
   screne_height += 2176
   return false if object.real_x <= screne_x
   return false if object.real_x >= screne_width
   return false if object.real_y <= screne_y
   return false if object.real_y >= screne_height
   return true
end
end

#================================
# ? Light Effects Class
#================================

class Light_Effect
#--------------------------------------------------------------
attr_accessor :light
attr_accessor :event
attr_accessor :type
#--------------------------------------------------------------
def initialize(event, type)
   @light = Sprite.new
   @light.bitmap = RPG::Cache.picture("LE.PNG")
   @light.visible = true
   @light.z = 1000
   @event = event
   @type = type
end
end

#================================
# ? Game Temp Class
#================================

class Game_Temp
#--------------------------------------------------------------
attr_accessor :refresh_spritemap
#--------------------------------------------------------------
alias les_game_temp_initialize initialize
#--------------------------------------------------------------
def initialize
   @refresh_spritemap = false
   les_game_temp_initialize
end
end

#================================
# ? Game Event Class
#================================

class Game_Event
#--------------------------------------------------------------
alias les_game_event_refresh refresh
#--------------------------------------------------------------
def refresh
   $game_temp.refresh_spritemap = true
   les_game_event_refresh
end
end


That will go through events and look for new lights if an events need to refresh, e.g. when an event has a new page active.
So I have an event
setup


Just a normal event



Once switch 1 is on, the event lights up!
xxVSxx
Thanks Night runner it works perfect happy.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.