Advertisement
neutale

Random Choice Order

Aug 14th, 2018
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.51 KB | None | 0 0
  1. #==============================================================================
  2. # ■ Random Choice Order
  3. #  RandomChoiceList.rb
  4. #------------------------------------------------------------------------------
  5. #  When specified switch is ON, the order of the choices are randomized.
  6. #
  7. # ●How to use
  8. # 1. Turn on a # switch that's specified through module
  9. # 2. You'll see choices in randomized order during gameplay
  10. #
  11. # ●Terms of Service:
  12. #  It's possible to modify and redistribute without permission from the author.
  13. #  And this plugin licensed under MIT License.
  14. #-----------------------------------------------------------------------------
  15. # Copyright (c) 2016 Triacontane
  16. # This software is released under the MIT License.
  17. # http://opensource.org/licenses/mit-license.php
  18. #-----------------------------------------------------------------------------
  19. # Version
  20. # 1.0.0 2016/11/22 First release
  21. # ----------------------------------------------------------------------------
  22. # [Blog]   : http://triacontane.blogspot.jp/
  23. # [Twitter]: https://twitter.com/triacontane/
  24. # [GitHub] : https://github.com/triacontane/
  25. #=============================================================================
  26.  
  27. module Triac
  28.   # Number of a switch to enable randomized choice order
  29.   RandomChoiceTriggerSwitch = 1
  30. end
  31.  
  32. #==============================================================================
  33. # ■ Window_ChoiceList
  34. #==============================================================================
  35.  
  36. class Window_ChoiceList < Window_Command
  37.   #--------------------------------------------------------------------------
  38.   # ● Create command list
  39.   #--------------------------------------------------------------------------
  40.   alias rcts_make_command_list make_command_list
  41.   def make_command_list
  42.     if $game_switches[Triac::RandomChoiceTriggerSwitch]
  43.       @random_sort = (0...$game_message.choices.size).to_a.sort_by{rand}
  44.       @random_sort.each do |index|
  45.         add_command($game_message.choices[index], :choice)
  46.       end
  47.     else
  48.       rcts_make_command_list
  49.     end
  50.   end
  51.   #--------------------------------------------------------------------------
  52.   # ● Call choice handler
  53.   #--------------------------------------------------------------------------
  54.   alias rcts_call_ok_handler call_ok_handler
  55.   def call_ok_handler
  56.     if $game_switches[Triac::RandomChoiceTriggerSwitch]
  57.       $game_message.choice_proc.call(@random_sort[index])
  58.       close
  59.     else
  60.       rcts_call_ok_handler
  61.     end
  62.   end
  63. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement