-20%
Le deal à ne pas rater :
-20% Récupérateur à eau mural 300 litres (Anthracite)
79 € 99 €
Voir le deal

Aller en bas
Spytje
Spytje
Administrateur

Nombre de messages : 5935
Localisation : La terre
Distinction : Spiraliste [Korn']
Forestia : Projet du mois juillet 2014
Papy Pulkigrat [Yama']
Date d'inscription : 16/03/2008

Résolu Modification script (résolu)

Mer 5 Juin 2013 - 17:32

J'aurais besoin d'un scripteur pour me modifier une chose dans un script.


Dans mon projet j'utilise ce script pour faire apparaître dans une fenêtre les loot après avoir tué un ennemi.
J'aimerais que lorsque le joueur sélectionne le sac, qui apparaît sur le sol après la mort d'un ennemi, se vide automatiquement dans l'inventaire et referme la fenêtre de loot.

Voici le script en question :


Code:
#------------------------------------------------------------------------------#
#  Galv's Multiple Storage Containers
#------------------------------------------------------------------------------#
#  For: RPGMAKER VX ACE
#  Version 1.2
#------------------------------------------------------------------------------#
#  Script calls to use:
#------------------------------------------------------------------------------#
#
#  open_container                                    # Opens event container
#
#  c_add(type, item_id, amount, event_id, map_id)    # Adds item to container.
#
#  c_rem(type, item_id, amount, event_id, map_id)    # removes item from container
#
#  c_count(type, id, event_id, map_id)               # counts certain item in
#                                                    # container. Use in condition
#                                                    # branches and variables.
#  
#------------------------------------------------------------------------------#
#  EXPLAINATION:
#  type      this can be "weapon", "armor" or "item"
#  item_id   the ID of the item/armor/weapon you want to add
#  amount    the number of the item/armor/weapon/gold you want to remove
#  event_id  the event ID of the container you want to add items to. Set this
#            to 0 to add an item to the event the script call is in.
#  map_id    the ID of the map the container you want is on. Make this 0 if you
#            want to refer to the same map as the script call was made.
#
#  EXAMPLE OF USE:
#  c_add("item",2,3,5,4)         # adds an item to event 5 on map 4
#  c_add("weapon",2,3,0,0)       # adds a weapon to the same event as the call
#  c_rem("armor",3,6,10,2)       # removes armor from event 10 on map 2
#  c_count("item",1,5,1)         # counts item ID 1 stored in event 5 on map 1
#------------------------------------------------------------------------------#

#------------------------------------------------------------------------------#
#  Recommend downloading the demo to see how to set up container events.
#  More setup options further down.
#------------------------------------------------------------------------------#

$imported = {} if $imported.nil?
$imported["Item_Containers"] = true

module Container

#------------------------------------------------------------------------------#
#  SCRIPT SETUP OPTIONS
#------------------------------------------------------------------------------#
  
  # PARTY LIMITS
  # NOTE: These limits set to 0 will use the default limits. In theory this will
  # be compatible with a limit breaker script by leaving them at 0. Or you can
  # set the party limits below to whatever you like.
  

  MAX_ITEMS = 0                   # Max items your PARTY can carry.
                                 # This will overwrite the default limit.
                                  # 0 means do not use this.


#------------------------------------------------------------------------------#
#  SCRIPT SETUP OPTIONS
#------------------------------------------------------------------------------#

end


class Game_Temp
  attr_accessor :contents
  attr_accessor :container_name
  alias galv_container_initialize initialize
  
  def initialize
    galv_container_initialize
    @contents = []
    @container_name = ""
  end
  
  def contents
    @contents
  end
  
  def container_name
    @container_name
  end
  
end # Game_Temp


class Scene_Container < Scene_Map
  def start
    super
    check_storage_exists
    create_background_loot
    create_number_window
    create_take_window
    activate_take_window
    @take_window.show
    @take_window.refresh
  end

  def check_storage_exists
    if $game_party.container[$game_temp.contents].nil?
      $game_party.container[$game_temp.contents] = {}
    end
  end
  
#--------------------------------------------------------------------------
# ● AFFICHAGE IMAGE DANS LE MENU
#--------------------------------------------------------------------------
  
def create_background_loot
    Audio.se_play("", 100, 100)
    @background_sprite = Sprite.new
  end
  

  #--------------------------------------------------------------------------
  # Create Windows
  #--------------------------------------------------------------------------

  def create_number_window
    @number_window = Window_ContainerNumber.new(170, 230, 50)
    @number_window.viewport = @viewport
    @number_window.hide
    @number_window.set_handler(:ok,     method(:on_number_ok))
    @number_window.set_handler(:cancel, method(:on_number_cancel))
  end
  
  def create_take_window
    @take_window = Window_ContainerTake.new(10, 20, 220, 150)
    @take_window.viewport = @viewport
    @take_window.help_window = @help_window
    @take_window.set_handler(:ok,     method(:on_take_ok))
  end

  #--------------------------------------------------------------------------
  # * Activate Windows
  #--------------------------------------------------------------------------
  
  def activate_take_window
     @take_window.select(0)
     @take_window.refresh
     @take_window.show.activate
  end

  #--------------------------------------------------------------------------
  # HANDLER METHODS
  #--------------------------------------------------------------------------
  
  def on_take_ok
    @item = @take_window.item
    if @item.nil? || $game_party.container[$game_temp.contents].empty? || $game_party.item_number(@item) == $game_party.max_item_number(@item)
      @take_window.activate
      @take_window.refresh
      return
    elsif
      @item = @take_window.item
      @number_window.set(@item, max_take)
      @number_window.show.activate
    end
  end
  
  def on_number_ok
    do_take(@number_window.number)
    end_number_input
  end
  
  def on_number_cancel
    end_number_input
  end
  
  def end_number_input
    Audio.se_play("", 100, 100)
    @number_window.hide
    activate_take_window
  end  


  #--------------------------------------------------------------------------
  # * Taking methods
  #--------------------------------------------------------------------------
  def max_take
    if $game_party.container[$game_temp.contents][@item] > $game_party.max_item_number(@item) - $game_party.item_number(@item)
      $game_party.max_item_number(@item) - $game_party.item_number(@item)
    else
      $game_party.container[$game_temp.contents][@item]
    end
  end
  
  def do_take(number)
    return if @item.nil?
    $game_party.gain_item(@item, number)
    $game_party.container[$game_temp.contents][@item] -= number
    $game_party.container[$game_temp.contents].delete(@item) if $game_party.container[$game_temp.contents][@item] <= 0
    if $game_party.container[$game_temp.contents].empty?
      @take_window.activate
    end
  end

end # Scene_Container < Scene_MenuBase

#------------------------------------------------------------------------------#
#  Window Stored Items
#------------------------------------------------------------------------------#

class Window_StoreList < Window_Selectable
  def initialize(x, y, width, height)
    super
    @category = :none
    @data = []
  end
  
  def category=(category)
    return if @category == category
    @category = category
    refresh
    self.oy = 0
  end
  
  def col_max
    return 1
  end
  
  def item_max
    @data ? @data.size : 1
  end
  
  def item
    @data && index >= 0 ? @data[index] : nil
  end
  
  def current_item_enabled?
    enable?(@data[index])
  end
  
  def include?(item)
    case @category
    when :item
      item.is_a?(RPG::Item) && !item.key_item?
    when :weapon
      item.is_a?(RPG::Weapon)
    when :armor
      item.is_a?(RPG::Armor)
    when :key_item
      item.is_a?(RPG::Item) && item.key_item?
    else
      false
    end
  end
  
  def enable?(item)
    $game_party.container[$game_temp.contents].has_key?(item)
  end
  
  def make_item_list
    @data = $game_party.container[$game_temp.contents].keys {|item| include?(item) }
    @data.push(nil) if include?(nil)
  end
  
  def select_last
    select(@data.index($game_party.last_item.object) || 0)
  end
  
  def draw_item(index)
    item = @data[index]
    if item
      rect = item_rect(index)
      rect.width -= 4
      draw_item_name(item, rect.x, rect.y, enable?(item))
      draw_item_number(rect, item)
    end
  end
  
  def draw_item_number(rect, item)
    draw_text(rect, sprintf(":%2d", $game_party.container[$game_temp.contents][item]), 2)
  end
  
  def refresh
    make_item_list
    create_contents
    draw_all_items
  end
end # Window_StoreList < Window_Selectable


#------------------------------------------------------------------------------#
#  Window Stored Item amount
#------------------------------------------------------------------------------#

class Window_ContainerNumber < Window_Selectable
  attr_reader :number
  def initialize(x, y, height)
    super(x, y, window_width, height)
    @item = nil
    @max = 1
    @number = 1
  end
  
  def window_width
    return 250
  end
  
  def set(item, max)
    @item = item
    @max = max
    @number = 1
    refresh
  end
  
  def refresh
    contents.clear
    draw_item_name(@item, 0, item_y)
    draw_number
  end
  
  def draw_number
    change_color(normal_color)
    draw_text(cursor_x, item_y, cursor_width - 4, line_height, @number, 2)
  end
  
  def item_y
    contents_height = 0
  end
  
  def cursor_width
    figures * 10 + 12
  end
  
  def cursor_x
    contents_width - cursor_width - 4
  end
  
  def figures
    return 2
  end
  
  def update
    super
    if active
      last_number = @number
      update_number
      if @number != last_number
        Sound.play_cursor
        refresh
      end
    end
  end
  
  def update_number
    change_number(1)   if Input.repeat?(:RIGHT)
    change_number(-1)  if Input.repeat?(:LEFT)
  end
  
  def change_number(amount)
    @number = [[@number + amount, @max].min, 1].max
  end
  
  def update_cursor
    cursor_rect.set(cursor_x, item_y, cursor_width, line_height)
  end
  
end # Window_ContainerNumber < Window_Selectable

#------------------------------------------------------------------------------#
#  Window Take Item
#------------------------------------------------------------------------------#

class Window_ContainerTake < Window_StoreList
  def initialize(x, y, width, height)
    super(x, y, width, height)
  end
  
  def current_item_enabled?
    enable?(@data[index])
  end
  
  def enable?(item)
    $game_party.container[$game_temp.contents][item] != 0 && $game_party.item_number(item) < $game_party.max_item_number(@item)
  end
end

#------------------------------------------------------------------------------#
#  Game Party Additions
#------------------------------------------------------------------------------#

class Game_Party < Game_Unit
  attr_accessor :container

  
  alias galv_container_init_all_items init_all_items
  def init_all_items
    galv_container_init_all_items
    @storage = {}
    @stored_items = {}
    @stored_weapons = {}
    @stored_armors = {}
  end
  
  def container
    @storage
  end

  def storage
    @stored_items
    @stored_weapons
    @stored_armors
  end
  
 
 alias galv_container_max_item_number max_item_number
  def max_item_number(item)
    return Container::MAX_ITEMS if Container::MAX_ITEMS > 0
    return 99 if item.nil?
    galv_container_max_item_number(item)
    
  end
  
end # Game_Party < Game_Unit


class Game_Interpreter

  def c_add(type, id, amount, event_id, map_id)
    if event_id <= 0
      add_where = @event_id
    else
      add_where = event_id
    end
    if map_id <= 0
      add_where_map = $game_map.map_id
    else
      add_where_map = map_id
    end
    $game_temp.contents = [add_where, add_where_map]
    if $game_party.container[$game_temp.contents].nil?
      $game_party.container[$game_temp.contents] = {}
    end
    case type
    when "weapon"
      @item = $data_weapons[id]
    when "item"
      @item = $data_items[id]
    when "armor"
      @item = $data_armors[id]
    end
    if $game_party.container[$game_temp.contents][@item].nil?
      $game_party.container[$game_temp.contents][@item] = amount
    else
      $game_party.container[$game_temp.contents][@item] += amount
    end
  end

  def c_rem(type, id, amount, event_id, map_id)
    if event_id <= 0
      rem_where = @event_id
    else
      rem_where = event_id
    end
    if map_id <= 0
      rem_where_map = $game_map.map_id
    else
      rem_where_map = map_id
    end
    $game_temp.contents = [rem_where, rem_where_map]
    if $game_party.container[$game_temp.contents].nil?
      $game_party.container[$game_temp.contents] = {}
    end
    case type
    when "weapon"
      @item = $data_weapons[id]
    when "item"
      @item = $data_items[id]
    when "armor"
      @item = $data_armors[id]
    end
    return if $game_party.container[$game_temp.contents][@item].nil?
    if $game_party.container[$game_temp.contents][@item] <= amount
      $game_party.container[$game_temp.contents].delete(@item)
    else
      $game_party.container[$game_temp.contents][@item] -= amount
    end
  end
  
  def c_count(type, id, event_id, map_id)
    if event_id <= 0
      container_id = @event_id
    else
      container_id = event_id
    end
    if map_id <= 0
      container_id_map = $game_map.map_id
    else
      container_id_map = map_id
    end
    $game_temp.contents = [container_id, container_id_map]
    if $game_party.container[$game_temp.contents].nil?
      $game_party.container[$game_temp.contents] = {}
    end
    case type
    when "weapon"
      @item = $data_weapons[id]
    when "item"
      @item = $data_items[id]
    when "armor"
      @item = $data_armors[id]
    end
    return 0 if $game_party.container[$game_temp.contents][@item].nil?
    $game_party.container[$game_temp.contents][@item]
  end
  
  def open_container
    $game_temp.contents = [@event_id, $game_map.map_id]
    $game_temp.container_name = @list[0].parameters[0]
    SceneManager.call(Scene_Container)
  end
end # Game_Interpreter

Merci d'avance à celui qui pourra m'aider Smile


Dernière édition par spywaretof le Mer 10 Juil 2013 - 18:14, édité 1 fois
Dishi
Dishi
Membre

Nombre de messages : 632
Age : 25
Localisation : Marseille
Distinction : Alias Dichie
Aussi alias Sherifa Luna de la commu' (je suis dichie et d'ailleurs )

Co-créateur du Nyan Xak
[Tétété]

Apprenti Pedobear
[Mémé nova]

Keupiteur de ponctuation.
[un sombre inconnu.]
Date d'inscription : 07/07/2011
https://github.com/paul-roman

Résolu Re: Modification script (résolu)

Mer 5 Juin 2013 - 17:43
J'ai essayé le script sur un projet vide, il se passe rien. Normal ?
Spytje
Spytje
Administrateur

Nombre de messages : 5935
Localisation : La terre
Distinction : Spiraliste [Korn']
Forestia : Projet du mois juillet 2014
Papy Pulkigrat [Yama']
Date d'inscription : 16/03/2008

Résolu Re: Modification script (résolu)

Mer 5 Juin 2013 - 17:48
Oui il sort tout droit de mon projet et est modifié pour fonctionner avec celui-ci.

J'ai déjà réussis à modifier, pour que la fenêtre se ferme juste après avoir sélèctionné les loots dans la fenêtre avec un update :

Code:
def update
    super
    if $game_party.container[$game_temp.contents].empty?
        SceneManager.goto(Scene_Map)
    end
  end

Il faut maintenant que je trouve comment faire pour que le loot se passe automatiquement.

Donc que le "container" se vide automatiquement dans l'inventaire, si quelqu'un a une idée...

...
Bencoco
Bencoco
Membre

Nombre de messages : 31
Age : 33
Localisation : Alsace
Distinction : aucune
Date d'inscription : 04/03/2012

Résolu Re: Modification script (résolu)

Mar 11 Juin 2013 - 12:55
Salut !

ligne 131 à 136 tu as :

Code:
  def create_take_window
    @take_window = Window_ContainerTake.new(10, 20, 220, 150)
    @take_window.viewport = @viewport
    @take_window.help_window = @help_window
    @take_window.set_handler(:ok,    method(:on_take_ok))
  end
la dernière ligne gère le fait que l'on prenne des item (à ce que j'ai compris)

si tu remplace

Code:
@take_window.set_handler(:ok,    method(:on_take_ok))

par :

Code:
@take_window.on_take_ok

les objets devraient être automatiquement ajoutés à ton inventaire

à tester... tiens moi au courant Smile
Spytje
Spytje
Administrateur

Nombre de messages : 5935
Localisation : La terre
Distinction : Spiraliste [Korn']
Forestia : Projet du mois juillet 2014
Papy Pulkigrat [Yama']
Date d'inscription : 16/03/2008

Résolu Re: Modification script (résolu)

Mar 11 Juin 2013 - 13:59
Ca ne fonctionne pas il me semble que j'avais aussi testé un truc dans le genre.

Merci quand même Smile
Bencoco
Bencoco
Membre

Nombre de messages : 31
Age : 33
Localisation : Alsace
Distinction : aucune
Date d'inscription : 04/03/2012

Résolu Re: Modification script (résolu)

Mar 11 Juin 2013 - 17:13
ok en tout cas la partie qui gère l'ajout des objets dans le menu objet est contenue dans  le on_take_ok

il faut chercher de ce coté à mon avis


Dernière édition par Bencoco le Sam 13 Juil 2013 - 9:21, édité 1 fois
Spytje
Spytje
Administrateur

Nombre de messages : 5935
Localisation : La terre
Distinction : Spiraliste [Korn']
Forestia : Projet du mois juillet 2014
Papy Pulkigrat [Yama']
Date d'inscription : 16/03/2008

Résolu Re: Modification script (résolu)

Mar 11 Juin 2013 - 17:15
Ok c'est bien ce que je pensais, je vais encore chercher, si quelqu'un à une solution je suis preneur.
Spytje
Spytje
Administrateur

Nombre de messages : 5935
Localisation : La terre
Distinction : Spiraliste [Korn']
Forestia : Projet du mois juillet 2014
Papy Pulkigrat [Yama']
Date d'inscription : 16/03/2008

Résolu Re: Modification script (résolu)

Mer 10 Juil 2013 - 17:45
Petit up Smile

Personne n'a d'idée ?
Contenu sponsorisé

Résolu Re: Modification script (résolu)

Revenir en haut
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum