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] "Not Player" event command?

Hi there,

This should be fairly straight forward but for some reason I am having problems with it... Essentially I am dealing with the Game_Map class and want something to apply to some events but not others. I also don't want this to apply to the player. The way I want some events to be included/excluded depends on the events name (by default EV001, EV002, etc.)
Events that are excluded would have a name something like "EV001"
Events that are included would have a name something like "EV001#TEST#"
The script would check the events name and look for a #TEST# within the name. Remember this would all have to be done within Game_Map so I believe I would need to add a few new attr_accessor's.

So for example: "if not player or event_name.include?("#TEST#)"

If this can't be done within Game_Map but can be done some other way, or an easier way, I'd like to hear your suggestions as well.

Any help would be appreciated,
Thanks in advance.

EDIT: Maybe it would help if you knew why I am trying to do this. There are several things that I need this script snippet for. One of them being so that Flying Monsters can fly over cliffs while player's and other events cannot (and no I can't use "Always On Top" for the system I am trying to create).
Hopefully that helps. Thanks again.
 
Inside Game_Map's setup method theres a for that initializes all the events.. Inside that for just ask if the event's name matches "#TEST#", for instance. If it matches that name either create another Event class or add an attribute to the Game_Event class and if it matches set that attribute to whatever you need so that it is differente from other clases.
Example
Code:
for i in @map.events.keys
  if @map.events[i].name == "#TEST#"
    @events[i] = Game_Event_Costum.new(@map_id, @map.events[i])
  else
    @events[i] = Game_Event.new(@map_id, @map.events[i])
  end  
end

Cya

EDITED for a clearer example
 
Thanks that helped me quite a bit but I'm still running into a few problems... Again, I need some events to be blocked by certain tiles and others to be able to walk over them.

Here's what I have so far:
Code:
    
class Game_Map

  def passable?(x, y, d, self_event = nil)

    for i in @map.events.keys
      if @map.events[i].name == "#TEST#" and terrain_tag(x, y) == 5
         return false
      end  
    end

  end
end

The problem is, if it finds an event that has the name #TEST# then ALL the events on the map can't walk over tiles with tag 5. If it doesn't find an event with the name #TEST# then ALL the events can walk over the tiles.
What I'm trying to do is so that ONLY the events with #TEST# in their name can't walk over and the rest will be able to walk over.

I'd really appreciate some help so I can complete the final touches on this system. Thanks in advance.
 
in that case maybe you should create another Event class, and overwrite its passable? method.
Let me show you an example:

Code:
class Game_Event_Costum < Game_Event
  def initialize(map_id, event)
    super(map_id, event)
  end
  def passable?(x, y, d)
    # Get new coordinates
    new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
    new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
    # If coordinates are outside of map
    unless $game_map.valid?(new_x, new_y)
      # impassable
      return false
    end
    # If through is ON
    if @through
      # passable
      return true
    end
    # If unable to leave first move tile in designated direction
    unless $game_map.passable?(x, y, d, self)
      return false	
    end


    # ***************************************
    # If terrain's tag equals 5, its not passable
    if $game_map.terrain_tag(new_x, new_y) == 5
      return false
    end
    # ***************************************


    # If unable to enter move tile in designated direction
    unless $game_map.passable?(new_x, new_y, 10 - d)
      # impassable
      return false
    end
    # Loop all events
    for event in $game_map.events.values
      # If event coordinates are consistent with move destination
      if event.x == new_x and event.y == new_y
        # If through is OFF
        unless event.through
          # If self is event
          if self != $game_player
            # impassable
            return false
          end
          # With self as the player and partner graphic as character
          if event.character_name != ""
            # impassable
            return false
          end
        end
      end
    end
    # If player coordinates are consistent with move destination
    if $game_player.x == new_x and $game_player.y == new_y
      # If through is OFF
      unless $game_player.through
        # If your own graphic is the character
        if @character_name != ""
          # impassable
          return false
        end
      end
    end
    # passable
    return true
  end
end

Its basically the same passable method with a small change, which its self explanatory.
This combined with the small piece of code I gave you before should be enough.

Later
 

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