Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> Need a little help with my script, Can't access some attributes :/
Sel Feena
post Jun 23 2011, 05:16 AM
Post #1


Level 2
Group Icon

Group: Member
Posts: 26
Type: Writer
RM Skill: Beginner




Hello all, I've started developing a photo script. Right now it's just script calls, with windows and scenes to come later.

However, I've hit a snag and am tearing my hair out trying to figure out how to get access to two attributes:

The name of the current map, that can be set in the game editor
The name of an event, that can be set in the game editor

This info will be referred to in the initialize function for SelFeenaPhoto

Here's my code so far...

CODE
=begin

##############################
## Basic Photo System V 1.0 ##
##############################

Author : Sel Feena
Date   : -.06.11

A simple system that lets your party keep a collection of
screenshots, which are stored along with descriptive data.
The data stored is:

* The snapshot itself (obviously), which is a Bitmap object.
* The ID of the map the photo was taken on.
* The player's XY coords and what direction they were facing.
* The top left XY coords of the photo.
* Information about any events that are captured in the photo:
  -The event's ID
  -The event's XY coords
  -The values for the event's Self-Switches

Compatibility
-------------

Adds new functions to the Game_Party class, and changes its
initialize function. Should be fine.

Possible Bugs
-------------

It doesn't seem possible in the editor, but using maps in your game that are
smaller than 17 X 13 in size could mess things up.

################
## How To Use ##
################

Create Photo
------------

To create a photo, use the following script call:

myPhoto = SelFeenaPhoto.new

Add Photo to Collection
-----------------------

To add the photo to your collection, you'd then type:

$game_party.addPhoto(myPhoto)

The new photo will be added to your party's collection. HOWEVER, if your
collection is full then the photo in slot 0 will be erased to make room.
Set the maximum number of photos allowed in the module below.

Get Photo from Collection
-------------------------

To get a photo, call:

myPhoto = $game_party.getPhoto( x )

Where x is the index of the photo in the collection. Just like
arrays, this starts from 0

Remove Photo from Collection
----------------------------

To destroy a photo, call:

$game_party.delPhoto( x )

Where x is the index of the photo in the collection. Just like
arrays, this starts from 0

Get Number of Photos in Collection
----------------------------------

Use this script:

collection_size = $game_party.getPhotoCount

Make good use of this function call to avoid out-of-bounds errors!

Get Photo Image
---------------

myPhoto = $game_party.getPhoto( x )
picture = myPhoto.getImage

Where x is the index of the photo in the collection. Just like
arrays, this starts from 0
This function returns a Bitmap object.

Get Location of Photo
---------------------

myPhoto = $game_party.getPhoto( x )
location = myPhoto.getLocationID

Where x is the index of the photo in the collection. Just like
arrays, this starts from 0
Variable 'location' will then have the Map ID of where the photo was taken.

Get Player's Position when Taking Photo
---------------------------------------

myPhoto = $game_party.getPhoto( x )
player_loc_data = myPhoto.getPlayerPosition

player_x = player_loc_data[0]
player_y = player_loc_data[1]
player_dir = player_loc_data[2]

Where x is the index of the photo in the collection. Just like
arrays, this starts from 0
This function returns an array of three integers:
   - The player's X position.
   - The player's Y position.
   - The direction the player was facing:
      - 2 -> Down
      - 4 -> Left
      - 6 -> Right
      - 8 -> Up

Get Photo's Position
--------------------

myPhoto = $game_party.getPhoto( x )
photo_loc_data = myPhoto.getPhotoPosition

photo_x = photo_loc_data[0]
photo_y = photo_loc_data[1]

Where x is the index of the photo in the collection. Just like
arrays, this starts from 0
This function returns an array of two integers:
   - The photo's top-left X position.
   - The photo's top-left Y position.

Get Number of Events in Photo
-----------------------------

myPhoto = $game_party.getPhoto( x )
events_in_photo = myPhoto.getEventCount

Where x is the index of the photo in the collection. Just like
arrays, this starts from 0

Is a Certain Event in Photo?
---------------------------

myPhoto = $game_party.getPhoto( x )
has_event = myPhoto.hasEventWithID( i )

Where x is the index of the photo in the collection, and i is the ID
number you're looking for.
Returns true or false.

=end


=begin

This module contains settings that allow you to customise
the photo system.

=end

module SelFeenaPhotoModule
  
  MaxPhotos = 8  # Number of photos allowed in collection.
  
end

###############################
###############################
##                           ##
##    DON'T GO PAST HERE!    ##
##                           ##
###############################
###############################

=begin

Update Game_Party to include access to photo data.

=end

class Game_Party < Game_Unit
  alias selfeena_init initialize
  def initialize
    @photos = []
    selfeena_init
  end
  
  def getPhotoCount
    return @photos.length
  end
  
  def getPhoto(i)
    return @photos[i]
  end
  
  def delPhoto(i)
    @photos.delete_at(i)
  end
  
  def addPhoto(p)
    if(@photos.length == SelFeenaPhotoModule::MaxPhotos)
      @photos.delete_at(0)
    end
    @photos.push(p)
  end
end

=begin

Class encapsulating photo data.

=end

class SelFeenaPhoto  
  def initialize
    # Save image data...
    
    @image_data = Graphics.snap_to_bitmap
    
    # Save Map ID...
    
    @map_id = $game_map.map_id
    
    # Save player position and direction...
    
    @player_x = $game_player.x
    @player_y = $game_player.y
    @player_dir = $game_player.direction
    
    # Save xy position of photo (top-left corner) as map coordinates
    
    @photo_pos_x = $game_map.display_x / 256
    @photo_pos_y = $game_map.display_y / 256
    
    # What events have we captured in the photo?
        
    arr = []
    for x in @photo_pos_x..(@photo_pos_x + 16)
      if(x >= $game_map.width)      # Horizontal loop fix
        x -= $game_map.width
      end      
      for y in @photo_pos_y..(@photo_pos_y + 12)              
        if(y >= $game_map.height)   # Vertical loop fix
          y -= $game_map.height
        end        
        arr = arr + $game_map.events_xy(x, y)
      end
    end

    # For each event within photo, store data...
    
    @event_data = []
    for i in arr
      i_swa = $game_self_switches[[$game_map.map_id, i.id, "A"]]
      i_swb = $game_self_switches[[$game_map.map_id, i.id, "B"]]
      i_swc = $game_self_switches[[$game_map.map_id, i.id, "C"]]
      i_swd = $game_self_switches[[$game_map.map_id, i.id, "D"]]
      
      @event_data.push([i.id,[i.x,i.y],[i_swa,i_swb,i_swc,i_swd]])
    end
  end
  
  def dispose
    @image_data.dispose
  end
  
  def getImage
    return @image_data
  end
  
  def getLocationID
    return @map_id
  end
  
  def getPlayerPosition
    return [@player_x, @player_y, @player_dir]
  end
  
  def getPhotoPosition
    return [@photo_pos_x, @photo_pos_y]
  end
  
  def getEventCount
    return @event_data.length
  end
  
  def hasEventWithID(target_id)
    result = false
    
    for i in @event_data
      if i[0] == target_id
        result = true
      end
    end
    
    return result
  end
end


Thanks for your time! smile.gif

This post has been edited by Sel Feena: Jun 23 2011, 05:20 AM
Go to the top of the page
 
+Quote Post
   
stripe103
post Jun 23 2011, 09:02 AM
Post #2


PHP ERROR: Couldn't get value from UInteger. Value too large
Group Icon

Group: Revolutionary
Posts: 737
Type: Mapper
RM Skill: Intermediate




For the name of the current map, this should work
CODE
class Game_Map
  attr_reader :name
  alias :mapname_setup :setup
  def setup(map_id)
    mapname_setup(map_id)
    data = load_data("Data/MapInfos.rvdata")
    @name = data[map_id].name
  end
end

To get the name, just write $game_map.name

For the event name, I think Night_Runner made one. I'll search around a bit.

EDIT: Nevermind, that was for XP. However, I found a solution.

CODE
class Game_Event
  attr_accessor :event
end


Insert that somewhere in the scripts (I put it under the other script I gave you), and then use
$game_map.events[Event_ID].event.name to get the name.

This post has been edited by stripe103: Jun 23 2011, 09:07 AM


__________________________

By Axerax

The rest of my sig



Go to the top of the page
 
+Quote Post
   
Sel Feena
post Jun 24 2011, 02:17 AM
Post #3


Level 2
Group Icon

Group: Member
Posts: 26
Type: Writer
RM Skill: Beginner




Bah. Kind of lame that you can't get to them without rewriting code. Silly VX :/

Thanks for the help. smile.gif

While I'm here, and to avoid clogging up the help forum, can someone tell me how to access the Arrows in the game system's windowskin file, if that's even possible? So, my windowskin right now is (from CLOSET-VX):



And I want to be able to display the brown up/down/left/right arrows in a window.

This post has been edited by Sel Feena: Jun 24 2011, 02:59 AM
Go to the top of the page
 
+Quote Post
   
stripe103
post Jun 24 2011, 09:07 AM
Post #4


PHP ERROR: Couldn't get value from UInteger. Value too large
Group Icon

Group: Revolutionary
Posts: 737
Type: Mapper
RM Skill: Intermediate




The only way I know on how to get them is to have the contents bitmap to be bigger than the actual window. I'm sure it's possible, but I don't know how. Not simple anyway. One solution I know is that you can open the windowskin file and then cut out the parts needed through a script. I don't know how to do that though.. Sorry.


__________________________

By Axerax

The rest of my sig



Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 23rd May 2013 - 11:15 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker