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.

XP: Terrain Tag's for Events

Star

Sponsor

So basically I want to alter how an event moves depending on what terrain tag they are standing on. I have already done this for the player by asking $game_player.terrain_tag == the value. But I haven't been as successful for events.

so under the command.code under Game Character 1

I want

command.code
1
if event's terrain tag == value
do this
else
move up

so how do I call the event's terrain tag?
 

Star

Sponsor

Neo-Bahamut":omlcsvqr said:
Just like the same way you do for the player:
Code:
$game_map.events[event_id].terrain_tag
Thank you for that.

I just have one more question. How do I make it to where it calls the event ID that is moving in that direction and loop through all event_ids to find the specific event that is standing on that terrain tag and make that event only do something different? I don't want all events doing it unless they are on the terrain tag.
 
It'd make sense to place that in Game_Event's update method, such as this:
Code:
class Game_Event

  alias terrainstuff_update update

  def update

    terrainstuff_update

    self.opacity = self.terrain_tag == 5 ? 128 : 255 # sets the opacity to 50% if on terrain #5, otherwise completely opaque

  end

end
Should work theoretically...
 

Star

Sponsor

BlueScope":2rr4vpie said:
It'd make sense to place that in Game_Event's update method, such as this:
Code:
class Game_Event

  alias terrainstuff_update update

  def update

    terrainstuff_update

    self.opacity = self.terrain_tag == 5 ? 128 : 255 # sets the opacity to 50% if on terrain #5, otherwise completely opaque

  end

end
Should work theoretically...
I'm so happy I could kiss you. I know it would have made sense to put it in game_event but I didn't since game_event was already looping through game_character some how. I basically just called self.terrain_tag in game_character and it worked freaking great for my two events

Now I can get people to walk up or down stairs going left or right : D
 
I'm not sure why you'd do it in Game_Character unless you want the player to be affected by terrain tags as well; it would be nicer to place the code in the subclass Game_Event.
 

Star

Sponsor

regi":3kmg6gjy said:
I'm not sure why you'd do it in Game_Character unless you want the player to be affected by terrain tags as well; it would be nicer to place the code in the subclass Game_Event.
True, but I did want the player to be effected. I want the player to walk up the same steps in the same fashion as an event would. The problem I was having was only being able to do it for the player and not events too. Don't have that problem now. I checked it for bugs just to make sure, didn't find anything. All is well :)

Edit: Here is a demo just incase you guys think I wasn't doing it right. http://www.filefront.com/17250165/Project5.rar

Show me the errors of my ways. I'm still new to this. I need to learn so if you wanna explain or ask questions go ahead. I wanna make sure I did do this right.
 
Hm, lemme give you some advice... if you promise you don't kiss me ;)

Giving us the project instead of the code is cool, however that means I can't check out the code as I don't have RMXP (still, providing a project in a case like this is kinda awesome...). That leaves me with testing the project, and of course I found some things you might want to fix... here's a snapshot:

stairsu.png


That of course isn't a direct snapshot, but a stitched-together one of multiple screens. You can easily see how the distance between the character's feet and the bottom of the stairs tile differs in each step, which is either due to a silly y-adjustment of the player, or because you chose a silly height for the stairs tile. A quick checkup of the tileset tells me that you did a good job on the last part, meaning you messed up the actual code.
That's not really a problem, though, as you should go back to that one either way :grin: That is because your characters aren't taking steps, but more like get lifted up to a certain y level and then travel horizonally. What you need instead is either a straight diagonal movement (move them 1px up for 2px they travel horizontally) or have that first-up-then-ahead-movement done for each step (which would look hyper-cool and hasn't been done before, I think... and it's quite easy to figure out :p ). Personally, I'd like to fiddle with this on my own if I were you, so I just leave you with this for now - just post again if you need help on it
Last but not least, there's a flaw in your script design... the functionality of travelling diagonally is cool, but you limit the player's movements here - you can't walk straight north or south anymore when on the steps. I personally don't see the reason for that, as it shouldn't be any problem whatsoever...

As for bug checking, I'd check what the y-coordinates (tile-wise) are for the respective instances... I can imagine problems with that if you rape their y-values like that, and it might cause incompatibilities with other scripts.

Keep up the good work!
 

Star

Sponsor

I see what you mean there. But the problem is. Since the character had to drop 64 pixels or two rmxp tiles within a distance of 5 steps. I had to do that math which was 2/5 which equals .4 So that was my gain or loss in y for the character to go 5 steps and appear perfectly within two tiles. I tried other numbers and ended up getting the player of center and eventually screws all to hell. I think I should do the stair drop better.

Also Yeah there really was no reason for me to prevent the player from going up or down on the stairs. I had a problem at first, but since fixed that and should return that to normal.

Wait.. How would I increase their potential of y and x gradually? *thinks about it* Maybe I'll figure it out before you respond.
 
You have two approaches basically... I don't think I'm taking away two much by just saying the 'captions' of these, being frame-based gradiation (aka time-based) and position-based gradiation... I'd personally recommend the latter, however here's a quick mock-up for the both of them (you should still think about what I mean by these two before looking at it... you know, for good practice, and because I only took 6 mins to spot your post XD ):

Code:
# frame-based (aka time-based)

def update

  @timer += 1

  @sprite.y = 50 + @timer

  @timer = 0 if @timer == 30 # replace 30 with however many frames it takes to complete one tile step

end
Code:
# position-based

def update

  @sprite.y = 50 + ( @sprite.x % 32 / 4 ) # you'd need to tinker with this A LOT, as it's just a real quick write, but I think if you put this in your code, you'll perfectly see what I'm talking about

end


As for your steps, there's a pretty easy solution to that: Make them 4 tiles long :D
Seriously though, 5 is a damn hard number to work with, as everything in RMXP is based on the number 2 (which is why you'll find any of 2, 4, 8, 16, 32, 64, 128 and 256/255 often), so working with a 2-based amount of steps will prevent problems like this. Also, when you think about it, including a prime (only divideable by 1 and itself, sure you know that) amount of stairs as a requirement allows for amounts based on the number 5, enabling you to make sets of 5, 10, 15, ... stairs; based on the number 2 gives you 2, 4, 6, 8, 10, ... stairs, in other words a lot more versatile and different, especially since 5 is already a huge scale to work with for the otherwise quite compact RMXP mapping style.
(sorry for the probably cheesy phrasing in the above paragraph, it's late at night over here :p )
 

Star

Sponsor

Okay I've been trying hard to make this perfect and i have no idea why, it's just a set of stairs damnit, but for some reason I can't let go trying to make it perfect.

Here's the script I have since you can't view RMXP I don't know why I didn't give it to you earlier

Code:
 

  

class Game_Character

  def move_upper_right0

    # If no direction fix

    unless @direction_fix

      # Face right if facing left, and face up if facing down

      @direction = 6

    end

    # When an up to right or a right to up course is passable

    

      # Update coordinates

      @x += 1

      @y -= 0.5

      # Increase steps

      increase_steps

  end

  def move_lower_right0

    # If no direction fix

    unless @direction_fix

      # Face right if facing left, and face down if facing up

      @direction = 6

    end

    # When a down to right or a right to down course is passable

 

      # Update coordinates

      @x += 1

      @y += 0.5

      # Increase steps

      increase_steps

  end

    def move_upper_left0

    # If no direction fix

    unless @direction_fix

     # Face left if facing right, and face up if facing down

      @direction = 4

    end

    # When an up to left or a left to up course is passable

 

      # Update coordinates

      @x -= 1

      @y -= 0.5

      # Increase steps

      increase_steps

 

  end

    def move_lower_left0

    # If no direction fix

    unless @direction_fix

      # Face down is facing right or up

      @direction = 4

    end

    # When a down to left or a left to down course is passable

 

      @x -= 1

      @y += 0.5

      # Increase steps

      increase_steps

 

  end

  def move_type_custom

    # Interrupt if not stopping

    if jumping? or moving?

      return

    end

    # Loop until finally arriving at move command list

    while @move_route_index < @move_route.list.size

      # Acquiring move command

      command = @move_route.list[@move_route_index]

      # If command code is 0 (last part of list)

      if command.code == 0

        # If [repeat action] option is ON

        if @move_route.repeat

          # First return to the move route index

          @move_route_index = 0

        end

        # If [repeat action] option is OFF

        unless @move_route.repeat

          # If move route is forcing

          if @move_route_forcing and not @move_route.repeat

            # Release forced move route

            @move_route_forcing = false

            # Restore original move route

            @move_route = @original_move_route

            @move_route_index = @original_move_route_index

            @original_move_route = nil

          end

          # Clear stop count

          @stop_count = 0

        end

        return

      end

      # During move command (from move down to jump)

      if command.code <= 14

        # Branch by command code

        case command.code

        when 1

        move_down

        when 2

          if self.terrain_tag == 0 or self.terrain_tag == 2 or self.terrain_tag == 5

          move_left

          return

          end

          if self.terrain_tag == 1 or self.terrain_tag == 3

          move_lower_left0

          return

          end

          if self.terrain_tag == 4  or self.terrain_tag == 6

          move_upper_left0

          return

          end

   

        when 3

          if self.terrain_tag == 0 or self.terrain_tag == 3 or self.terrain_tag == 6

          move_right

          return

          end

          if self.terrain_tag == 1 or self.terrain_tag == 2

          move_upper_right0

          return

          end

          if self.terrain_tag == 4  or self.terrain_tag == 5

          move_lower_right0

          return

          end

 

        when 4

          move_up

        when 5  # Move lower left

          move_lower_left

        when 6  # Move lower right

          move_lower_right

        when 7  # Move upper left

          move_upper_left

        when 8  # Move upper right

          move_upper_right

        when 9  # Move at random

          move_random

        when 10  # Move toward player

          move_toward_player

        when 11  # Move away from player

          move_away_from_player

        when 12  # 1 step forward

          move_forward

        when 13  # 1 step backward

          move_backward

        when 14  # Jump

          jump(command.parameters[0], command.parameters[1])

        end

        # If movement failure occurs when [Ignore if can't move] option is OFF

        if not @move_route.skippable and not moving? and not jumping?

          return

        end

        @move_route_index += 1

        return

      end

      # If waiting

      if command.code == 15

        # Set wait count

        @wait_count = command.parameters[0] * 2 - 1

        @move_route_index += 1

        return

      end

      # If direction change command

      if command.code >= 16 and command.code <= 26

        # Branch by command code

        case command.code

        when 16  # Turn down

          turn_down

        when 17  # Turn left

          turn_left

        when 18  # Turn right

          turn_right

        when 19  # Turn up

          turn_up

        when 20  # Turn 90° right

          turn_right_90

        when 21  # Turn 90° left

          turn_left_90

        when 22  # Turn 180°

          turn_180

        when 23  # Turn 90° right or left

          turn_right_or_left_90

        when 24  # Turn at Random

          turn_random

        when 25  # Turn toward player

          turn_toward_player

        when 26  # Turn away from player

          turn_away_from_player

        end

        @move_route_index += 1

        return

      end

      # If other command

      if command.code >= 27

        # Branch by command code

        case command.code

        when 27  # Switch ON

          $game_switches[command.parameters[0]] = true

          $game_map.need_refresh = true

        when 28  # Switch OFF

          $game_switches[command.parameters[0]] = false

          $game_map.need_refresh = true

        when 29  # Change speed

          @move_speed = command.parameters[0]

        when 30  # Change freq

          @move_frequency = command.parameters[0]

        when 31  # Move animation ON

          @walk_anime = true

        when 32  # Move animation OFF

          @walk_anime = false

        when 33  # Stop animation ON

          @step_anime = true

        when 34  # Stop animation OFF

          @step_anime = false

        when 35  # Direction fix ON

          @direction_fix = true

        when 36  # Direction fix OFF

          @direction_fix = false

        when 37  # Through ON

          @through = true

        when 38  # Through OFF

          @through = false

        when 39  # Always on top ON

          @always_on_top = true

        when 40  # Always on top OFF

          @always_on_top = false

        when 41  # Change Graphic

          @tile_id = 0

          @character_name = command.parameters[0]

          @character_hue = command.parameters[1]

          if @original_direction != command.parameters[2]

            @direction = command.parameters[2]

            @original_direction = @direction

            @prelock_direction = 0

          end

          if @original_pattern != command.parameters[3]

            @pattern = command.parameters[3]

            @original_pattern = @pattern

          end

        when 42  # Change Opacity

          @opacity = command.parameters[0]

        when 43  # Change Blending

          @blend_type = command.parameters[0]

        when 44  # Play SE

          $game_system.se_play(command.parameters[0])

        when 45  # Script

          result = eval(command.parameters[0])

        end

        @move_route_index += 1

      end

    end

  end

end

 

class Game_Player < Game_Character

    def update

    # Remember whether or not moving in local variables

    last_moving = moving?

    # If moving, event running, move route forcing, and message window

    # display are all not occurring

    unless moving? or $game_system.map_interpreter.running? or

           @move_route_forcing or $game_temp.message_window_showing

      # Move player in the direction the directional button is being pressed

      case Input.dir4

      when 2

        move_down

      when 4

        if $game_player.terrain_tag == 0 or $game_player.terrain_tag == 2 or $game_player.terrain_tag == 5

        move_left

        return

        end

        if $game_player.terrain_tag == 1 or $game_player.terrain_tag == 3

        move_lower_left0

        return

        end

        if $game_player.terrain_tag == 4  or $game_player.terrain_tag == 6

        move_upper_left0

        return

        end

   

      when 6

        if $game_player.terrain_tag == 0 or $game_player.terrain_tag == 3 or $game_player.terrain_tag == 6

        move_right

        return

        end

        if $game_player.terrain_tag == 1 or $game_player.terrain_tag == 2

        move_upper_right0

        return

        end

        if $game_player.terrain_tag == 4  or $game_player.terrain_tag == 5

        move_lower_right0

        return

        end

 

      when 8

        move_up

      end

    end

    # Remember coordinates in local variables

    last_real_x = @real_x

    last_real_y = @real_y

    super

    # If character moves down and is positioned lower than the center

    # of the screen

    if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y

      # Scroll map down

      $game_map.scroll_down(@real_y - last_real_y)

    end

    # If character moves left and is positioned more let on-screen than

    # center

    if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X

      # Scroll map left

      $game_map.scroll_left(last_real_x - @real_x)

    end

    # If character moves right and is positioned more right on-screen than

    # center

    if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X

      # Scroll map right

      $game_map.scroll_right(@real_x - last_real_x)

    end

    # If character moves up and is positioned higher than the center

    # of the screen

    if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y

      # Scroll map up

      $game_map.scroll_up(last_real_y - @real_y)

    end

    # If not moving

    unless moving?

      # If player was moving last time

      if last_moving

        # Event determinant is via touch of same position event

        result = check_event_trigger_here([1,2])

        # If event which started does not exist

        if result == false

          # Disregard if debug mode is ON and ctrl key was pressed

          unless $DEBUG and Input.press?(Input::CTRL)

            # Encounter countdown

            if @encounter_count > 0

              @encounter_count -= 1

            end

          end

        end

      end

      # If C button was pressed

      if Input.trigger?(Input::C)

        # Same position and front event determinant

        check_event_trigger_here([0])

        check_event_trigger_there([0,1,2])

      end

    end

  end

  end

 

The problem is I can't seem to figure out how to use your ideas for making the character move diagonal gradually instead of moving up then moving right. I tried the second formula but I couldn't figure out what to put in there to make the character move correctly. I tried the first one and ended up getting a Nomethod on + for @timer which doesn't make sense to me how could it not know how to add. *facepalm*

I did however fix the step movement and the graphics error by doing what you said about using 2 and 4's instead of 5. Took me forever to get it right but I think i do now.

http://www.filefront.com/17264293/Project5.rar
 

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