Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Maplock Images
#1
Maplock Images
by Khatharr
version 2
Jun 8 2005

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


Okay! The old maplock script was messy and buggy. I think it was one of the earlier scripts I did. This new one works great and is easy to install.

There are two parts to this: one part allows you to 'spawn' a picture, the exact same way the 'show picture' does, so that you can 'spoof' this command from inside a script. The second part allows you to lock a picture to the map, so it will not follow the screen, but will stay put relative to the map.

To install this script create a new section in the script editor just above "Main". Do this by scrolling the menu on the left-hand side all the way to the bottom, then right-clicking on "Main" and selecting "Insert". Name the section and then select it. Paste the following code into the right-hand pane.

Code:
#==============================================================================
# Picture Spoofer Script
#  * This is a utility script that allows a picture to be set up from script as it would be from the
#  * "Show Picture" event command.  Pictures created this way are entirely identical to pictures
#  * created by events.  This method works on the map or in battle.
#==============================================================================
class Game_Screen
  #--------------------------------------------------------------------------
  #   num : Number of picture.
  #   name : Name of picture imported normally to project.  Do not include file extension.
  #   origin : 0 = x, y refers to upper-left pixel on picture; 1 = x, y refers to center pixel on picture.
  #   x, y : Screen x, y pixel to draw picture at.
  #   zoom_x, zoom_y : Percentage to zoom picture.  100 is normal size.
  #   opacity : Opposite of transparency.  255 = normal; 128 = half faded; 0 = invisible
  #   blend_type : 0 = "Normal"; 1 = "Add"; 2 = "Subtract"
  #  
  #   To remove a picture from script use the command
  #       $game_screen.pictures[number].erase
  #   "Spoofed" pictures are identical to pictures created with event commands in every respect.
  #--------------------------------------------------------------------------
  def spoof_pic(num, name, origin, x, y, zoom_x, zoom_y, opacity, blend_type)
    number = num + ($game_temp.in_battle ? 50 : 0)
    @pictures[number].show(name, origin, x, y, zoom_x, zoom_y, opacity, blend_type)
  end
end
#==============================================================================
# Maplock Picture script
#  * This script will lock a picture to an X, Y pixel location on the map.  The picture will remain
#  * in place on the map rather than following the screen as the map scrolls.
#  * To move a picture that is locked re-lock it to the new location.
#  * To unlock a picture, erase it and then re-create it.
#==============================================================================
class Game_Picture
  alias maplock_init initialize #Modified the "initialize" method in Game_Picture.
  def initialize(number) #Create lock_x and lock_y values.  These values store the map-relative pixel for the picture's origin point.
    @lock_x = nil
    @lock_y = nil
    maplock_init(number)
  end
  def lock(x, y) #Lock a picture to a map-relative pixel.
    @lock_x = x + ($game_map.display_x / 4)
    @lock_y = y + ($game_map.display_y / 4)
  end
  def erase  #Overwrote the "erase" method in Game_Picture.
    @name = ""
    @lock_x = nil #Removing the lock_x and lock_y properties unlocks the picture.
    @lock_y = nil
  end
  alias maplock_update update #Modified the "update" method in Game_Picture.
  def update #If the picture has a lock_x and lock_y property it is "locked" to the map accordingly.
    if @lock_x != nil and @lock_y != nil
      @x = @lock_x - ($game_map.display_x / 4)
      @y = @lock_y - ($game_map.display_y / 4)
    end
    maplock_update
  end
end


And that's it.

Now, the 'picture spoofer' makes the game think that you used the 'Show Picture' command in an event. It actually sets up a picture the same way, so if you use it to make a picture, you could then remove that picture using the 'Erase Picture' event command, or you could use the move, rotate, and tint commands. The syntax to use it is as follows:

Code:
$game_screen.spoof_pic(number, filename, origin, x, y, zoom_x, zoom_y, opacity, blend_type)


number - The number of the picture, 1 to 50. This is used by events to reference the picture. It is required to assign a number, even if you don't need it.

filename - The name of the image. (Duhr...) The file must be in your pictures directory. Do not add the file extension. Before you complain about this, did you know that you can import more than one picture at a time? Just select the whole bunch of 'em on the 'open' dialog while importing. They will batch-import. It even remembers your color settings between images. Very convenient. No, I will not change this. Import your pics. If you want to show monster pics, import them.

origin - 0 or 1. An origin of 0 means the x,y refers to the upper-left corner of the image. An origin of 1 means the x,y refers to the center of the image.

x, y - This refers to the x, y on the screen (not the map!). To calculate a pixel location with reference to the map instead of the screen, you can use this formula:

(Screen-relative X) - ($game_map.display_x / 4) = Map-relative X

In other words, if you want to start your picture offscreen at a specific x,y on the map, such as 45,90, you would calculate as follows:

scrolled_x = $game_map.display_x / 4
scrolled_y = $game_map.display_y / 4
target_x = 45 - scrolled_x
target_y = 90 - scrolled_y

and then feed the target_x and target_y values into the method. The screen is 640x480 logical pixels.

zoom_x, zoom_y - Percentage of zoom. Set to 100 for normal size.

opacity - The opposite of transparency. Set to 255 to make your picture normal.

blend_type - Normal = 0; Add = 1; Subtract = 2 (Just like in 'Show Picture')

And that's how the spoofer works.

If you want to remove a picture from within script, use:
Code:
$game_screen.pictures[number].erase



Fortunately the lock command is a lot simpler. Once you have created your picture, use
Code:
$game_screen.pictures[number].lock(x, y)


And pass it a MAP x, y value. Use the method give above to convert to map x,y.

You must pass an x, y location to the lock command. The old method of locking a picture wherever it lay is no longer present.

There's also no longer an "unlock" command, as it was somewhat silly. To unlock a picture simply erase it and re-create it.

The "Move Picture" event command can no longer be used on locked pictures. To move a picture that is locked just lock it to a new x,y location. You don't have to erase it first.

A final note, tiles are 32x32, so if you want your x,y to be on the upper-left corner of map tile 8,6 then your x,y is:

x = 8 * 32 = 288
y = 6 * 32 = 224

If you want your x,y in the center of the tile, just add 16 to both x and y. But you probably knew that.

Thanks again for all the comments on the script and for your patience while waiting for version 2. Sorry it took so long.
}




Users browsing this thread: