SHARE
TWEET

Velvet Isis' Direction Based Interaction Script

Velvetisis Nov 6th, 2015 (edited) 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Velvet Isis' Direction Based Interaction Script
  2. #-------------------------------------------------------------------------------
  3. # This is not entirely my own work. It is mostly based on:
  4. #   The Infamous Bon Bon's Direction Based Line of Sight Events
  5. # This script takes the information they gave and adds a little bit to turn it
  6. # into a simple but functional Direction Based Interaction script.
  7. #-------------------------------------------------------------------------------
  8.  
  9. #-------------------------------------------------------------------------------
  10. # Directions:  To make an event's interaction be direction based use the event
  11. #   command 'Script...' under tab 3 of the Event Commands and type in
  12. #
  13. #   director
  14. #
  15. #   That's it, no ' no " just the word director, all lower case. Also they MUST
  16. #   MUST MUST MUST MUST be set to parallel process.
  17. #  
  18. #   Then for what they do when interacted with by the Player, have a new page
  19. #   with the Condition: self-switch B is on for when interacted from the side
  20. #   and Condition: self-switch C is on for when interacted from behind.
  21. #   The defaults are B and C, but you can change them below.
  22. #-------------------------------------------------------------------------------
  23.  
  24.  
  25. #-------------------------------------------------------------------------------
  26. #  Things you can edit
  27. #-------------------------------------------------------------------------------
  28.  
  29. module VIS  
  30.     SIDE_SELFSWITCH = "B"
  31.       #This is which self switch becomes true when the Event is interacted with
  32.       #from the side.
  33.       #Be sure to keep the " " around the letter.  
  34.      
  35.     BACK_SELFSWITCH = "C"
  36.       #This is which self switch becomes true when the Event is interacted with
  37.       #from the side.
  38.       #Be sure to keep the " " around the letter.
  39. end
  40.  
  41. #-------------------------------------------------------------------------------
  42. #   You probably shouldn't edit things below here, but I'm not gonna judge.
  43. #   I mean, that's how I learned to do things, was by putzin' around with
  44. #   other people's scripts.  I mean if you change stuff the script might not
  45. #   work, but you live and you learn, and that's how you get better
  46. #-------------------------------------------------------------------------------
  47.  
  48. class Game_Character
  49.  
  50. #-------------------------------------------------------------------------------  
  51. #     Player's position relation to Enemy
  52. #-------------------------------------------------------------------------------
  53.  
  54.   #---------------------------------#
  55.   #    Enemy behind Player?         #
  56.   #---------------------------------#
  57.     def E_behind_P?
  58.       ex = self.x
  59.       ey = self.y
  60.       px = $game_player.x
  61.       py = $game_player.y
  62.       pd = $game_player.direction
  63.      
  64.       if
  65.         @direction == 2 && pd == 2 && py > ey ||
  66.         @direction == 8 && pd == 8 && py < ey ||
  67.         @direction == 4 && pd == 4 && px < ex ||
  68.         @direction == 6 && pd == 6 && px > ex
  69.         return true
  70.       end
  71.     end
  72.    
  73.   #---------------------------------#
  74.   #    Player behind Enemy?         #
  75.   #---------------------------------#
  76.     def P_behind_E?
  77.       ex = self.x
  78.       ey = self.y
  79.       px = $game_player.x
  80.       py = $game_player.y
  81.       pd = $game_player.direction
  82.      
  83.       if
  84.         @direction == 2 && pd == 2 && py < ey ||
  85.         @direction == 8 && pd == 8 && py > ey ||
  86.         @direction == 4 && pd == 4 && px > ex ||
  87.         @direction == 6 && pd == 6 && px < ex
  88.         return true
  89.       end
  90.     end
  91.    
  92.   #---------------------------------#
  93.   #    Player Facing Enemy          #
  94.   #---------------------------------#
  95.     def P_face?
  96.       ex = self.x
  97.       ey = self.y
  98.       px = $game_player.x
  99.       py = $game_player.y
  100.       pd = $game_player.direction
  101.       if
  102.         pd == 2 && py < ey ||
  103.         pd == 8 && py > ey ||
  104.         pd == 4 && px > ex ||
  105.         pd == 6 && px < ex
  106.         return true
  107.       end
  108.     end
  109.    
  110.   #---------------------------------#
  111.   #    Enemy Facing Player          #
  112.   #---------------------------------#
  113.     def E_face?
  114.       ex = self.x
  115.       ey = self.y
  116.       ed = self.direction
  117.       px = $game_player.x
  118.       py = $game_player.y
  119.       if
  120.         ed == 2 && ey < py ||
  121.         ed == 8 && ey > py ||
  122.         ed == 4 && ex > px ||
  123.         ed == 6 && ex < px
  124.         return true
  125.       end
  126.     end
  127.    
  128.   #---------------------------------#
  129.   #    Facing Each Other            #
  130.   #---------------------------------#
  131.     def facing?
  132.       ex = self.x
  133.       ey = self.y
  134.       px = $game_player.x
  135.       py = $game_player.y
  136.       pd = $game_player.direction
  137.      
  138.       if
  139.         @direction == 8 && pd == 2 && py < ey ||
  140.         @direction == 2 && pd == 8 && py > ey ||
  141.         @direction == 6 && pd == 4 && px > ex ||
  142.         @direction == 4 && pd == 6 && px < ex
  143.         return true
  144.       end
  145.     end
  146.  
  147.   #---------------------------------#
  148.   #    Touching                     #
  149.   #---------------------------------#
  150.     def touching?
  151.       ex = self.x
  152.       ey = self.y
  153.       px = $game_player.x
  154.       py = $game_player.y
  155.       if (ex - px).abs + (ey - py).abs <= 1
  156.           return true
  157.       end
  158.     end
  159.    
  160. #-------------------------------------------------------------------------------
  161. #     Hitting            
  162. #-------------------------------------------------------------------------------
  163.  
  164.   #---------------------------------#
  165.   #     Hit from Front              #
  166.   #---------------------------------#  
  167.   def hitting
  168.     if touching?
  169.       if P_face?
  170.         if P_behind_E? #Hitting from behind
  171.           if Input.press?(:C)
  172.             set_self_switch("C", true)
  173.           end
  174.         elsif facing? #Hitting from in front
  175.           if Input.press?(:C)
  176.             set_self_switch("D", true)
  177.           end
  178.         else          #Hitting from side
  179.           if Input.press?(:C)
  180.             set_self_switch("B", true)
  181.           end
  182.         end          
  183.       end
  184.     end
  185.   end  
  186.  
  187. #-------------------------------------------------------------------------------
  188. #     Basic Enemy Behavior              
  189. #-------------------------------------------------------------------------------
  190.  
  191.   #---------------------------------#
  192.   #     Director                    #
  193.   #---------------------------------#
  194.   def director
  195.     hitting
  196.   end
  197.  
  198.  
  199. #-------------------------------------------------------------------------------
  200. #   Self Switches
  201. #-------------------------------------------------------------------------------
  202.  
  203.   #-----------------------------#
  204.   # Get Self Switch             #
  205.   #-----------------------------#
  206.     def get_self_switch(switch)
  207.       key = [@map_id, @id, switch]
  208.       return $game_self_switches[key]
  209.     end
  210.   #-----------------------------#
  211.   # Set Self Switch             #
  212.   #-----------------------------#
  213.     def set_self_switch(switch,true_false)
  214.       key = [@map_id, @id, switch]
  215.       $game_self_switches[key] = true_false
  216.       $game_map.need_refresh = true
  217.     end
  218.    
  219. end
  220.  
  221. class Game_Interpreter
  222.   def director
  223.     get_character(0).director
  224.   end
  225. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top