Scripts:Stairs

From OHRRPGCE-Wiki
Jump to navigation Jump to search
Stairs-zones.png

This script is for walking diagonally up or down stairs at a 45 degree angle. The player can freely move one tile at time diagonally, or move north and south if the stairs are wide enough.

If you just want the player to walk down or up the complete flight of stairs when they move to the top or bottom step, you can use this simpler set of scripts.

This script relies on 4 different zones to indicate the 4 diagonal directions in which you could move. At the end of a set of stairs, you can only go in one of those 4 directions (either up or down), so there will be a single zone on those tiles. In the central tiles of stairs (that are more than 1 tile long) there are two available diagonal directions, so you would have two overlapping zones. While you are standing on one of these four zones the script overrides normal left or right movement. See the screenshot.

Here is an example .rpg file.

# You only need to call this script once, it will keep running the entire game.
# For example, set as the new-game script.
plotscript, handle stairs, begin
    while(true) do(
        # Have we called a wait command yet?
        variable (waited)
        waited := false

        if(hero is walking(me) == false && player is suspended == false) then(

            if (key is pressed (left key)) then(
                # Zone 1 indicates stairs going up-left
                if (read zone(1, hero X, hero Y)) then(
                    walk diagonally(up, left)
                    waited := true
                )
                # Zone 2 indicates stairs going down-left
                else if (read zone(2, hero X, hero Y)) then(
                    walk diagonally(down, left)
                    waited := true
                )
            ) else if(key is pressed (right key)) then(
                # Zone 3 indicates stairs going up-right
                if (read zone(3, hero X, hero Y)) then(
                    walk diagonally(up, right)
                    waited := true
                )
                # Zone 4 indicates stairs going down-right
                else if (read zone(4, hero X, hero Y)) then(
                    walk diagonally(down, right)
                    waited := true
                )
            )

        )

        # "walk diagonally" already does a wait, make sure we don't wait a second time,
        # or movement up stairs will stutter.
        if (waited == false) then (wait(1))
    )
end

# Move the player one tile diagonally while preventing normal movement
script, walk diagonally, up or down, left or right, begin
    suspend player  # Suspend player prevents normal player movement, very important
    suspend hero walls
    walk hero(me, up or down, 1)
    walk hero(me, left or right ,1)
    wait for hero(me)
    resume player
    resume hero walls
end