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.

RMVX Area Conditional Branch

Hello, I was wondering if there was anyway to use the Conditional Branch: Script command to determine the player's area. For example, if I wanted to make it so the music changes when the player is in a given area, it would do that. Can I do this via the default scripts or would I need a whole new script created for this?

Thank you.
 
Sure there is... you could for example do this:

Code:
if $game_player.x.between?(4, 12) and $game_player.y.between?(3, 6)

  # fancy code here

end

If by script command you mean event command, then note that all you have to put in the line is this:

Code:
$game_player.x.between?(4, 12) and $game_player.y.between?(3, 6)
 
Hmm that's very useful, thank you. That should suit my purposes, but I was just wondering if there's a script variable or whatever you call it for player's area, like how there is one for map.id.
 
You mean area like the area function in RM2k3? Because I don't think it's in XP or VX... though I'm not sure. I'm definately sure that the player doesn't have any areas, just the map, so... you should get more in-detail about what you need, maybe? ^^
 
In VX, you can create areas on maps, like if you have a world map and want 1 type of encounter on one part of it and another type on another part of it. Since the areas have area IDs, I was wondering if there was a way to check them via scripting like you could for map IDs.

But the player.x and player.y thing should work just as well.
 
Ah, I see... there is indeed areas in VX, who would've thought that! Ah well... lemme explain them to you, know that I found them XD

Areas are stored in $data_areas, which is a hash. Areas are stored in there by their ID as the key (so, if your area's named AREA001, it's ID is 1; therefore the key in the hash is also 1). The couple of things stored in the value part of the hash are less important - what is is that there's the rect field, which is an instance of Rect class.
While all of this sounds complicated maybe, all it means is: You can access the area's coordinated pretty easily, however not easy enough to be actually adviseable... so, let me invest a few and modify the (actually existant) default method to check if the player is in an area, so it's a bit friendlier to use... (search for def in_area?(area) within Game_Player in the script library and replace the whole method with the following)

[rgss]   #--------------------------------------------------------------------------
  # * Determine if in Area
  #     area : Area data (RPG::Area) or Area ID (Integer)
  #--------------------------------------------------------------------------
  def in_area?(area)
    if area.is_a?(Integer)
      area = $data_areas[area]
    end
    return false if area == nil
    return false if $game_map.map_id != area.map_id
    return false if @x < area.rect.x
    return false if @y < area.rect.y
    return false if @x >= area.rect.x + area.rect.width
    return false if @y >= area.rect.y + area.rect.height
    return true
  end
[/rgss]

Now, all you have to put in your conditional is this:

Code:
if $game_player.in_area?(1)

  # fancy code here

end

And this for a Conditional Branch event command:

Code:
$game_player.in_area?(1)

While, again, 1 stands for AREA001. In case you renamed your areas, you can see the ID in the window header of the Area's window header.


I'd like some input if it works, especially since I couldn't really test it now without a maker, could I? :p It's optimized for fast processing and compatibility, meaning there's only a single additional line that encounter checks have to run through now (and you can't really evade that), and you retain compatibility to anything unless it's modifying this very method.
 
I didn't see your post before I posted :grin:

Funny, I thought of doing the exact same thing when I noticed the in_area? method accepted an RPG::Area as an argument instead of an area ID.
 
Thanks for the help guys, I decided to make a Window_Area script for the menu screen with this. Pretty simple stuff, but I like being able to name regions on the world map.

I figure I'd ask this in here instead of making another topic. Trying to do another RMVX script conditional branch that checks the name of the first party member. For example, if you switch party members and put "Actor B" in front, an NPC will have a different response than if "Actor A" was in front.

I tried $game_party.members[0].character_name = "Actor B" but that didn't seem to work. I figure there has to be some way to do this, I knew you could in RMXP, but forgot the code snippet that allowed it.
 
Hmm, I'm trying to do it in an event like so

Conditional Branch: $game_party.members[0].name = "A"
Text: "Hello A"

Conditional Branch: $game_party.members[0].name = "B"
Text: "Hello B"

but the even will turn around real quick, like for a split second, and then turn back without any text. And the first party member is named "A"

any thoughts?

EDIT: It appears $game_party.members[0].name = "B" is actually changing the first character's name to "B", even when it appears in the conditional branch. I tried adding an "if" but that caused a syntax error; guess you can't do that with conditional branches.

EDIT #2: Problem solves. It was just a case of using $game_party.members[0].name == "A" over $game_party.members[0].name = "A"
 

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