Age : 30 Inscrit le : 22/12/2011 Messages : 1600
| Sujet: Army Manager Sam 3 Aoû 2013 - 11:14 | |
| Crédit: Galv Ce script vous permet d'avoir un menu pour gérer tout vos alliés. Utile pour les tactic-RPG: Script: - Code:
-
#------------------------------------------------------------------------------# # Galv's Army Manager #------------------------------------------------------------------------------# # For: RPGMAKER VX ACE # Version 1.0 # Requested by Rue #------------------------------------------------------------------------------- # This script was designed for tactical battle system games to manager party # members (your army). You can arrange, dismiss, equip, etc. your units from # this scene as well as display some army and game related information. #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- # NOTE TAG - ACTORS OR CLASSES #------------------------------------------------------------------------------- # <a_icon: x> # icon displayed left of actor in the army manager. This icon # # will only appear if you set the ICONTYPES accordingly #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- # SCRIPT CALLS #------------------------------------------------------------------------------- # manage_army # Calls the army manager scene # # a_icon(id,icon_id) # Change an actor's icon during game. # a_access(id,x) # if x is false cannot access actor at all. Default true # a_cmd(id,:cmd,x) # used to enable/disable commands for certain actors # # :cmd is the CMD ID of the command (further down) # # x can be true or false to disable/enable commands # # armyname("Name") # Changes the name of your army #------------------------------------------------------------------------------- # EXAMPLES # a_cmd(1,:dismiss,false) # Disable the "DISMISS" command for actor 1 # a_cmd(4,:order,true) # Enable the "ORDER" command for actor 4. # # All commands are true (enabled) by default #------------------------------------------------------------------------------- ($imported ||= {})["Galv_ArmyManager"] = true module GARMY #------------------------------------------------------------------------------- # # * SETTINGS # #------------------------------------------------------------------------------- # Some Default Settings NO_ACTOR_ICON = 186 # Icon ID used if you don't tag actor with <a_icon: x> NO_CLASS_ICON = 162 # Icon ID used if you don't tag class with <a_icon: x> NO_WEAPON_ICON = 186 # Icon ID used if nothing is equipped ICONTYPE1 = :actor # these ICONTYPES can be :actor, :class or :weapon ICONTYPE2 = :weapon # This will show either the class icon, actor icon (if # ou note tagged them) or the equipped weapon icon to # the left of the actor's sprite. SPRITE_X_POS = 1.6 # width of box divided by this number to position the # character sprite. (2 is central). Default 1.6 B_MEMBERS = false # highlight members in party that are 'battle members' # true or false B_MEMBER_COLOR = 16 # windowskin color for battle member highlight box that # appears if B_MEMBERS = true # Army Info UNIT_COUNT = "Units: " # Party member count text HIGH_LEVEL = "Highest Level: " # Highest level text TIME = "Time: " # Time text FUNDS = "Funds: " # Gold amount text INFOVAR1 = 1 # Variable id used to display in info window INFOVAR2 = 2 # Variable id used to display in info window # Displays the variable name beside these. # Sounds DISMISS_SE = ["Blow8",100,100] # ["SE_Name",volume,pitch] for dimiss SE ORDER_SE = ["Wind7",100,100] # ["SE_Name",volume,pitch] for order SE # Command Setup # (Command list appears when you select a unit from your army) CMDS = { # CMD ID => ["NAME", :Scene_Class, switch, icon], :equip => ["EQUIP", :Scene_Equip, 1, 161], :status => ["STATUS", :Scene_Status,0, 236], :order => ["ORDER", :order, 0, 12], # Change only "NAME" :dismiss => ["DISMISS", :dismiss, 0, 187], # Change only "NAME" #:class => ["JOB", :Scene_Class, 0, 121], # Example yanfly class #:item => ["USE ITEM", :Scene_Item, 0, 261], } # don't touch #------------------------------------------------------------------------------- # EXPLANATION: #------------------------------------------------------------------------------- # CMD ID = unique identifier for the menu command (scripting purposes). Use # anything here but do not change :order or :dismiss or those options # will no longer function. You can, however, remove them. # "NAME" = Menu command text # :Scene_Class = The name of the scene class as a symbol # switch = a swith ID. Turn this switch ON to disable the menu command # icon = the icon ID to go with the menu command #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- # # * END OF SETTINGS # #------------------------------------------------------------------------------- end # GARMY #----------------------# #---| Game_Interpreter |---------------------------------------------------- #----------------------# class Game_Interpreter def manage_army; SceneManager.call(Scene_Army); end def a_access(id,status); $game_actors[id].a_accessible = status; end def a_cmd(id,cmd_name,status) $game_actors[id].a_cmds[cmd_name] = status end def a_icon(id,icon_id); $game_actor[id].a_icon = icon_id; end def armyname(name); $game_party.armyname = name; end end # Game_Interpreter #----------------# #---| Game_Party |---------------------------------------------------------- #----------------# class Game_Party attr_accessor :last_atroop attr_accessor :armyname alias galv_garmy_gp_initialize initialize def initialize @armyname = "Unnamed Army" galv_garmy_gp_initialize end end # Game_Party #------------------# #---| SceneManager |-------------------------------------------------------- #------------------# module SceneManager def self.gcall(scene_class) @stack.push(@scene) @scene = Kernel.const_get(scene_class).new end end # SceneManager #----------------------# #---| RPG::CLASS/ACTOR |---------------------------------------------------- #----------------------# class RPG::Class def a_icon if @a_icon.nil? if @note =~ /<a_icon: (.*)>/i @a_icon = $1.to_i else @a_icon = GARMY::NO_CLASS_ICON end end @a_icon end end # RPG::Class class RPG::Actor def a_icon if @a_icon.nil? if @note =~ /<a_icon: (.*)>/i @a_icon = $1.to_i else @a_icon = GARMY::NO_ACTOR_ICON end end @a_icon end end # RPG::Class #----------------# #---| Game_Actor |---------------------------------------------------------- #----------------# class Game_Actor attr_accessor :a_accessible attr_accessor :a_cmds attr_accessor :a_icon alias galv_garmy_ga_setup setup def setup(actor_id) @a_accessible = true @a_icon = $data_actors[actor_id].a_icon @a_cmds = {} GARMY::CMDS.each { |cmd| @a_cmds[cmd[0]] = true } galv_garmy_ga_setup(actor_id) end end # Game_Actor #-----------------# #---| Scene_Army |--------------------------------------------------------- #-----------------# class Scene_Army < Scene_MenuBase def start super create_help_window create_info_window create_troop_window create_command_window create_face_window end #-----| CREATE STUFF | def create_help_window @help_window = Window_ArmyHelp.new @help_window.viewport = @viewport end def create_info_window @info_window = Window_ArmyInfo.new @info_window.viewport = @viewport end def create_troop_window wy = @help_window.height ww = Graphics.width wh = Graphics.height - @help_window.height - @info_window.height @troop_window = Window_Troops.new(0,wy,ww,wh) @troop_window.help_window = @help_window @troop_window.viewport = @viewport @troop_window.activate @troop_window.set_handler(:ok, method(:on_troop_ok)) @troop_window.set_handler(:cancel, method(:return_scene)) end def create_command_window wx = Graphics.width / 2 wy = (Graphics.height - @info_window.height - @help_window.height) / 2 @command_window = Window_ArmyCommand.new(wx,wy) @command_window.viewport = @viewport GARMY::CMDS.each { |cmd| handle = cmd[1][0].delete(' ').downcase.to_sym @command_window.set_handler(handle, method(:cmd)) } @command_window.set_handler(:cancel, method(:back_to_troop)) @command_window.y -= @command_window.height / 2 - @help_window.height @command_window.hide.deactivate end def create_face_window ww = @command_window.width wh = @command_window.height wx = @command_window.x wy = @command_window.y @face_window = Window_ArmyFace.new(wx,wy,ww,wh) @face_window.viewport = @viewport @face_window.hide end #-----| HANDLERS | def cmd list = GARMY::CMDS.to_a cmd = @command_window.index symbol = list[cmd][1][1] if custom_action(symbol) custom_on_command_ok(symbol) else SceneManager.gcall(list[cmd][1][1]) end end def custom_action(symbol) case symbol when :dismiss, :order return true else return false end end def custom_on_command_ok(symbol) case symbol when :dismiss do_dismiss when :order start_ordering end end def start_ordering if $game_party.last_atroop.a_cmds[:order] @troop_window.order_on @ordering = true @troop_window.psound = GARMY::ORDER_SE else Sound.play_buzzer end back_to_troop end def do_dismiss @troop_window.dismiss back_to_troop end def on_troop_ok if @ordering @troop_window.swap_actor @ordering = false back_to_troop else $game_party.last_atroop = actor $game_party.menu_actor = actor @command_window.refresh @face_window.refresh @command_window.show.activate @face_window.show.activate end end def back_to_troop @command_window.hide.deactivate @face_window.hide @troop_window.activate end def return_scene if @troop_window.ordering_on @ordering = false @troop_window.cancel_ordering @troop_window.activate else $game_party.last_atroop = nil SceneManager.return end end #-----| OTHER STUFF | def actor; @troop_window.actor; end def terminate super end def update super end end # Scene_Army < Scene_MenuBase #----------------------# #---| Window_ArmyHelp |---------------------------------------------------- #----------------------# class Window_ArmyHelp < Window_Help def initialize super(1) @icons = [] end def set_text(text) if text != @text @text = text refresh end end def clear set_text("") @icons = [] @actor = nil end def set_item(actor) @actor = actor @icons = [get_icon(GARMY::ICONTYPE1,actor),get_icon(GARMY::ICONTYPE2,actor)] set_text(actor ? create_text(actor) : "") end def create_text(actor) n = actor.name c = actor.class.name l = Vocab::level_a + actor.level.to_s text = n + " - " + l + " " + c return text end def get_icon(icontype,actor) return 0 if !actor case icontype when :actor return actor.a_icon when :class return $data_classes[actor.class_id].a_icon when :weapon if actor.equips[0].nil? return GARMY::NO_WEAPON_ICON else return actor.equips[0].icon_index end else return 0 end end def refresh contents.clear contents.font.size = 21 if Graphics.height < 480 if !@icons.empty? draw_icon(@icons[0], 0, 0) draw_icon(@icons[1], 28, 0) end if @actor offset = Graphics.width >= 640 ? 0 : -100 draw_actor_hp(@actor, 355 + offset, 0) draw_actor_mp(@actor, 490 + offset, 0) draw_text(62, 0, 280 + offset, line_height, @text) end end end # Window_ArmyHelp < Window_Help #--------------------# #---| Window_Troops |------------------------------------------------------ #--------------------# class Window_Troops < Window_Selectable attr_accessor :pending_index attr_accessor :ordering_on attr_accessor :psound def initialize(x, y, width, height) super @data = [] @last_index ||= 0 @animtime = 0 @walk = 0 @pending_index = -1 refresh select_last end #------| Sizes and Stuff | def item_width (width - standard_padding * 2 + spacing) / col_max - spacing end def item_height; item_width; end def spacing; return 10; end def col_max; return 6; end def item_max; @data ? @data.size : 1; end def actor; @data && index >= 0 ? @data[index] : nil; end def current_item_enabled? enable?(@data[index]) end def include?(actor) return false if actor.nil? return true end def enable?(actor) return false if !actor return false if !actor.a_accessible return false if @ordering_on && !actor.a_cmds[:order] return true end def make_item_list @data = $game_party.members.select {|actor| include?(actor) } @data.push(nil) if include?(nil) end def select_last select(@data.index($game_party.last_atroop) || 0) end def swap_actor $game_party.swap_order($game_party.last_atroop.index,index) @pending_index = -1 @ordering_on = nil refresh end def actor_rect(index) rect = Rect.new rect.width = item_width rect.height = item_height rect.x = index % col_max * (item_width + spacing) rect.y = index / col_max * item_height rect end def offset Graphics.height < 480 ? 0 : 10 end def draw_item(index) actor = @data[index] if actor rect = actor_rect(index) rect.width -= 4 draw_in_battle_party(index) if GARMY::B_MEMBERS draw_selected(index) draw_actor_text(actor,rect.x + 2,rect.y + 38 + offset, enable?(actor), rect.width) draw_character(actor.character_name, actor.character_index, rect.x + item_width / GARMY::SPRITE_X_POS - 1, rect.y + 38 + offset, enable?(actor),index) end end def draw_selected(index) if index == @pending_index pendrect = item_rect(index) pendrect.x += 1 pendrect.y += 1 pendrect.width -= 2 pendrect.height -= 2 contents.fill_rect(pendrect, pending_color) end end def draw_in_battle_party(index) if index < $game_party.max_battle_members rect = item_rect(index) w = 1 c = text_color(GARMY::B_MEMBER_COLOR) trect = Rect.new(rect.x,rect.y,rect.width,w) lrect = Rect.new(rect.x,rect.y,w,rect.height) rrect = Rect.new(rect.x + rect.width - w,rect.y,w,rect.height) brect = Rect.new(rect.x,rect.y + rect.height - w,rect.width,w) contents.fill_rect(trect,c) contents.fill_rect(lrect,c) contents.fill_rect(rrect,c) contents.fill_rect(brect,c) end end def square_color end def draw_actor_text(actor, x, y, enabled = true, w) return unless actor icon1 = get_icon(GARMY::ICONTYPE1,actor) icon2 = get_icon(GARMY::ICONTYPE2,actor) draw_icon(icon1, x + 6, y - 20, enabled) draw_icon(icon2, x + 18, y - 20, enabled) change_color(normal_color, enabled) contents.font.size = 18 draw_text(x, y, w, line_height, actor.name,1) contents.font.size = 16 lvl = Vocab::level_a + actor.level.to_s cname = actor.class.name draw_text(x + 10, y - 40, w, line_height, lvl,0) draw_text(x, y + 16, w, line_height, cname,1) end def get_icon(icontype,actor) case icontype when :actor return actor.a_icon when :class return $data_classes[actor.class_id].a_icon when :weapon if actor.equips[0].nil? return GARMY::NO_WEAPON_ICON else return actor.equips[0].icon_index end else return 0 end end def draw_character(character_name, character_index, x, y,enabled,i) return unless character_name bitmap = Cache.character(character_name) sign = character_name[/^[\!\$]./] if sign && sign.include?('$') cw = bitmap.width / 3 ch = bitmap.height / 4 else cw = bitmap.width / 12 ch = bitmap.height / 8 end n = character_index step = 0 step = @walk if enabled && i == index src_rect = Rect.new((n%4*3+1+step)*cw, (n/4*4)*ch, cw, ch) contents.blt(x - cw / 2, y - ch, bitmap, src_rect, enabled ? 255 : 150) end def update_help @help_window.set_item(actor) end def refresh make_item_list create_contents draw_all_items end def order_on @ordering_on = true @pending_index = index refresh end def cancel_ordering @ordering_on = nil @pending_index = -1 refresh end def dismiss $game_party.remove_actor(actor.id) refresh end def update super update_walk redraw_item(index) end def update_walk @animtime += 1 if @animtime == 10 case @walk when 1; @walk -= 1 when -1; @walk += 1 when 0 if @step == 1 @walk = -1; @step = 0 else @walk = 1; @step = 1 end end @animtime = 0 end end def cursor_down(wrap = false); super; cursor_move_extras; end def cursor_up(wrap = false); super; cursor_move_extras; end def cursor_left(wrap = false); super; cursor_move_extras; end def cursor_right(wrap = false); super; cursor_move_extras; end def cursor_move_extras @walk = 0 @animtime = 0 redraw_item(@last_index) @last_index = index end def process_ok if current_item_enabled? psound Input.update deactivate call_ok_handler else Sound.play_buzzer end end def psound if @psound.nil? Sound.play_ok else name,vol,pitch = @psound RPG::SE.new(name,vol,pitch).play @psound = nil end end end # Window_Troops < Window_Selectable #------------------------# #---| Window_ArmyCommand |-------------------------------------------------- #------------------------# class Window_ArmyCommand < Window_Command def initialize(x,y) super(x,y) self.opacity = 255 self.back_opacity = 255 end def window_width; return 160; end def visible_line_number; item_max; end def make_command_list @cmd_index = [] GARMY::CMDS.each { |cmd| text = cmd[1][0] handle = text.delete(' ').downcase.to_sym add_command(text,handle,check_enabled($game_switches[cmd[1][2]],cmd[0],text)) @cmd_index << cmd[0] } end def check_enabled(switch,cmd,text) return false if switch return false if cmd == :dismiss && $game_party.members.count <= 1 if $game_party.last_atroop return false if !$game_party.last_atroop.a_cmds[cmd] end return true end def draw_item(index) change_color(normal_color, command_enabled?(index)) recti = item_rect_for_text(index) recti.x += 26 draw_text(recti, command_name(index), alignment) draw_icon(GARMY::CMDS[@cmd_index[index]][3],0,recti.y) end def process_ok if current_item_enabled? psound Input.update deactivate call_ok_handler else Sound.play_buzzer end end def psound if current_symbol == :dismiss name,vol,pitch = GARMY::DISMISS_SE RPG::SE.new(name,vol,pitch).play @psound = nil else Sound.play_ok end end end # Window_ArmyCommand < Window_Command #---------------------# #---| Window_ArmyInfo |----------------------------------------------------- #---------------------# class Window_ArmyInfo < Window_Base def initialize(line_number = 2) super(0, Graphics.height - window_height, Graphics.width, window_height) refresh end def window_height h = h480? ? 30 : 0 fitting_height(3) + h end def h480?; Graphics.height >= 480; end def setup_info w = contents.width o = h480? ? 18 : 0 h = line_height y = line_height + o y2 = h * 2 + o * 1.4 contents.font.size = 21 if !h480? change_color(system_color) draw_text(0,0,contents.width,line_height,$game_party.armyname,1) change_color(normal_color) draw_horz_line(h - 4) if h480? draw_text(0,y,w,h,GARMY::UNIT_COUNT + $game_party.members.count.to_s,0) draw_text(0,y,w,h,GARMY::HIGH_LEVEL + highlevel,1) draw_text(0,y,w,h,GARMY::TIME + time_text,2) draw_text(0,y2,w,h,GARMY::FUNDS + $game_party.gold.to_s + currency,0) if GARMY::INFOVAR1 > 0 v = GARMY::INFOVAR1 n = $data_system.variables[v] draw_text(0,y2,w,h,n + $game_variables[v].to_s,1) end if GARMY::INFOVAR2 > 0 v = GARMY::INFOVAR2 n = $data_system.variables[v] draw_text(0,y2,w,h,n + $game_variables[v].to_s,2) end end def currency; Vocab::currency_unit; end def highlevel ($game_party.members.max_by { |k,v| k.level }).level.to_s end def time_text sprintf("%02d:%02d:%02d", (Graphics.frame_count / 60**2) / 60, Graphics.frame_count / 60**2 % 60, Graphics.frame_count / 60 % 60) end def draw_horz_line(y) line_y = y + line_height / 2 - 1 contents.fill_rect(0, line_y, contents_width, 2, line_color) end def line_color color = normal_color color.alpha = 48 color end def update refresh end def refresh contents.clear setup_info end end # Window_ArmyInfo < Window_Base #---------------------# #---| Window_ArmyFace |----------------------------------------------------- #---------------------# class Window_ArmyFace < Window_Base def initialize(x,y,w,h) super(x - w,y,w,h) self.opacity = 255 self.back_opacity = 255 end def draw_cont fy = (contents.height - 96) / 2 fx = (contents.width - 96) / 2 draw_actor_face($game_party.last_atroop, fx, fy) end def refresh contents.clear draw_cont end end # Window_ArmyFace < Window_Base
Démo: http://www.mediafire.com/?6mczyzwm8dye9sx |
|