Save-Point
P's Priority Checking [Exclusive] - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Scripts Database (https://www.save-point.org/forum-39.html)
+---- Forum: RPGMaker XP (RGSS) Engine (https://www.save-point.org/forum-116.html)
+---- Thread: P's Priority Checking [Exclusive] (/thread-2308.html)



P's Priority Checking [Exclusive] - PK8 - 05-10-2009

P's Priority Check
Version: 1

Introduction
This script adds a feature that was lacking in the default scripts: Getting the priority value of a tile.
There's also a few niceties added just to make the script stand out a little from any possible priority-checking scripts.

Features
  • Check the priority value of a non-blank tile in the top-most layer with script call: $game_map.priority?(x, y) or $game_map.priority(x, y, -1)
  • Check the priority value of a tile in a specific layer with script call: $game_map.priority?(x, y, layer).
  • For those who tend to want their results "printed" (alert box!), the script would print the returning value of with this script call: $game_map.priority?(x, y, layer, true)
Screenshots
[Image: eulm5l.png]

Script
Code:
=begin
????????????????????????????????????????????????????????????????????????????????
? PK8's Priority Check                                                         ?
? Version 1                                                                    ?
? by PK8                                                                       ?
????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????
? ? Description:                                                               ?
? ?? This script adds a feature that was lacking in the default script:        ?
?    Getting the priority value of a tile.                                     ?
?    There's also a few niceties added just to make the script stand out a     ?
?    little from any possible priority-checking scripts.                       ?
????????????????????????????????????????????????????????????????????????????????
? ? Features:                                                                  ?
? ?? Check the priority value of a non-blank tile in the top-most layer with   ?
? ?  script call: $game_map.priority?(x, y) or $game_map.priority(x, y, -1)    ?
? ?? Check the priority value of a tile in a specific layer with script call:  ?
? ?  $game_map.priority?(x, y, layer).                                         ?
? ?? For those who tend to want their results "printed" (alert box!), the      ?
?    script would print the returning value of with this script call:          ?
?    $game_map.priority?(x, y, layer, true)                                    ?
????????????????????????????????????????????????????????????????????????????????
? ? Usage and examples:                                                        ?
? ?? The script call: $game_map.priority?(x, y, layer, print)                  ?
?                                                                              ?
?  x: X-coordinate of a map.                                                   ?
?  y: Y-coordinate of a map.                                                   ?
?  layer: Map layer. (-1:All layers(default), 0:1st, 1:2nd, 2:3rd) (Optional)  ?
?  print: Prints value from the call. (false:no(default), true:Yes) (Optional) ?
????????????????????????????????????????????????????????????????????????????????
? ? Tips:                                                                      ?
? ?? Get the priority value of the tile in top-most layer where your player is ?
?    standing by calling this:                                                 ?
?    $game_map.priority?($game_player.x, $game_player.y)                       ?
?                                                                              ?
? You ought to try mixing that with if conditions. You might be able to do some?
? nice stuff. :P                                                               ?
????????????????????????????????????????????????????????????????????????????????
=end

class Game_Map
  def priority?(x, y, i = -1, print = false)
    if @map_id != 0
      # If layer isn't specified or user deliberately types in -1 in the call.
      if i == -1
        # Checking all layers.
        for i in [2, 1, 0]
          tile_id = data[x, y, i]
          # Returns 0 if the top-most tiles are blank or something.
          if tile_id == 0
            if i != 0
              next
            end
            # Prints the returning value if fourth argument is true.
            if print == true
              print 0
            end
            return 0
          # Returns top-most tile's priority if there.
          elsif tile_id >= 1
            # Prints the returning value if fourth argument is true.
            if print == true
              print priorities[tile_id]
            end
            return priorities[tile_id]
          end
        end
      end
      # If developer types in a specific layer in the call.
      if i != -1
        tile_id = data[x, y, i]
        if tile_id == 0
          # Prints the returning value if fourth argument is true.
          if print == true
            print 0
          end
          return 0
        # Returns layer-specific tile's priority if there.
        elsif tile_id >= 1
          # Prints the returning value if fourth argument is true.
          if print == true
            print priorities[tile_id]
          end
          return priorities[tile_id]
        end
      end
      return 0
    end
  end
end

Instructions
Simply copy-paste the script into your project. Examples of use are included in the script.

FAQ
No questions asked so far.

Compatibility
Dunno.

Credits and Thanks
No thanks. ;P

Author's Notes
Feel free to let me know if there's any bugs so I could try to fix it.

Terms and Conditions
Just credit me, it's all I ask. :3