Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Event Comment List

Well, Again again, I was scripting with this MACL method, but, this code has several problems that I can't fix.. So I need help with this.

The problems that I found:

- If the Event is Erased, the comment cheking still working. (This one is easy to solve, but I think, this must be script work by Itself, but don't work).

- Only works for 1 event page. (Only 1 page, i think the idea of this, is that read the event current page, but this scripts doesn't do that, only read the defined page).

This is the Code:

Code:
#==============================================================================

# ** Game_Event

#==============================================================================

 

class Game_Event

  #--------------------------------------------------------------------------

  # * Public Instance Variables

  #--------------------------------------------------------------------------

  attr_reader   :erased

  attr_reader   :event

  #-------------------------------------------------------------------------

  # * Name      : Event Comment List

  #   Info      : Gets the Info from the comments in events

  #               returns A Hash setup like so {'trigger' => info}

  #   Author    : Trickster

  #   Call Info : Variable Amount, String used for triggers

  #   Comments  : Detects Integers, Floats, Arrays and Hashes, else its a string

  #-------------------------------------------------------------------------

  def event_comment_list(*triggers)

    # Setup Parameters

    parameters = {}

    # Run Through Each Page With Index

    @event.pages.each_with_index do |page, index|

      parameters[index] = {}

      list = page.list

      return if list == nil or not list.is_a?(Array)

      list.each do |command|

        next if command.code != 108

        comment = command.parameters[0]

        array = comment.split

        trigger = array[0]

        value = array[1...array.size].join

        value = value.to_i if value =~ /\d+/

        value = value.to_f if value =~ /\d+\.\d+/

        value = eval(value) if value =~ /\[\.+\]/ or value =~ /\{\.+\}/

        parameters[index][trigger] = value if triggers.include?(trigger)

      end

    end

    return parameters

  end

end

A Call Example:

Comment: Gold 100

Code:
args = ['Gold', 'Silver', 'Bronze']

page = 0

if $game_map.events[1].event_comment_list(*args)[page].include?('Gold')

    $game_party.gold += $game_map.events[1].event_comment_list('Gold')[0]('Gold')

end

Well, maybe anyone can fix this, or can recreate this to make it work correctly.

Thanks.
 
I am not 100% on this, but try:

Code:
args = ['Gold', 'Silver', 'Bronze']

# Gets hash page_id => value

parameters = $game_map.events[1].event_comment_list(*args)

if parameters.has_key?(0)

  parameters[0].each {|value| $game_party.gain_gold += value}

end

I think that's how it works.
 
Mmm.. Doesn't Work, It give me a wrong number of arguments (0 for 1) in this line:

Code:
parameters[0].each {|value| $game_party.gain_gold += value}

And really, I don't figure, what did you do there? (Can you Explain that :) )
 
Oops. I based half the code on what it should be and what you had (gold is not a writable instance in Game_Party. You have to use the gain_gold method.

It should be
$game_party.gain_gold(value)

I need to get some sleep. lol
 
Thanks but still no working, I can print the value, but I cant add the ammount of gold to gameparty, I don't know why..

Here is the code:

Code:
 

args = ['Gold', 'Silver', 'Bronze']

# Gets hash page_id => value

parameters = $game_map.events[1].event_comment_list(*args)[0]

if parameters.has_key?(args[0])

  parameters.each {|value| p value[1]}

end

 

And about the event pages, Only read the first page, maybe you can give a look at the method.

Thanks Again (Yes Sleep is better :) )
 
Is it only reading the first page, or simply reading the active page? There is a difference. This method appears to read the events when the map is first called, so I think it might just read whatever event page is active when the map is first called.
 
@glitchfinder : Only read the page that you call in the method.

I get to this, but, Now I have another problem, Like I said, only read the page that you call, i want to know how i can get the event current active page?.

In a way like : Event.current_page....blah.

Code:
 

class Scene_Map

#--------------------------------------------------------------------------

# * Alias Listings

#--------------------------------------------------------------------------

  alias_method :meph_dynenviron_scmap_update, :update

#--------------------------------------------------------------------------

# * Frame Update

#--------------------------------------------------------------------------

  def update

    # Original Update

    meph_dynenviron_scmap_update

    if Input.trigger?(Input::Z) && $game_map.event?(*$game_player.tile_front)

      # Set list of Possible Arguments

      args = ['Gold', 'Silver', 'Bronze']

      # Gets hash page_id => value

      parameters = $game_player.event_front.event_comment_list(*args)[0]

      # If Event Comment Include Gold

      if parameters.has_key?('Gold')

        # Gain Gold equal to Parameter Gold n

        $game_party.gain_gold(parameters['Gold'])

      end

    end

  end

end

 

Thanks.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top