Advertisement
NinjaChicle

RPG Maker VX Ace - Party Member Select Script

Jul 9th, 2022 (edited)
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.57 KB | None | 0 0
  1. #--------------------------------------------------------------------------
  2. #* Party Member Select Script
  3. #
  4. # A script for RPG Maker VX Ace projects
  5. #
  6. # script by: NinjaChicle
  7. #
  8. # This script lets you select an actor from your party and save their ID
  9. # in a variable. Also saves the name of the actor in a different
  10. # variable too if you want to.
  11. #
  12. # To use it, just put SceneManager.call(Scene_ActorSelect) in a script call and then
  13. # add the wait command for one frame, and you will be able to select an actor and then use the ID for
  14. # whatever you want.
  15. #
  16. #--------------------------------------------------------------------------
  17.  
  18. module YAHOO
  19.   ACTOR_ID_VAR = 1 #the variable in which the actor id will be saved in.
  20.   ACTOR_NAME = 2   #this variable will save the name of the selected actor.
  21.                    #set ACTOR_NAME to 0 if you don't need it.
  22.   SELECT_TEXT = "Choose who \nshould be \nselected." #the \n moves the text after it one line down.
  23. end
  24.  
  25. class Scene_ActorSelect < Scene_MenuBase
  26.   def start
  27.     super
  28.     @okay = false
  29.     create_actor_window
  30.     show_sub_window(@actor_window)
  31.   end
  32.  
  33.  
  34.   def update
  35.     super
  36.     return if @okay != true
  37.     do_stuff
  38.     return if @actor_window.opacity != 0
  39.     @actor_window.hide.deactivate
  40.     @text_window.hide
  41.     return_scene
  42.   end
  43.  
  44.   def do_stuff
  45.     move_window(@actor_window, 550, 13)
  46.     ghost_actor_window(0)
  47.     @text_window.opacity = @actor_window.opacity
  48.     @actor_window.contents_opacity = @actor_window.opacity
  49.     move_window(@text_window, -450, 13)
  50.   end
  51.  
  52.   def move_window(window, x, speed)
  53.     current_x = window.x
  54.     window.x = [x, current_x + speed].min if current_x < x
  55.     window.x = [x, current_x - speed].max if current_x > x
  56.   end
  57.   def ghost_actor_window(opacity)
  58.     current_o = @actor_window.opacity
  59.     @actor_window.opacity = [opacity, current_o + 13].min if current_o < opacity
  60.     @actor_window.opacity = [opacity, current_o - 13].max if current_o > opacity
  61.   end
  62.   #--------------------------------------------------------------------------
  63.   # show_sub_window
  64.   #--------------------------------------------------------------------------
  65.   def show_sub_window(window)
  66.     width_remain = Graphics.width - window.width
  67.     window.x = width_remain
  68.     @viewport.rect.x = @viewport.ox = 0
  69.     @viewport.rect.width = width_remain
  70.     window.show.activate
  71.   end
  72.  
  73.   #--------------------------------------------------------------------------
  74.   # on_actor_ok
  75.   #--------------------------------------------------------------------------
  76.  
  77.   def on_actor_ok
  78.       Sound.play_ok
  79.       $game_party.menu_actor = $game_party.members[@actor_window.index]
  80.       $game_variables[YAHOO::ACTOR_ID_VAR] = $game_party.menu_actor.id
  81.       window = @actor_window
  82.       @okay = true
  83.       $game_variables[YAHOO::ACTOR_NAME] = $game_actors[$game_party.menu_actor.id].name unless YAHOO::ACTOR_NAME == 0
  84.   end
  85.  
  86.   #--------------------------------------------------------------------------
  87.   # on_actor_cancel
  88.   #--------------------------------------------------------------------------
  89.  
  90.   def on_actor_cancel
  91.     Sound.play_buzzer
  92.     @actor_window.activate
  93.   end
  94.  
  95.   def create_actor_window
  96.     @actor_window = Window_MenuActor.new
  97.     @actor_window.set_handler(:ok,     method(:on_actor_ok))
  98.     @actor_window.set_handler(:cancel, method(:on_actor_cancel))
  99.     @actor_window.select_last
  100.     @text_window = Window_Base.new(0,0,200,120)
  101.     @text_window.width = Graphics.width - @actor_window.width
  102.     @text = YAHOO::SELECT_TEXT
  103.     @text_window.draw_text_ex(0,0,@text)
  104.   end
  105. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement