Advertisement
roninator2

Tidloc Compass - Mod - Multiple locations

Dec 5th, 2024
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.69 KB | None | 0 0
  1. ################################################################################
  2. #    Compass script v.1.2                                                      #
  3. #         by Tidloc                                                            #
  4. #==============================================================================#
  5. #  simple script, that allows on given maps a compass to appear and point at a #
  6. #  given point on that map. To define that point use the following command:    #
  7. #     Tidloc::Set_Coord(*map*,*x*,*y*)                                         #
  8. #  were x and y are the x and y coordinates on that map.                       #
  9. #  If no coordinates are saved for a specific map, no compass will appear.     #
  10. #==============================================================================#
  11. #  Only adjustable thing in this script is the name of the graphic for the     #
  12. #  compass, and the place where the compass will be shown. Everything else     #
  13. #  will be calculated on its own by using the stated command.                  #
  14. #  You can erase the saved coordinates with the command:                       #
  15. #     Tidloc::Clear_Coord(*map*)                                               #
  16. #  You are free to leave the map out, then all coordinates will be erased.     #
  17. #==============================================================================#
  18. #  Feel free to use this script, but please credit me for my work! ^__^        #
  19. #==============================================================================#
  20. #  Modification: Roninator2                                                    #
  21. #  Now able to hold several locations at once                                  #
  22. #  New method - Remove_Coord                                                   #
  23. #    Specify what coordinates to remove - Tidloc::Remove_Coord(map_id, x, y)   #
  24. #  It will hold any coordinates you provide, but will only point               #
  25. #    to the last one in the array for that map.                                #
  26. ################################################################################
  27.  
  28. $imported = {} if $imported.nil?
  29. $imported["Tidloc-Compass"] = [1,2,0]
  30.  
  31. module Tidloc
  32.   module Compass
  33.     Graphic = "compass_needle"
  34.     Target  = nil
  35.     X = Graphics.width - 32
  36.     Y = 32
  37.   end
  38.    
  39. ################################################################################
  40.  
  41.   class<<self
  42.     def Set_Coord(map,x,y)
  43.       $game_system._tidloc_compass[map] = [] if $game_system._tidloc_compass[map].nil?
  44.       $game_system._tidloc_compass[map] << [x,y]
  45.     end
  46.    
  47.     def Remove_Coord(map,x,y)
  48.       return if $game_system._tidloc_compass == []
  49.       for i in 0..$game_system._tidloc_compass[map].size - 1
  50.         set = $game_system._tidloc_compass[map][i]
  51.         if set[0] == x && set[1] == y
  52.           $game_system._tidloc_compass[map].delete($game_system._tidloc_compass[map][i])
  53.         end
  54.       end
  55.     end
  56.    
  57.     def Clear_Coord(map = nil)
  58.       if map == nil
  59.         $game_system._tidloc_compass = []
  60.       else
  61.         $game_system._tidloc_compass[map] = []
  62.       end
  63.     end
  64.   end
  65. end
  66.  
  67. class Game_System
  68.   attr_accessor :_tidloc_compass
  69.   alias wo_compass_init initialize
  70.   def initialize
  71.     self._tidloc_compass = []
  72.     wo_compass_init
  73.   end
  74. end
  75.  
  76. class Scene_Map < Scene_Base
  77.   if !$imported["Tidloc-Header"]
  78.     alias wo_tidloc_update update
  79.     def update
  80.         compass_update
  81.       wo_tidloc_update
  82.     end
  83.   end
  84.  
  85.   def compass_update
  86.     if $game_system._tidloc_compass[$game_map.map_id]
  87.       x = Tidloc::Compass::X
  88.       y = Tidloc::Compass::Y
  89.       ydif = 0
  90.       xdif = 0
  91.       $game_map.screen.pictures[401].show(Tidloc::Compass::Graphic,
  92.                                            1, x, y, 50, 50, 255, 0)
  93.       $game_system._tidloc_compass[$game_map.map_id].each do |i|
  94.         next if i.nil?
  95.         xdif = $game_player.x - i[0].to_i
  96.         ydif = $game_player.y - i[1].to_i
  97.       end
  98.       angle = 0
  99.       if ydif == 0 && xdif > 0
  100.         angle = 180
  101.       elsif ydif == 0 && xdif < 0
  102.         angle = -180
  103.       elsif xdif == 0 && ydif > 0
  104.         angle = 0
  105.       elsif xdif == 0 && ydif < 0
  106.         angle = 360
  107.       elsif xdif == 0 && ydif == 0
  108.         $game_map.screen.pictures[401].erase
  109.         unless Tidloc::Compass::Target.nil?
  110.           $game_map.screen.pictures[401].show(Tidloc::Compass::Target,
  111.                                            1, x, y, 50, 50, 255, 0)
  112.         end                                  
  113.       else
  114.         angle = Math::atan2(xdif + 0.0, ydif + 0.0) * 360.0 / Math::PI
  115.       end
  116.       $game_map.screen.pictures[401].rotate(angle)
  117.     else
  118.       $game_map.screen.pictures[401].erase
  119.     end
  120.   end
  121. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement