Rataime's Dynamic Shadows
Ok, jus� an FYI, this script is caterpillar compatible.  This is Rataime�s Shadow scripts.  Its quite simple to use actually.  I find it easier though to write down all the different commands to the scripts I have implemented, for easy referance, so I suggest you do the same.  Now, here are the commands that you will need to use inorder to use this script:

**All of these commands go into comments in the events, also, don�t capitalize any of the commands at any point, otherwise it wont work**

begin shadow source � starts a source of light in an event
begin shadow � starts shadows for an event (party members all have this automatically)

Now, put these in comments only if you have selected the event to be a source.

anglemin (number between 0 and 360.  Example: anglemin 0)- sets angle of rotation
anglemax (number between 0 and 360. Example: anglemax 360) � sets angle of rotation
distancemax (number)- sets how far the shadow will show up.

And that�s all there is to it.  Just remember Geometry; this script works in angles, 180 being half way around, and 360 being all the way around.

Put this script in a new class called Dynamic Shadows.  Put it over the Sun Effects Script and under Wachunga�s Fog of War script if you are using it.
#==============================================================================
# ? Sprite_Shadow (Sprite_Ombre )
# Based on Genzai Kawakami's shadows, dynamisme&features by Rataime, extra features Boushy
#==============================================================================

CATERPILLAR_COMPATIBLE = true
SHADOW_WARN = true

class Game_Party
  attr_reader :characters
end

class Sprite_Shadow < RPG::Sprite

  attr_accessor :character

  def initialize(viewport, character = nil,id=0)
    super(viewport)
    params=$shadow_spriteset.shadows[id]
    @source=params[0]
    @anglemin=0
    @anglemin=params[1] if params.size>1
    @anglemax=0
    @anglemax=params[2] if params.size>2
    @self_opacity=100
    @self_opacity=params[4] if params.size>4
    @distancemax=350
    @distancemax=params[3] if params.size>3
    @character = character
    update
  end

  def update

    if !in_range?(@character, @source, @distancemax)
      self.opacity=0
      return
    end
    super
   
    if @tile_id != @character.tile_id or
       @character_name != @character.character_name or
       @character_hue != @character.character_hue
      @tile_id = @character.tile_id
      @character_name = @character.character_name
      @character_hue = @character.character_hue
      if @tile_id >= 384
        self.bitmap = RPG::Cache.tile($game_map.tileset_name,
          @tile_id, @character.character_hue)
        self.src_rect.set(0, 0, 32, 32)
        self.ox = 16
        self.oy = 32
      else
        self.bitmap = RPG::Cache.character(@character.character_name,
          @character.character_hue)
        @cw = bitmap.width / 4
        @ch = bitmap.height / 4
        self.ox = @cw / 2
        self.oy = @ch
      end
    end
    self.visible = (not @character.transparent)
    if @tile_id == 0
      sx = @character.pattern * @cw
      sy = (@character.direction - 2) / 2 * @ch
      if self.angle>90 or angle<-90
        if @character.direction== 6
               sy = ( 4- 2) / 2 * @ch
        end
        if @character.direction== 4
               sy = ( 6- 2) / 2 * @ch
        end
        if @character.direction== 2
               sy = ( 8- 2) / 2 * @ch
        end
        if @character.direction== 8
               sy = ( 2- 2) / 2 * @ch
        end
      end
      self.src_rect.set(sx, sy, @cw, @ch)
    end
    self.x = @character.screen_x
    self.y = @character.screen_y-5
    self.z = @character.screen_z(@ch)-1
    self.blend_type = @character.blend_type
    self.bush_depth = @character.bush_depth
    if @character.animation_id != 0
      animation = $data_animations[@character.animation_id]
      animation(animation, true)
      @character.animation_id = 0
    end
    @[email protected]_x-self.x
    @deltay= @source.screen_y-self.y
    self.color = Color.new(0, 0, 0)
    @distance = ((@deltax ** 2) + (@deltay ** 2))
    self.opacity = @self_opacity*13000/((@distance*370/@distancemax)+6000)
    self.angle = 57.3*Math.atan2(@deltax, @deltay )
    @angle_trigo=self.angle+90
    if @angle_trigo<0
        @angle_trigo=360+@angle_trigo
     end
    if @anglemin !=0 or @anglemax !=0
       if (@angle_trigo<@anglemin or @angle_trigo>@anglemax) and @anglemin<@anglemax
         self.opacity=0
         return
       end
       if (@angle_trigo<@anglemin and @angle_trigo>@anglemax) and @anglemin>@anglemax
         self.opacity=0
         return
       end    
     end
  end
  
  def in_range?(element, object, range)# From Near's Anti Lag Script, edited
    x = (element.screen_x - object.screen_x) * (element.screen_x - object.screen_x)
    y = (element.screen_y - object.screen_y) * (element.screen_y - object.screen_y)
    r = x + y
    if r <= (range * range)
       return true
    else
      return false
    end
  end
 
end

#===================================================
# ? CLASS Sprite_Character edit
#===================================================

class Sprite_Character < RPG::Sprite
  alias shadow_initialize initialize
 
  def initialize(viewport, character = nil)
    @character = character
    super(viewport)
    @ombrelist=[]
    if character.is_a?(Game_Event) and $shadow_spriteset.shadows!=[]
      params = XPML_read("Shadow",@character.id,4)
      if params!=nil
        for i in 0...$shadow_spriteset.shadows.size
          @ombrelist.push(Sprite_Shadow.new(viewport, @character,i))
        end
      end
    end
    if character.is_a?(Game_Player) and $shadow_spriteset.shadows!=[]
      for i in 0...$shadow_spriteset.shadows.size
        @ombrelist.push(Sprite_Shadow.new(viewport, $game_player,i))
      end
      #===================================================
      # ? Compatibility with fukuyama's caterpillar script
      #===================================================
      if CATERPILLAR_COMPATIBLE and $game_party.characters!=nil
        for member in $game_party.characters
          for i in 0...$shadow_spriteset.shadows.size
            @ombrelist.push(Sprite_Shadow.new(viewport, member,i))
          end
        end
      end
      #===================================================
      # ? End of the compatibility
      #===================================================
    end
    shadow_initialize(viewport, @character)
  end
 
  alias shadow_update update
 
  def update
    shadow_update
    if @ombrelist!=[]
      for i in [email protected]
        @ombrelist[i].update
      end
    end
  end 
 
end

#===================================================
# ? CLASS Game_Event edit
#===================================================
class Game_Event
  attr_accessor :id
end

#===================================================
# ? CLASS Spriteset_Map edit
#===================================================
class Spriteset_Map
  attr_accessor :shadows
  alias shadow_initialize initialize
 
  def initialize
    $shadow_spriteset=self
    @shadows=[]
    warn=false
    for k in $game_map.events.keys.sort
      warn=true if ($game_map.events[k].list!=nil and $game_map.events[k].list[0].code == 108 and ($game_map.events[k].list[0].parameters == ["s"] or $game_map.events[k].list[0].parameters == ["o"]))
      params = XPML_read("Shadow Source",k,4)
      $shadow_spriteset.shadows.push([$game_map.events[k]]+params) if params!=nil
    end
    p "Warning : At least one event on this map uses the obsolete way to add shadows" if warn == true and SHADOW_WARN
    shadow_initialize
  end 
end



#===================================================
# ? XPML Definition, by Rataime, using ideas from Near Fantastica
#
#   Returns nil if the markup wasn't present at all,
#   returns [] if there wasn't any parameters, else
#   returns a parameters list with "int" converted as int
#   eg :
#   begin first
#   begin second
#   param1 1
#   param2 two
#   begin third
#   anything 3
#
#   p XPML_read("first", event_id) -> []
#   p XPML_read("second", event_id) -> [1,"two"]
#   p XPML_read("third", event_id) -> [3]
#   p XPML_read("forth", event_id) -> nil
#===================================================

  def XPML_read(markup,event_id,max_param_number=0)
    parameter_list = nil
    event=$game_map.events[event_id]
    return if event.list==nil
      for i in 0...event.list.size
        if event.list[i].code == 108 and event.list[i].parameters[0].downcase == "begin "+markup.downcase
          parameter_list = [] if parameter_list == nil
          for j in i+1...event.list.size
            if event.list[j].code == 108
              parts = event.list[j].parameters[0].split
              if parts.size!=1 and parts[0].downcase!="begin"
                if parts[1].to_i!=0 or parts[1]=="0"
                  parameter_list.push(parts[1].to_i)
                else
                  parameter_list.push(parts[1])
                end
              else
                return parameter_list
              end
            else
              return parameter_list
            end
            return parameter_list if max_param_number!=0 and j==i+max_param_number
          end
        end
      end
    return parameter_list
  end
Hosted by www.Geocities.ws

1