Le Deal du moment : -15%
(Adhérents Fnac) LEGO® Star Wars™ ...
Voir le deal
552.49 €

Aller en bas
Nérylis
Nérylis
Membre

Nombre de messages : 615
Age : 35
Localisation : Seine Maritime
Distinction : aucune
Date d'inscription : 23/11/2014

Résolu Problème de condition sur un script

Dim 21 Fév 2016 - 13:50
Re coucou,

Je fais encore appel à vous pour m'aider à faire une condition sur un script. J'utilise le script de Selchar pour donner de l'expérience à mes équipements. J'utilise également une interface pour vérifier les points d'expérience et les bonus accordés.

Mon souci se trouve pour modifier l'affichage dans mon interface lorsque l'équipement a atteint le level max. Je n'arrive pas à bien formuler la condition. J'ai essayé en mettant "if @level == 5" pour tester mais ça ne marche pas.

Je vous mets les deux scripts (la base et l'interface) ci-dessous :

Code:
#===============================================================================
# Script: Instance Equip Leveling Base 0 Ver. 1.05
# Author: Selchar
# Credit: Tsukihime
# Required: Tsukihime's Item Instance
#===============================================================================
=begin
This script provides common methods required for Equipment Levels.  It does
nothing on it's own and requires another script to initiate the leveling
process.  Feel free to look at what is provided.  For scripters, to change
an equip's level in whatever script you may make, simply call the equip's
level_up/down method.

This Base has your equip's levels start at 0.

#-------------------------------------------------------------------------------
# Weapon/Armor Notetag
#-------------------------------------------------------------------------------
<can level>
Sets where a piece of equipment can level or not.  See Default_Can_Level below.

<max level: x>
Where x is how high you wish for weapon to be able to get to.

<static level param: x>
Where param is the name of a parameter, from mhp/mmp/atk/def/mat/mdf/agi/luk
and x is an integer indicating how much said param will change at level up.

<mult level param: x>
Where param is the same as above, and x is a decimal number that will be used
to determine how much said param changes.  Default setting is down  below.

<static level price: x>
Same as <static level param: x> except for price

<mult level price: x>
Same as <mult level param: x> except for price
=end
module TH_Instance
  module Equip
    #Set this to the default maximum level of your choice.
    Default_Max_Level = 5
    
    #Change this to how you wish for your weapon's level to be shown.
    #'+' will show it as 'Name+1', while 'LV ' will show as 'Name LV 1'
    Level_Prefix = ''
    
    #Default Multipler bonus
    Default_Mult_Bonus = 1.00
    #Mult bonus for price
    Default_Mult_Price = 1.10
    
    #Determines the default availability of an equip's ability to level.
    #The <can level> notetag will always do the opposite
    Default_Can_Level = true
#===============================================================================
# Rest of the Script
#===============================================================================
    def self.static_lvl_stat_regex(param_id)
      /<static[-_ ]?level[-_ ]?#{Selchar::Param[param_id]}:\s*(.*)\s*>/i
    end
    def self.mult_lvl_stat_regex(param_id)
      /<mult[-_ ]?level[-_ ]?#{Selchar::Param[param_id]}:\s*(.*)\s*>/i
    end
    Price_Static_Regex = /<static[-_ ]?level[-_ ]?price:\s*(.*)\s*>/i
    Price_Mult_Regex = /<mult[-_ ]?level[-_ ]?price:\s*(.*)\s*>/i
  end
end
#===============================================================================
# Rest of the Script
#===============================================================================
module Selchar
  Param = ['mhp','mmp','atk','def','mat','mdf','agi','luk','mtp']
end
$imported = {} if $imported.nil?
$imported[:Sel_Equip_Leveling_Base] = true
unless $imported["TH_InstanceItems"]
  msgbox("Tsukihime's Instance not detected, exiting")
  exit
end
#===============================================================================
# Equip Methods
#===============================================================================
class RPG::EquipItem
  attr_accessor :level
  def level
    @level ||= 0
  end
  
  #Call this to increase an equip's level
  def level_up
    return unless can_level
    return if @level == @max_level
    @level += 1
    level_update
  end
  #Call this to decrease an equip's level
  def level_down
    return if @level.zero?
    @level -= 1
    level_update
  end
  #Unnecessary?
  def level_update
    refresh
  end
#===============================================================================
# Renaming/Param/Price Adjusting
#===============================================================================
  def apply_level_suffix(name)
    name += TH_Instance::Equip::Level_Prefix % [@level]
  end
  alias :sel_equip_levels_make_name :make_name
  def make_name(name)
    name = sel_equip_levels_make_name(name)
    name = apply_level_suffix(name) if can_level && level > 0
    name
  end
  
  def apply_level_params(params)
    @level.times do
      (0..7).each do |i|
        params[i] = (params[i] * instance_mult_lvl_bonus(i)).to_i
        params[i] += instance_static_lvl_bonus(i)
      end
    end
    return params
  end
  alias :sel_equip_levels_make_params :make_params
  def make_params(params)
    params = sel_equip_levels_make_params(params)
    params = apply_level_params(params) if can_level && @level > 0
    params
  end

  alias :sel_equip_levels_make_price :make_price
  def make_price(price)
    price = sel_equip_levels_make_price(price)
    price = apply_level_price(price) if can_level && @level > 0
    price
  end
  
  def apply_level_price(price)
    @level.times do
      price = (price * instance_mult_price_mod).to_i
      price += instance_static_price_mod
    end
    price
  end
#===============================================================================
# Equip Notetag
#===============================================================================
  def max_level
    @note =~ /<max[-_ ]?level:\s*(.*)\s*>/i ? @max_level = $1.to_i : @max_level = TH_Instance::Equip::Default_Max_Level if @max_level.nil?
    @max_level
  end
  
  def can_level
    if @can_level.nil?
      cl = TH_Instance::Equip::Default_Can_Level
      @note =~ /<can[-_ ]?level>/i ? @can_level = !cl : @can_level = cl
    end
    @can_level
  end
  
  def instance_static_lvl_bonus(param_id)
    if @instance_static_lvl_bonus.nil?
      @instance_static_lvl_bonus = []
      (0..8).each do |i|
        if @note =~ TH_Instance::Equip.static_lvl_stat_regex(i)
          @instance_static_lvl_bonus[i] = $1.to_i
        else
          @instance_static_lvl_bonus[i] = 0
        end
      end
    end
    @instance_static_lvl_bonus[param_id]
  end
  
  def instance_mult_lvl_bonus(param_id)
    if @instance_mult_lvl_bonus.nil?
      @instance_mult_lvl_bonus = []
      (0..8).each do |i|
        if @note =~ TH_Instance::Equip.mult_lvl_stat_regex(i)
          @instance_mult_lvl_bonus[i] = $1.to_f
        else
          @instance_mult_lvl_bonus[i] = TH_Instance::Equip::Default_Mult_Bonus
        end
      end
    end
    @instance_mult_lvl_bonus[param_id]
  end
  
  def instance_static_price_mod
    @note =~ TH_Instance::Equip::Price_Static_Regex ? @instance_static_price_mod = $1.to_i : @instance_static_price_mod = 0 if @instance_static_price_mod.nil?
    @instance_static_price_mod
  end
  
  def instance_mult_price_mod
    @note =~ TH_Instance::Equip::Price_Mult_Regex ? @instance_mult_price_mod = $1.to_f : @instance_mult_price_mod = TH_Instance::Equip::Default_Mult_Price if @instance_mult_price_mod.nil?
    @instance_mult_price_mod
  end
end
#===============================================================================
# Instance Manager: setup_instance
#===============================================================================
module InstanceManager
  class << self
    alias :instance_equip_level_setup :setup_equip_instance
  end
  
  def self.setup_equip_instance(obj)
    obj.level = 0
    obj.max_level
    instance_equip_level_setup(obj)
  end
end
#===============================================================================
# End of File
#===============================================================================


Code:
#Modif class Scene_Equip
class Scene_Equip < Scene_MenuBase
  
  #Modification de l'update
  alias update_interface update
  def update
    update_interface
    if Input.trigger?(:SHIFT)
      return if !@item_window.active && !@slot_window.active && @status_window.menu == 0
      if @item_window.item != nil && !@slot_window.active && @item_window.visible
        if @status_window.menu == 0
          Sound.play_cursor
        else
          Sound.play_cancel
        end
        switch_info
      end
      if @slot_window.visible && @slot_window.item != nil
        if @status_window.menu == 0
          Sound.play_cursor
        else
          Sound.play_cancel
        end
        switch_info
      end
    elsif Input.trigger?(:UP) && @status_window.menu == 1
      Sound.play_cursor
      @status_window.ligne_actuel -= 1
      @status_window.refresh(@status_window.item_actuel)
    elsif Input.trigger?(:DOWN) && @status_window.menu == 1
      Sound.play_cursor
      @status_window.ligne_actuel += 1
      @status_window.refresh(@status_window.item_actuel)
    elsif Input.trigger?(:B) && @status_window.menu == 1
      Sound.play_cancel
      switch_info
    end
  end
  
  #Switch vers le menu info
  def switch_info
    if @status_window.menu == 1
      @status_window.menu = 0
      @status_window.ligne_actuel = 0
      @item_window.activate if @item_window.visible
      @slot_window.activate if @slot_window.visible
      item = nil
    else
      @status_window.menu = 1
      if @item_window.visible
        @item_window.deactivate
        item = @item_window.item
      elsif @slot_window.visible
        @slot_window.deactivate
        item = @actor.equips[@slot_window.index]
      end
    end
    @status_window.refresh(item)
  end
  
end
#Modif Window_EquipStatus
class Window_EquipStatus < Window_Base
  
  attr_accessor :menu #Ajout de la variable menu
  attr_reader :ligne_actuel #Ajout de la variable ligne actuel
  
  #Modification Initialisation
  alias initialize_interface initialize
  def initialize(*args)
    @menu = 0
    @ligne_actuel = 0
    initialize_interface(*args)
  end
  
  #Modification de la ligne actuel
  def ligne_actuel=(value)
    @ligne_actuel = [0,[value,@max_ligne-8].min].max
  end
  
  #Modifiication du refresh
  alias refresh_interface refresh
  def refresh(item = nil)
    if @menu == 0
      refresh_interface
    else
      contents.clear
      draw_interface(item)
    end
  end
  
  #Récuperation de l'item_actuel
  def item_actuel
    return @item
  end
  
  #Creation de la fenetre d'info
  def draw_interface(item)
    if item == nil
      draw_text_ex(0, 0, "")
      @max_ligne = 0
      @item = nil
    else
      @max_ligne = 0
      @item = item
#~       draw_icon(item.icon_index , 0, -@ligne_actuel*24)
#~       contents.font.color = item.rarity_colour
#~       contents.draw_text(24, -88-@ligne_actuel*24, contents.width, contents.height, item.name)
      contents.font.color = system_color
      contents.draw_text(0, -88-@ligne_actuel*24, contents.width, contents.height, "Niveau :")
      contents.font.color = normal_color
      contents.draw_text(0, -64-@ligne_actuel*24, contents.width, contents.height, item.level.to_s + " / " + item.max_level.to_s)
      contents.font.color = system_color
      contents.draw_text(0, -40-@ligne_actuel*24, contents.width, contents.height, "Expérience :")
      if @level == 5
        contents.font.color = normal_color
        contents.draw_text(0, -16-@ligne_actuel*24, contents.width, contents.height, "-")
      else
        contents.font.color = normal_color
        contents.draw_text(0, -16-@ligne_actuel*24, contents.width, contents.height, item.exp.to_s)
        contents.font.color = normal_color
        contents.draw_text(0, 8-@ligne_actuel*24, contents.width, contents.height, item.exp_to_level.to_s)
      end
      contents.font.color = system_color
      contents.draw_text(0, 32-@ligne_actuel*24, contents.width, contents.height, "Prochains bonus :")
      if @level == 5
        contents.draw_text(0, 56-@ligne_actuel*24, contents.width, contents.height, "-")
      else
        @max_ligne = 6
        j = 0
        for i in 0..7
          if item.instance_mult_lvl_bonus(i) != 1 || item.instance_static_lvl_bonus(i) != 0
            next_value = item.params[i]*item.instance_mult_lvl_bonus(i)+item.instance_static_lvl_bonus(i)
            contents.font.color = normal_color
            contents.draw_text(0 , 56+j*48-@ligne_actuel*24, contents.width, contents.height, Vocab.param(i))
            contents.font.color = normal_color
            contents.draw_text(0 , 80+j*48-@ligne_actuel*24, contents.width, contents.height, item.params[i].to_s+" passe à "+next_value.floor.to_s)
            j += 1
            @max_ligne += 2
          end
        end
      end
    end
  end
  
end


Dernière édition par Nérylis le Lun 22 Fév 2016 - 21:03, édité 1 fois
tonyryu
tonyryu
Membre

Nombre de messages : 902
Age : 43
Localisation : Près de Nantes
Distinction : aucune
Date d'inscription : 27/05/2010
http://www.tonyryudev.com

Résolu Re: Problème de condition sur un script

Dim 21 Fév 2016 - 14:40
Je regarde ça également ce soir en récupérant ton projet. Tu vas m'en devoir une bonne!! ^_^
tonyryu
tonyryu
Membre

Nombre de messages : 902
Age : 43
Localisation : Près de Nantes
Distinction : aucune
Date d'inscription : 27/05/2010
http://www.tonyryudev.com

Résolu Re: Problème de condition sur un script

Dim 21 Fév 2016 - 23:04
Tu peux mettre à jour avec la modification que j'ai apporté sur l'autre topic. Voir reuploder le projet avec les dernières modifications, plus facile pour reproduire le problème et le corriger.
Nérylis
Nérylis
Membre

Nombre de messages : 615
Age : 35
Localisation : Seine Maritime
Distinction : aucune
Date d'inscription : 23/11/2014

Résolu Re: Problème de condition sur un script

Lun 22 Fév 2016 - 18:30
Voici la démo à jour : http://www.mediafire.com/download/b4wozyau96uhb49/Ace+menu4.exe

Au passage, si tu peux regarder également pour le petit problème évoqué dans ce topic http://rpgmakervx.1fr1.net/t19547-probleme-de-son-dans-un-menu
tonyryu
tonyryu
Membre

Nombre de messages : 902
Age : 43
Localisation : Près de Nantes
Distinction : aucune
Date d'inscription : 27/05/2010
http://www.tonyryudev.com

Résolu Re: Problème de condition sur un script

Lun 22 Fév 2016 - 20:12
Tu veux faire quoi en fait?

Modifier cela :
Code:
      contents.draw_text(0, 24, contents.width, 24, item.level.to_s + " / " + item.max_level.to_s)

pour que quant l'item est level max, écrire autre chose?

Code:
      if item.level != item.max_level
        contents.draw_text(0, 24, contents.width, 24, item.level.to_s + " / " + item.max_level.to_s)
      else
        contents.draw_text(0, 24, contents.width, 24, "-- Max --")
      end
Nérylis
Nérylis
Membre

Nombre de messages : 615
Age : 35
Localisation : Seine Maritime
Distinction : aucune
Date d'inscription : 23/11/2014

Résolu Re: Problème de condition sur un script

Lun 22 Fév 2016 - 21:03
Oui, en temps normal, on a les infos suivantes :

Expérience :
Valeur actuelle
Valeur à atteindre

Prochains bonus :
Stat augmentée
Evolution de la valeur

Quand l'équipement atteint le niveau max, je souhaiterais ça :

Expérience :
-

Prochains bonus :
-

C'est la condition que je n'arrive pas à formuler.

Edit : Ah bah tu l'as prévu dedans en fait. Merci, c'est tout à fait ça que je voulais.
Contenu sponsorisé

Résolu Re: Problème de condition sur un script

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