Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: diagostimo on July 13, 2012, 02:44:49 am

Title: is it possible to manipulate tile passibility via script?
Post by: diagostimo on July 13, 2012, 02:44:49 am
i was wondering if it is possible to manipulate the pasibility of tiles via script? the reason i need to do this is because im making a swimming script, heres the script:

class Game_Character
  attr_reader :swimming
end
class Game_Player
  EXTENSION = "_swim"
  TERRAIN = 2
  alias update_swim update
  def update
    if $game_map.terrain_tag(@x, @y) != TERRAIN
      player = $game_party.actors[0]
      if @swimming == true
        orig_name = player.character_name.split(EXTENSION)
        $game_player.character_name = orig_name[0]
        player.set_graphic(orig_name[0], player.character_hue, player.battler_name, player.battler_hue)
        @step_anime = false
        @through = false
        @swimming = false
      end
      if @direction == 2
        if $game_map.terrain_tag(@x, @y + 1) == TERRAIN
          if Input.trigger?(Input::C)
            swim_graphic = player.character_name + EXTENSION
            $game_player.character_name = swim_graphic
            player.set_graphic(swim_graphic, player.character_hue, player.battler_name, player.battler_hue)
            @step_anime = true
            @swimming = true
            @through = true
            move_down
          end
        end
      elsif @direction == 4
        if $game_map.terrain_tag(@x - 1, @y) == TERRAIN
          if Input.trigger?(Input::C)
            swim_graphic = player.character_name + EXTENSION
            $game_player.character_name = swim_graphic
            player.set_graphic(swim_graphic, player.character_hue, player.battler_name, player.battler_hue)
            @step_anime = true
            @swimming = true
            @through = true
            move_left
          end
        end
      elsif @direction == 6
        if $game_map.terrain_tag(@x + 1, @y) == TERRAIN
          if Input.trigger?(Input::C)
            swim_graphic = player.character_name + EXTENSION
            $game_player.character_name = swim_graphic
            player.set_graphic(swim_graphic, player.character_hue, player.battler_name, player.battler_hue)
            @step_anime = true
            @swimming = true
            @through = true
            move_right
          end
        end
      elsif @direction == 8
        if $game_map.terrain_tag(@x, @y - 1) == TERRAIN
          if Input.trigger?(Input::C)
            swim_graphic = player.character_name + EXTENSION
            $game_player.character_name = swim_graphic
            player.set_graphic(swim_graphic, player.character_hue, player.battler_name, player.battler_hue)
            @step_anime = true
            @swimming = true
            @through = true
            move_up
          end
        end
      end
    end
    update_swim
  end
end

so as you can see it changes the player to through when swimming, this currently is a very impracticable way to go about it because say i want to put rocks in the water or cliffs outlining it i would be able to walk onto those tiles, if i could change the water tile to passible that would resolve that issue completly :/
Title: Re: is it possible to manipulate tile passibility via script?
Post by: LiTTleDRAgo on July 13, 2012, 07:15:54 am
Quoteclass Game_Map
    attr_accessor :passages
end


$game_map.passages[TILE_ID] = (1/2/4/8/15)

(http://i.imgur.com/yb7XQ.jpg)


Title: Re: is it possible to manipulate tile passibility via script?
Post by: diagostimo on July 13, 2012, 07:42:10 am
cool, thanks for that :D im guessing 0 would be fully passable?
Title: Re: is it possible to manipulate tile passibility via script?
Post by: LiTTleDRAgo on July 13, 2012, 07:56:37 am
yes,

just for reference :

64 = bush flag
128 = counter flag
Title: Re: is it possible to manipulate tile passibility via script?
Post by: diagostimo on July 13, 2012, 08:32:43 am
ok im having trouble getting that to work, im using the following: $game_map.passages[1] = (0)
the tile im trying to enable is the first auto tile on the tileset, im guessing the tileset starts from 0, also would there be a way to get a tile id?
say i have multiple water terrains set up could i get the id of all the terrains with that terrain id?
edit:
ok i went through printing the values of the tile id's like so: p $game_map.passages[0] ... all the way to 48, the passibility didnt change until i hit 48, so i really dont get how the tileset is being split up :/
edit 2:
nvm i cracked it, each auto tile has 48 blocks and im guessing the first tile in the tileset acounts to have 48 tiles to, changing the value of the hole auto tile section fixes my problem and i have figured out what id the tileset actually starts at, my question now really is there a simpler way like i said before to change all the tiles with the terrain id of the water?
Title: Re: is it possible to manipulate tile passibility via script?
Post by: LiTTleDRAgo on July 13, 2012, 09:36:53 am
I hope you can understand this image, I'm bad at explaining in english

Spoiler: ShowHide
(http://i.imgur.com/MqeF5.jpg)


so if you want to change all passable in the autotile 1 :

Quote$game_map.passages[94] = 0
$game_map.passages[48] = 0
$game_map.passages[64] = 0
$game_map.passages[68] = 0
$game_map.passages[72] = 0
$game_map.passages[76] = 0
$game_map.passages[82] = 0
$game_map.passages[84] = 0
$game_map.passages[86] = 0
$game_map.passages[88] = 0


ah, that's too much code... let's shorten it

Quote
array = [48,64,68,72,76,82,84,86,88,94]
array.each {|i|
    $game_map.passages[i] = 0
    # that's for autotile 1
    $game_map.passages[i+48] = 0
    # that's for autotile 2
    # etc
}

Title: Re: is it possible to manipulate tile passibility via script?
Post by: diagostimo on July 13, 2012, 09:44:23 am
yes i was literaly just editing my last post as you posted that saying i realized the auto tiles where made up of 48 tiles, would there be a possible way to change the passibilty of all the tiles with the water terrain id? that way i wouldnt have to pre define all the tiles that are water in the script
Title: Re: is it possible to manipulate tile passibility via script?
Post by: LiTTleDRAgo on July 13, 2012, 10:09:40 am
then how about this

Quote
class Game_Player

  TERRAIN = 2
   
  def change_water_passable(passage=0)
    @water = []
    (0...$game_map.width).each {|x|
      (0...$game_map.height).each {|y|
        [2, 1, 0].each {|i|
           id = $game_map.data[x, y, i]
           @water << id if $game_map.terrain_tags[id] == TERRAIN
    }}}
    # This code will get all the possible tile id with
    # water terrain tags
    @water.each {|i|  $game_map.passages[i] = passage  }
    # then this code will change all the water passages
  end
end


now you can change all passability for tile with terrain tag 2 with call script

Script : $game_player.change_water_passable(0)
Script : $game_player.change_water_passable(15)
Title: Re: is it possible to manipulate tile passibility via script?
Post by: diagostimo on July 13, 2012, 07:06:09 pm
thats exacty what i need :D thanks for your help
Title: Re: is it possible to manipulate tile passibility via script?
Post by: diagostimo on July 16, 2012, 07:31:05 am
bump: is there a way to change the priority and terrain tags of the tiles???
edit: sorry, figured it out, i thought the priority may have been stored in the same variable but looking at game_map solves that :)