[XP] Mail Box System

Started by G_G, August 01, 2010, 04:14:26 pm

Previous topic - Next topic

stripe103

After you close the scene yeah.. But I think she meant that you could send gold and when you open a specific mail, you'll get them. What you do is that no matter what mail you open, you get that money.

SquareMan

not if you use this
Quote$game_party.mail_read?(id)
QuoteThey've got helmets on they're heads. But I gotta watermeloan instead!

xeilmach

How do you make the text message wrap so the words in a line would not get cut off?

And how come when pressing ENTER after reading a message, the Mail Title list's window is shrunk?
Quote from: Blizzard on November 17, 2010, 02:22:18 am
Don't worry if you lose your motivation at one point. Just keep doing something else, it should come back to you. If it doesn't, get back into it anyway. xD

G_G

Your first question, its a small bitmap snippet by Blizzard. Very useful.
class Bitmap
  def format_text(text, width)
    words = text.split(' ')
    return words if words.size == 1
    result, current_text = [], words.shift
    words.each_index {|i|
        if self.text_size("#{current_text} #{words[i]}").width > width
          result.push(current_text)
          current_text = words[i]
        else
          current_text = "#{current_text} #{words[i]}"
        end
        result.push(current_text) if i >= words.size - 1}
    return result
  end
end


Second, small typo I had when making the script. Its fixed now.

xeilmach

Thanks for the reply, game_guy.

1. I don't understand how the text wrap is used. Could you post any example?

2. The shrunk window is fixed now, but the window is moved a little to the right and into the message window after a mail is selected.
Quote from: Blizzard on November 17, 2010, 02:22:18 am
Don't worry if you lose your motivation at one point. Just keep doing something else, it should come back to you. If it doesn't, get back into it anyway. xD

G_G

1. Here's an example from the script.
  def draw_msg(msg, x, y)
   text = self.contents.format_text(msg, 392) #msg is the text it formats, 392 is the max width
   text.each_index {|i|
       self.contents.draw_text(x, y + i*32, 544, 32, text[i])}
 end


2. Fixed.

hyakkivn

How can I call this Mail scene from the menu or something like that. That's mean I don't have to create an event to call the script.
Sorry for  :n00b: question  :haha:

Twb6543

*cough*
Spoiler: ShowHide
 

#==============================================================================
# ** Scene_Menu
#------------------------------------------------------------------------------
#  This class performs menu screen processing.
#==============================================================================

class Scene_Menu
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     menu_index : command cursor's initial position
  #--------------------------------------------------------------------------
  def initialize(menu_index = 0)
    @menu_index = menu_index
  end
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Make command window
    s1 = $data_system.words.item
    s2 = $data_system.words.skill
    s3 = $data_system.words.equip
    s4 = "Status"
    s5 = "Mail"
    s6 = "Save"
    s7 = "End Game"
    @command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6, s7])
    @command_window.index = @menu_index
    # If number of party members is 0
    if $game_party.actors.size == 0
      # Disable items, skills, equipment, and status
      @command_window.disable_item(0)
      @command_window.disable_item(1)
      @command_window.disable_item(2)
      @command_window.disable_item(3)
    end
    # If save is forbidden
    if $game_system.save_disabled
      # Disable save
      @command_window.disable_item(4)
    end
    # Make play time window
    @playtime_window = Window_PlayTime.new
    @playtime_window.x = 0
    @playtime_window.y = 224
    # Make steps window
    @steps_window = Window_Steps.new
    @steps_window.x = 0
    @steps_window.y = 320
    # Make gold window
    @gold_window = Window_Gold.new
    @gold_window.x = 0
    @gold_window.y = 416
    # Make status window
    @status_window = Window_MenuStatus.new
    @status_window.x = 160
    @status_window.y = 0
    # Execute transition
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of windows
    @command_window.dispose
    @playtime_window.dispose
    @steps_window.dispose
    @gold_window.dispose
    @status_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update windows
    @command_window.update
    @playtime_window.update
    @steps_window.update
    @gold_window.update
    @status_window.update
    # If command window is active: call update_command
    if @command_window.active
      update_command
      return
    end
    # If status window is active: call update_status
    if @status_window.active
      update_status
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (when command window is active)
  #--------------------------------------------------------------------------
  def update_command
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Switch to map screen
      $scene = Scene_Map.new
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # If command other than save or end game, and party members = 0
      if $game_party.actors.size == 0 and @command_window.index < 4
        # Play buzzer SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # Branch by command window cursor position
      case @command_window.index
      when 0  # item
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to item screen
        $scene = Scene_Item.new
      when 1  # skill
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        @command_window.active = false
        @status_window.active = true
        @status_window.index = 0
      when 2  # equipment
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        @command_window.active = false
        @status_window.active = true
        @status_window.index = 0
      when 3  # status
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        @command_window.active = false
        @status_window.active = true
        @status_window.index = 0
      when 4 # mail
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Transfer to the mail screen
        $scene = Scene_Mail.new
      when 5  # save
        # If saving is forbidden
        if $game_system.save_disabled
          # Play buzzer SE
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to save screen
        $scene = Scene_Save.new
      when 6  # end game
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to end game screen
        $scene = Scene_End.new
      end
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (when status window is active)
  #--------------------------------------------------------------------------
  def update_status
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Make command window active
      @command_window.active = true
      @status_window.active = false
      @status_window.index = -1
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Branch by command window cursor position
      case @command_window.index
      when 1  # skill
        # If this actor's action limit is 2 or more
        if $game_party.actors[@status_window.index].restriction >= 2
          # Play buzzer SE
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to skill screen
        $scene = Scene_Skill.new(@status_window.index)
      when 2  # equipment
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to equipment screen
        $scene = Scene_Equip.new(@status_window.index)
      when 3  # status
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to status screen
        $scene = Scene_Status.new(@status_window.index)
      end
      return
    end
  end
end



*cough*

Line 114 in the Mail script should be set to:

  Return_Scene    = Scene_Menu


Replace you default menu with that or follow a how to add a option to a menu guide if you have a custom one.

Note the only reason it isn't a snippet is that I don't have time at the moment
If you put a million monkeys at a million keyboards, one of them will eventually write a Java program.
The rest of them will write Perl programs.

Fenriswolf

I'm sorry for necroposting.. again.  :>.<:
But I've been struggling with a problem which I can't seem to overcome.

Quote from: game_guy on August 04, 2010, 12:37:43 pm
Updated.
@Nadim: I updated it so you can now use this in a conditional branch
$game_party.mail_read?(id)


If its been read you can turn on a switch or whatever you need. ;D Thanks for the idea


This feature is great, but the problem is triggering it.
I'm trying to have this script work together with the Quest Log script, also from G_G.

So, I would like an event to run as a result of reading a message.
Problem is, I can't seem to get this to work.

Basically, I want the event to run as soon as the mailbox is closed.
(in this event i'll put some conditional branches for mails being required, which will then add quests to the quest log)

Any idea how to do this?

stripe103

December 12, 2011, 02:08:41 am #29 Last Edit: December 12, 2011, 02:19:34 am by stripe103
You could have a parallel process common event that all the time checks if the message have been read, and then just make the event you want to run being within the Conditional Branch. Or if you want a map event to run, have the common event check and it is it true, then make it set a switch to true and have that switch as a startup condition for the desired event.

Fenriswolf

I did try something similar, but my game froze as a result.
I figured the same would happen if I did it your way, I could be wrong.
Thanks for the suggestion :)

G_G

Execute this in the Script Call.
$game_switches[INSERT_ID_HERE] = $game_party.mail_read?(INSERT_ID_HERE)

Fenriswolf

Thanks a lot, that should do the trick.

Fenriswolf

I'm sorry for the double post,
but I'm still having a small problem.
Using the script call you gave me, allows me to add quests, but..

I have a message that is normally displayed whenever a quest is added,
but since in this case the quests are added while the mail scene is still active,
no message can be displayed.

Would it be possible to have something occur as soon as the player presses X (B button) and thus leaves the mail scene?
And if so, how?
Anything will do: the running of an event, switch turning on.

G_G

Pseudo code here. You could try doing it like this.
Call mail menu
if party.has_quest(id) and switch[id] is off
    display message
    switch[id] = on
end


Thats the only thing I can think of.

Fenriswolf

I know I'm necro-posting here, but I found an easier and better solution to the problem I was having.
Figured I'd share it, in case anyone ever has trouble with the same issue.

Just put this after line 301 in the script, that's all.
$game_switches[id] = true

metalebrio89

Sorry for necro-posting, guys, I just wanted to ask if there is a way to add an Icon (next to mail's name) for unreaded messages and a different one for readed messages.
Nice script, by the way. 8)

G_G

It's very possible. If you can wait a day or two, I can whip it up real fast.

metalebrio89

thanks, man, I really aprecciate your help  :)