Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
Bob423

Compass script

Recommended Posts

So here's what i need. a compass that appears in the lower left, or upper right hand corner of the screen, and points toward the place the player is supposed to go next, regardless of what map the player is on.

Share this post


Link to post
Share on other sites

The problem with this kind of script, is that rpg maker does not provide any way of getting some kind of map directional relativity.

i.e. there's no easy way to find the path from Map A to Map B

 

Nonetheless, I thought I might try and tackle this one.

 

Instructions:

-Put above Main

-Configure MapManager, C_FORE (_IMG, _X, _Y)

 

To configure MapManager, think of it as a 2d grid or matrix of your world map, and put every map id that would belong to that x, y location within an array.

i.e you have 5 maps in your world, map01 is a map which contains an inner map (house), map02 - and then map03, map04 and map05 are to the left, bottom left and bottom of map01, respectively

MapManager =
[
[ [1, 2], [3] ],
[ [5], [4] ]
]

It looks a little odd, but this was the quickest (that I could see) way to query relative map locations.

If you think of the array like a grid, it may be easier to see what I mean

[
[[ (0,0) ], [ (1,0) ]],
[[ (0,1) ], [ (1,1) ]]
]

 

Each x, y location must be an array of MapIDs in order to account for inner maps, etc.

 

SOME WARNINGS(IMPORTANT):

-I made this in linux, so I haven't really tested it...I hope it does SOMETHING

-I have not yet accounted for what happens when you are on the same map as your target location -- if the script works, right now it should make the compass point north. I wanted to see that the basics work before touching on that.

-currently, to use this script you must first call

$compass.show

to show the compass,

$compass.hide

hides it; as well as set a target location, by using

$game_map.set_target_location(map_id)

 

Lemme know what happens!

 

# Configure your map here.
# Think of the world as a 2D Grid, and place each
# map id into the array accordingly.
MapManager =
[
[[id], [id], [id], [id]],
[[id], [id], [id], [id]]
]

# If you want a background for the compass
# use these configurations
C_BACK_IMG = nil
C_BACK_X = nil
C_BACK_Y = nil

# The following configuration is for the foreground
# of the compass. This will be the rotating part
C_FORE_IMG = ""
C_FORE_X = 0
C_FORE_Y = 0

# NOTE: any _IMG should be a filename
#	any _X or _Y should be integers, representing
#	  the compass's screen x, y position

class Game_Map
 attr_reader  :map_id
 def initialize
   @map_id = 18
 end
 def set_target_location(id)
    MapManager.each_index do |y|
	  MapManager[y].each_index do |x|
		    if MapManager[y][x].include?(id)
			  @target_x, @target_y = x, y
			  return
		    end
	  end
    end
 end

 def remove_target
    @target_x = @target_y = nil
 end

 def current_map_location
    MapManager.each_index do |y|
	  MapManager[y].each_index do |x|
		    if MapManager[y][x].include?(@map_id)
			  return [x, y]
		    end
	  end
    end
 end

 def relative_direction_to_target
    return 0 if !@target_x || !@target_y
    x, y = current_map_location
    # Get new target x,y relative to 0, 0
    target_x, target_y = @target_x - x, @target_y - y
    # Get relative angle
    angle = Math.atan2(target_y, target_x)
    # Convert to degrees, where 0 is north
    (angle * 180.0 / Math::PI + 90) % 360
 end

end



class Spriteset_Map

alias :new_update_compass :update unless method_defined? :new_update_compass

 def update
new_update_compass
$compass.update
 end
end

class Compass

 def show
return if @sprite
@sprite = Sprite.new
@sprite.bitmap = RPG::Cache.picture(C_FORE_IMG)
@sprite.x, @sprite.y = C_FORE_X, C_FORE_Y
if C_BACK_IMG
  @back = Sprite.new
  @back.bitmap = RPG::Cache.picture(C_BACK_IMG)
  @back.x, @back.y = C_BACK_X, C_BACK_Y
end
 end

 def hide
return unless @sprite
@sprite.dispose; @sprite = nil
if @back
  @back.dispose; @back = nil
end
 end

 def update
return unless @sprite
angle = $game_map.relative_direction_to_target.to_i
@sprite.angle = angle if @sprite.angle != angle
 end  
end

$compass = Compass.new

Share this post


Link to post
Share on other sites

cool, thanks. one question though. the way you explained the map manager doesnt really make sense to me.

 

edit: i typed in some numbers into the map manager

MapManager =
[
[[1], [2], [3], [4]],
[[5], [6], [7], [18]]
]

 

tested it, and got a no method error with this line

alias :new_update_compass :update unless method_defined? new_update_compass

line 70

 

i have 18 in there, because thats the id for the debug room

Edited by Bob423

Share this post


Link to post
Share on other sites

WHOOPs, I forgot the `:` in front of the symbol is should read:

alias :new_update_compass :update unless method_defined? :new_update_compass

 

As for the MapManager, try to think of it like your rpg maker xp tiles. A 2 dimensional grid. Rather than tiles, each square would be an entire map...imagine you took all the maps in your game and laid them out, side by side, as they would appear in game flow.

[N W][ N ][N E]
[ W ][ X ][ E ]
[s W][ S ][s E]

Assuming X is the current map the player is on, and N is to the north

That would be, say, your entire world. However, some maps might be INSIDE another map (i.e. a house in a village) and thus, that would mean 2 maps actually belong to that "section" of your world.

 

 

So, say, on your map1, if the player walks south they end up in map2

if they walk east from map2 they end up in map3

if they walk north from map3 they end up in map4

 

it would look like this:

[
[[1],[4]],
[[2],[3]]
]

 

Now, lets say map 1 also has a house in it...well technically, that house map is in the same location as map 1...so

[
[[1,5],[4]],
[[2  ],[3]]
]

Now, the "house" map (map 5) is in the same tile as map1

 

EDIT: Also, i should probably mention it, you'll have to build a grid that includes ALL your game maps,

 

[
[[ids],[ids],[ids],[ids],[ids]],
[[ids],[ids],[ids],[ids],[ids]],
[[ids],[ids],[ids],[ids],[ids]]
[[ids],[ids],[ids],[ids],[ids]]
]

This would be a world, that has 4x5 main maps -- it will be bigger/smaller depending on the number of maps in your game.

 

I know it's an irritating work around--but it's really the best you'll get with RPG Maker (that I know of, if anyone knows a better way speak up).

 

[ASIDE, JUST SOME OF KELLS THOUGHTS]Does a 2d game really need a persistent compass? It's not like you can change your orientation...as well as, its just using up what little screen space RMXP gives you to work with...

What about just giving the player a world map and drawing an x on it?

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By troyr
      hello, I came to ask a way or script to center the texts without having to use spaces to center them
      I was for a while looking for a script or something to help me focus the texts in rpg maker vx ace, without success
      So I come to ask directly if anyone has any way to focus the texts, thank you very much. :)
    • By Bob423
      Title screen by Kevin.ds
      (you've been replaced shiny :P)
       
      Story

      2000 Years ago a huge city covered nearly all of the world. It was a thriving city where everyone was happy. Scientists discovered something that could make life so much easier. Not that it wasn't easy already. The energy gave the people the ability to summon water, or fire out of thin air, control earth, and wind, as well as heal the injured instantly. This power was in limited supply, however. People began to get greedy, and keep this energy to themselves. It was stored in glass containers, and released for a brief moment when used. The greed was slowly weakening the energy, and the people eventually ran out. They blamed each other for this.
      Then one day, the sky turned black. The city began to sink into the ground, taking most of the people with it. Some people made it out alive. The people began to restart their society. For hundreds of years, everything was fine. There wasn't even any trace of the city.
      One day an unlimited supply of that energy was found. The energy, which the people began to call magic, had been passed down; from generation to generation, through the peoples' souls, but lay dormant until then. Children now had the ability to use magic whenever they wanted. As the children aged, they learned to control their magic, and built schools to teach their children. Schools where the student were able to learn about the kind of magic they wanted to study.
       
      The 3 types of magic are: Attack Magic, Healing Magic, and
      Status Magic.
       
      One particular 16 year old boy named *Bob starts his first day at a school in his hometown of Silverwood Village. His best friend, *Joe happens to be in his first class. Over the course of their first year at the school, they meet a girl named *Cathy, who becomes their friend eventually. Finally, at the end of the year, they take the Final Exam together, and pass. Not long after being informed of their achievement, the wooden training dummies, brought to life by magic, get out of control, and attempt to burn the school down. They all make it out alright, and the teachers use water spells to douse the flames. When they reach the village, they find that their entire home town is on fire! They find a way to escape the flames by jumping over a broken part of a fence. While escaping the flames, they get separated, and Bob falls unconscious. Bob wakes up in a house south of Silverwood Village, and meets an old man, who only says to call him Brian, and that he found Bob unconscious, but not the others. He directs Bob toward the village, and hands him a sword and shield as he sets off to find his friends.
       
      after finding his friends, Bob, with the help of his friends, must save the world from an ancient, corrupted power formerly sleeping under the earth's crust.
       
      *Player can name this character


       
      contents
      places
      features
      characters
      screenshots
      videos
      credits
      download
       
      [/anchor]
       
      Places
       
       

       
      Features
       
       
       

       
      Characters
       
       
       


       
      Screenshots
       
      here's an album of them http://imgur.com/a/6TGnQ








       

      First 19 minutes of the demo
      [media]http://www.youtube.com/watch?v=TSO1x_sagtQ[/media]

       

      Credits
       
       
       
       

       
      Here's a banner made by Kevin.ds

       
      [anchor=download]
       
      UPDATE: Added difficulty levels and made it so the player is forced to chose one of each class.
      this prevents the player from getting stuck on certain parts and forced to restart the game.
      Expert mode is how the game was before i added the difficulty levels.
      Hopefully the game is easier now :D
       
      DOWNLOAD 
      (About 120mb)

      If the above link doesn't work, I'm probably fixing something.
       
       
      Known Bugs
      (That I can't fix, or not without making parts of the game too easy.)
       
       
       
      Tips for stuck people:
       
       
       
      If something seems weird and isn't explained in game,
      (e.g. Caeli Temple being really high in the air when you're inside, but on a mountain when outside, or the Mana Temple seeming less old, and some rooms being different from the rest of the temple)
      it can usually be explained by saying "It's magic"
       
      sorry if the game is broken. Alternatively, you can watch this:
      http://www.youtube.com/playlist?list=PLmZjr8BajltKjHOZWMbmTdl7mpNDzMDyI&feature=mh_lolz
       
      The Hidden City of Arcatis is more of a prequel then an actual beginning...if that makes sense. I've written out what happens in the game as another alternative to playing it. http://pastebin.com/07Ns42cG
    • By Polraudio
      Im wondering if anyone could spare some time to make me a neat script. It doesnt have to be private just for me but for everyone to enjoy and use :D
       
      This script needs 2 parts.
       
      Part 1: I need a private item storage script that will allow a person to store things like they would in real life and be able to have multiple containers. EX: a pot will be able to store lets say 5 items and a chest will be able to store 25 items but those storage containers are not shared.
      If i put items in the pot they wont show up in the chest when i open them and vice versa.
       
      Syntax EX: $scene = Scene_Storage[num, size].new
      num = the storage id. EX: 1 would be the pot, 2 would be the chest,3 would be whatever, etc....
      size = how many items can fit in the container
       
      Full syntax in use: $scene = Scene_Storage[1, 5].new
      That would mean when the callscript is used it will open container #1 with whatever items the player put in them and the player can put a max of 5 items in it.
       
      Part 2: Part 2 might be a little tricky. It needs to be the same as the top one but every item put in these containers is shared across save files.
       
      EX: Save 1 puts potions in container 1. When save 2, 3, or 4 access that same container on their save the potions will be in there. when they take the potions out it will no longer be in there for other saves. This is shared storage.
       
      Syntax EX: $scene = Scene_SharedStorage[num, size].new
       
      Finally the reason for this. The reason for this is because my game is going to be random loot heavy and you will have an item limit so you cant carry 10000lbs worth stuff like other games.
       
      The reason for sharing between saves is simple. If you find a rare item and want to give it to a friend on another save file you have the ability to. You dont want to be an assassin and have a weapon you cant use. just give it to another save then :D.
       
      If you need more info please feel free to ask :D.
    • By Bob423
      so here are my problems.
       
      1. the offset of "lvl. 2" or whatever level you are, is messed up. changing the offset in the main menu screws it up a whole lot more everywhere else.
       
      2. in the items and skills menus, i want the part where you chose what character to use stuff on, to be always visible at the bottom, and for the menu to scroll when i press the left and right arrow keys, instead of the up and down like it is now.
       
      3. the status screen is messy, i need each character to have their own window, and for everything to be moved around so it all fits correctly. also, the name of the character shouldn't be under the character's face.
       
      4. the equipment screen isn't updated until you exit. e.i if you have a wooden sword equipped, but change to an iron sword, it will still say wooden sword until you exit the menu. i also want the part that says what is equipped to say "weapon: sword" or something instead of just "sword"
       
      how do you change a screen to show the map as a background instead of the annoying black background? i want to do that for the shop
       
      here are the scripts
       
       
       
      so yea, that's it.
    • By avarisclari
      Is there a simple way to create a script for a cutscene that requires you to have all items in your inventory like id's 001-010 for example?
×
×
  • Create New...