[RESOLVED] Script that allows random placement of events

Started by Rymdpotatis, July 18, 2008, 06:47:37 am

Previous topic - Next topic

Rymdpotatis

Request for a script that allows random placements of events such as treasure chests and monsters that manages so they don't end up in walls. =3

Blizzard

Here's some help for whoever makes this script: You can use the code that I use for respawning in Blizz-ABS.

  #----------------------------------------------------------------------------
  # get_respawn_coordinates
  #  enemy - the killed enemy event
  #  Gets the respawning coordinates for the new enemy.
  #----------------------------------------------------------------------------
  def get_respawn_coordinates(enemy)
    # if fixed Respawn Point exists
    if enemy.respawn_point != nil
      # coordinates of the Respawn Point
      return [enemy.respawn_point.x, enemy.respawn_point.y]
    end
    # get virtual map passability
    v_map = $game_map.virtual_passability
    # passable
    passables = []
    # find all passable tiles
    (0...v_map.xsize).each {|x| (0...v_map.ysize).each {|y|
        # if passable and enemy may respawn and no event on position
        if v_map[x, y] != 0x00 && !BlizzABS::Config::NO_ENEMY_TAGS.include?(
            $game_map.terrain_tag(x, y)) && $game_map.event_passable?(x, y)
          passables.push([x, y])
        end}}
    # random possibnle coordinates on the map
    return passables[rand(passables.size)]
  end
  #----------------------------------------------------------------------------
  # respawn_enemy
  #  enemy - the killed enemy event
  #  Processes the respawn of a dead enemy.
  #----------------------------------------------------------------------------
  def respawn_enemy(enemy)
    # create new enemy on old enemy's template
    new_enemy = Map_Enemy.new($game_map.map_id, enemy)
    # gets the respawn coordinates
    x, y = get_respawn_coordinates(enemy)
    # no respawn position found
    return nil if x == nil || y == nil
    # move enemy to x, y coordinate
    new_enemy.moveto(x, y)
    # create sprite for respawned enemy
    sprite = Sprite_Character.new($scene.spriteset.viewport1, new_enemy)
    # set fade_in flag
    sprite.fade_in = true
    # add new sprite into spriteset
    $scene.spriteset.character_sprites.push(sprite)
    # enemy is invisible at first
    new_enemy.opacity = 0
    # return new enemy
    return new_enemy
  end


You'll have to delete the Blizz-ABS related stuff first. xD
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Rymdpotatis

I found a temporary solution to the random placement issue. I made a new enemy, named it Chest. Created an event that looks like a chest and named it Chest \m\e[3] . Now when it is destroyed it gets spawned somewhere else. Not a perfect sollution but it works for the moment.

Blizzard

Nice idea. xD Just don't forget to give him no actions, lol! You don't want a chest to eat you while you are trying to open it. xD
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Phasedscar

Spoiler: ShowHide
My own game project & My resource workshop! (respectively)
http://forum.chaos-project.com/index.php?topic=608.0 http://forum.chaos-project.com/index.php?topic=682.0



What that is? Affection area for flails. - Blizz-ABS, the ultimate ABS

The pictures in your signature may altogether be no more than 200kB. The height must not exceed 200 px and the width must not exceed 800 px. Altogether they may take up an area of 160000 px2. Every signature not matching this criteria is a subject of the moderator team to remove and leave this rule as message in your signature.