Chaos Project

RPG Maker => RPG Maker Scripts => Script Requests => Topic started by: LiTTleDRAgo on April 22, 2011, 09:39:11 am

Title: [RESOLVED][XP] Restricted Movement based on Width
Post by: LiTTleDRAgo on April 22, 2011, 09:39:11 am
Could someone make a script that can do something like this?

(http://img594.imageshack.us/img594/7474/unledag.jpg)

(http://img808.imageshack.us/img808/2933/unled2ds.jpg)

sorry for the image explanation, I just can't find the word to describe it

thanks in advance
Title: Re: [XP] Restricted Movement based on Width
Post by: WhiteRose on April 22, 2011, 11:33:00 am
Because RMXP handles sprites in a strictly tile-based system, this would probably require a rewrite of some fairly major parts of the default map scripts. Of course, I might be wrong.
Title: Re: [XP] Restricted Movement based on Width
Post by: LiTTleDRAgo on April 22, 2011, 12:52:37 pm
i think i remember found that kind of script in some japanese website and it's line is less than 1000 but I forgot where I find it

I guess it only modify game_map.passable

I wonder if anyone can create the same or similar script like that
Title: Re: [XP] Restricted Movement based on Width
Post by: brewmeister on April 23, 2011, 06:24:54 pm
How, EXACTLY, should this work?

You want a pixel to pixel comparison (i.e. collision detection)?

Or just, if the event is wider than 32, check the adjacent tiles for passability too?
Title: Re: [XP] Restricted Movement based on Width
Post by: ForeverZer0 on April 23, 2011, 06:48:13 pm
Do something like what Cogwheel's pixel-movement script did with the black and white passability maps, except maybe an expansion on it to include spritesets. Not easy to do, but that is a script that I am sure many would find very usefull. The problem is that I don't think its compatible with BABS, so that will be another obstacle that needs to be cleared. There are probably much easier solutions to your particular problem, but I was just throwing an idea out there.
Title: Re: [XP] Restricted Movement based on Width
Post by: Ryex on April 23, 2011, 06:52:27 pm
could this not be done with a simple event tag? the user would tag an even with it's width in tiles either in a comment on the top of the event page or in the event name and then the script would test to be sure that there was a 2*2 area  for the event to pass though.
Title: Re: [XP] Restricted Movement based on Width
Post by: ForeverZer0 on April 23, 2011, 07:02:26 pm
Yes, it could most certainly be done with some eventing. It may be a little tedious, depending on your map and how many areas a sprite can't pass through, but it wouldn't actually be difficult at all. An automatic script for it would be nice, still.

you misunderstand me. use the tags in the events to tell a script how wide the event is and let the script determine passibility.
Title: Re: [XP] Restricted Movement based on Width
Post by: LiTTleDRAgo on April 24, 2011, 08:08:27 am
I managed to edit this into my project, I guess it's resolved?

Spoiler: ShowHide
class Game_Character
 
  attr_accessor :size_x                   
  attr_accessor :size_y                   
  attr_accessor :tiles_left             
  attr_accessor :tiles_right             
 
  alias event_size_init initialize
  alias passable_size passable?
  def initialize
    event_size_init
    setup_event_size
  end
 
  def setup_event_size
    @size_x = 1
    @size_y = 1
    @tiles_left  = 0
    @tiles_right = 0
  end
 
  def size(x, y)
    @size_x = x
    @size_y = y
    tiles_x      = (@size_x - 1) / 2
    @tiles_left  = tiles_x.floor
    @tiles_right = tiles_x.ceil
  end

  def passable?(x, y, d)
    result = passable_size(x, y, d)
    new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
    new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
    unless $game_map.valid?(new_x, new_y) then  return false  end
    return result if @through
    @tiles_left = 0 if @tiles_left.nil?
    @tiles_right = 0 if @tiles_right.nil?
    (0...@size_x.to_i).each {|i|
      unless $game_map.passable?(x - @tiles_left + i, y, d, self) then return false end
      unless $game_map.passable?(new_x - @tiles_left + i, new_y, 10 - d) then return false end
      (0...@size_y.to_i).each {|j|
        unless $game_map.passable?(x, y - j, d, self) then return false end
        unless $game_map.passable?(new_x, new_y - j, 10 - d) then return false end
        unless $game_map.passable?(x - @tiles_left + i, y - j, d, self) then return false end
        unless $game_map.passable?(new_x - @tiles_left + i, new_y - j, 10 - d) then return false end
      }}
    $game_map.events.each_value {|event|
      return false if event_collide?(self, event, new_x, new_y)}
    if event_collide?(self, $game_player, new_x, new_y)
      return false if self.is_a?(Game_Event)
    end
    return result
  end

  def event_collide?(event1, event2, new_x, new_y)
    return false if event1.id == event2.id
    collision = false
    event1.size_y = 1 if event1.size_y.nil?
    event2.size_y = 1 if event2.size_y.nil?
    event1.size_x = 1 if event1.size_x.nil?
    event2.size_x = 1 if event2.size_x.nil?
    event1.tiles_left = 0  if event1.tiles_left.nil?
    event2.tiles_left = 0  if event2.tiles_left.nil?
    event1.tiles_right = 0 if event1.tiles_right.nil?
    event2.tiles_right = 0 if event2.tiles_right.nil?
    ((new_y - (event1.size_y - 1))..new_y).each {|i|
    ((event2.y - (event2.size_y - 1))..event2.y).each {|j|
        if i == j && event1.character_name != "" && event2.character_name != ""
          unless event1.through or event2.through then collision = true end
        end }}
    ((new_x - event1.tiles_left)..(new_x + event1.tiles_right)).each {|i|
    ((event2.x - event2.tiles_left)..(event2.x + event2.tiles_right)).each {|j|
        if i == j && event1.character_name != "" && event2.character_name != ""
          unless event1.through or event2.through then return true end
        end}} if collision
    return false
  end
end

class Game_Player

  alias check_size_here check_event_trigger_here
  alias check_size_there check_event_trigger_there
  alias check_size_touch check_event_trigger_touch
  def check_event_trigger_here(triggers)
    result = check_size_here(triggers) #false
    return result if $game_system.map_interpreter.running?
    $game_map.events.each_value {|event|
      if @x >= event.x - event.tiles_left &&
        @x <= event.x + event.tiles_right &&
        @y >= event.y - (event.size_y - 1) && @y <= event.y &&
        triggers.include?(event.trigger)
        if !event.jumping? && event.over_trigger?
          event.start
          result = true
        end
      end }
    return result
  end

  def check_event_trigger_there(triggers)
    result = check_size_there(triggers) #false
    return result if $game_system.map_interpreter.running?
    new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
    new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
    $game_map.events.each_value {|event|
      if new_x >= event.x - event.tiles_left &&
        new_x <= event.x + event.tiles_right &&
        new_y >= event.y - (event.size_y - 1) && new_y <= event.y &&
        triggers.include?(event.trigger)
        if !event.jumping? && !event.over_trigger?
          event.start
          result = true
        end
      end }
    if result == false
      if $game_map.counter?(new_x, new_y)
        new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
        new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
        $game_map.events.each_value {|event|
          if new_x >= event.x - event.tiles_left &&
            new_x <= event.x + event.tiles_right &&
             new_y >= event.y - (event.size_y - 1) && new_y <= event.y &&
             triggers.include?(event.trigger)
            if !event.jumping? && !event.over_trigger?
              event.start
              result = true
            end
          end }
      end
    end
    return result
  end

  def check_event_trigger_touch(x, y)
    result = check_size_touch(x, y)# false
    return result if $game_system.map_interpreter.running?
    $game_map.events.each_value {|event|
      if x >= event.x - event.tiles_left &&
        x <= event.x + event.tiles_right &&
         y >= event.y - (event.size_y - 1) &&
         y <= event.y && [1,2].include?(event.trigger)
        event.start
        result = true
      end }
    return result
  end
end

class Sprite_Character
  alias update_size update
  def update
    update_size
    return if @character.is_a?(Game_Player)
    if @character.size_x == 1 && @character.size_y == 1
      @character.size(self.bitmap.width/128, self.bitmap.height/160)
    end
  end
end
Title: Re: [RESOLVED][XP] Restricted Movement based on Width
Post by: Jragyn on April 24, 2011, 11:09:22 am
Does LittleDrago's script(let) work as the request suggested?
Haha, if it does, perhaps this should be released publicly. :o
Title: Re: [RESOLVED][XP] Restricted Movement based on Width
Post by: LiTTleDRAgo on April 24, 2011, 09:16:19 pm
that's not my script, I only edit it