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.

[Resolved] If comment exists in event?

I have this method for when the player hits "Z" on the keyboard i want it to open a scene if a comment in the event is present. How do i go about doing this?

Code:
class Scene_Map
  alias non_thief_update update
  
  def update
    non_thief_update
    if Input.trigger?(Input::Z)
      call_thief
    end
  end
  
  def call_thief
    case $game_player.direction
    when 2
      lookingx = $game_player.x
      lookingy = $game_player.y + 1
   when 4
      lookingx = $game_player.x - 1
      lookingy = $game_player.y
    when 6
      lookingx = $game_player.x + 1
      lookingy = $game_player.y
    when 8
      lookingx = $game_player.x
      lookingy = $game_player.y - 1
    end
    for actor in $game_party.actors
      thief = actor
    end
    for actor in $game_party.actors
        thief = actor
    end
   [color=red]if comment "thief" exists[/color]
    return if thief == nil
    end
  end
 
I think I know what you are doing here. ;)

Try this:
Code:
class Game_Character
  def events_in_front
    nx = @x + (@direction == 4 ? -1 : @direction == 6 ? 1 : 0)
    ny = @y + (@direciton == 8 ? -1 : @direction == 2 ? 1 : 0)
    events = []
    for event in $game_map.events.values
      events << event if event.x == nx && event.y == ny
    end
    return events
  end
end

class Game_Event
  attr_reader :thief
  alias_method :seph_theifcommentreader_gmevt_refresh, :refresh
  def refresh
    @thief = false
    seph_theifcommentreader_gmevt_refresh
    return if @erased || @list.nil?
    @list.each do |ec|
      if ec.code == 108
        if ec.parameters[0].downcase.include?('thief')
          @thief = true
          break
        end
      end
    end
  end
end

class Scene_Map
  alias_method :seph_theifcommentreader_scnmap_update, :update
  def update
    seph_theifcommentreader_scnmap_update
    if Input.trigger?(Input::Z)
      events = $game_player.events_in_front
      events.each do |event|
        if event.theif

          # Your code here

        end
      end
    end
  end
end

That should work but I haven't tested it.
 
It's a typo mistake.

Code:
class Game_Character
  def events_in_front
    nx = @x + (@direction == 4 ? -1 : @direction == 6 ? 1 : 0)
    ny = @y + (@direciton == 8 ? -1 : @direction == 2 ? 1 : 0)
    events = []
    for event in $game_map.events.values
      events << event if event.x == nx && event.y == ny
    end
    return events
  end
end

class Game_Event
  attr_reader :thief
  alias_method :seph_theifcommentreader_gmevt_refresh, :refresh
  def refresh
    @thief = false
    seph_theifcommentreader_gmevt_refresh
    return if @erased || @list.nil?
    @list.each do |ec|
      if ec.code == 108
        if ec.parameters[0].downcase.include?('thief')
          @thief = true
          break
        end
      end
    end
  end
end

class Scene_Map
  alias_method :seph_theifcommentreader_scnmap_update, :update
  def update
    seph_theifcommentreader_scnmap_update
    if Input.trigger?(Input::Z)
      events = $game_player.events_in_front
      events.each do |event|
        if event.thief #here says event.theif, and it's thief :)

          # Your code here

        end
      end
    end
  end
end
 
I used the script and it works fine (although I may have made a mistake in the direction test thing).

Code:
class Game_Character
  def events_in_front
    nx = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
    ny = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
    events = []
    for event in $game_map.events.values
      events << event if event.x == nx && event.y == ny
    end
    return events
  end
end

class Game_Event
  attr_reader :thief
  alias_method :seph_theifcommentreader_gmevt_refresh, :refresh
  def refresh
    @thief = false
    seph_theifcommentreader_gmevt_refresh
    return if @erased || @list.nil?
    @list.each do |ec|
      if ec.code == 108 || ec.code == 408
        if ec.parameters[0].downcase.include?('thief')
          @thief = true
          p @id
          break
        end
      end
    end
  end
end

class Scene_Map
  alias_method :seph_theifcommentreader_scnmap_update, :update
  def update
    seph_theifcommentreader_scnmap_update
    if Input.trigger?(Input::SHIFT)
      events = $game_player.events_in_front
      events.each do |event|
        if event.thief #here says event.thief, and it's thief :)
          
          p 1
        end
      end
    end
  end
end

Try that code. When you make an event, the comment must contain

Comment: thief
 
I check your demo, and the problem belongs to the SDK version that you're using, so, update your SDK version.
But, The SDK 2.3 It's fine, your problem is that you are loading twice the SDK, because you have the full version in the script editor, and you are using the RSC version, so erase the following scripts:

RSC Script
SDK Setup

And update the SDK 2.3 to SDK 2.4.
Also you can update that ugly Antilag, replace that for the Seph's Antilag (Find it in the TestBed).

Good Luck!
 
I updated to SDK 2.4 and took out the other SDK scripts and make an event with comment: thief on him but when i hit the "Z" key on him nothing happens. I put the code like this:
Code:
if event.thief #here says event.theif, and it's thief :)

          $scene = Scene_Menu.new

        end
I am also getting an error message that just says "4" before the game but it still runs. Thanks
 
yes, the "4" message, you just must erase the line 24 of the Seph Script that puts:
"p @id" #This retrieves the Ids of the Comment's events, just erase it.
____

And for the code...mmm remember the Z key is the "shift"(The key that is under the Enter key) keyboard real key.... I mean, you need to press the Shift key in the keyboard.
 

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