Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: diagostimo on June 11, 2012, 01:49:04 am

Title: a problem with changing the actors graphic
Post by: diagostimo on June 11, 2012, 01:49:04 am
ok in my script i have a line of code that gets the current graphic of the player, then it adds "_hack" onto the end of it, the problem i am getting is that when i come to turn $cutting on which changes the graphic as seen in the script below i get an undefined method for '+'

class Game_Player
 alias update_new update
 def update
   update_new
   a = $game_actors[1]
   if $cutting == true
     oldgraphic = a.character_name
     a.set_graphic((a.character_name + "_hack"), a.character_hue, a.battler_name, a.battler_hue)
     @step_anime = true
   else
      a.set_graphic(oldgraphic, a.character_hue, a.battler_name, a.battler_hue)
     @step_anime = false
   end
 end
end

i have tried it a few other similar ways but i keep getting errors, does anyone know how i can add it onto the end sucessfully?
Title: Re: a problem with changing the actors graphic
Post by: ForeverZer0 on June 11, 2012, 02:12:39 am
The whole method is kinda done wrong.

First, you need to set some type of condition so the "_hack" is only added once, otherwise with seconds, it will be searching for "Graphics/Characters/01-Fighter01_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack_hack".

Use an instance variable to store it, and do so only once. It would be smarter to just add a method to Game_Player, like "cutting=(value)" and forget aliasing update altogether.

The reason it is you get the error is that when $cutting" is false, you are setting the actor's character graphic to nil, since "oldgraphic" never gets set under them conditions.
Title: Re: a problem with changing the actors graphic
Post by: diagostimo on June 11, 2012, 06:38:35 am
cool, thanks i can see where i messed up now, i have now simplified it all out of game_player and added it all to my call method in Interpreter, it now functions how i want it to, my question is can i change @step_anime from outside Game_Player so it only affects Game_player? i have set up methods that work fine now but if i could control it from outside i wouldnt need them, heres my code as it stands:
module Wcconfig
  def self.tree_setup(tree)
    return case tree
     #when TREE_ID then [WAIT_TIME, EXP_GAINED, ITEM_GAINED, LEVEL_REQUIRED]
      when 1 then [20, 5, 1, 1]
      when 2 then [40, 10, 2, 5]
     
      else ''
    end
  end
end
#---------------------------------------------------------------------------
# *create new skills
#---------------------------------------------------------------------------
class Game_Actor
  attr_reader   :wclevel                    # wood cutting level
  attr_accessor   :wcexp                      # wood cutting exp
  #--------------------------------------------------------------------------
  alias setup_mod setup
  def setup(actor_id)
    setup_mod(actor_id)
    @wclevel = 1
    @wcexp_list = Array.new(101)
    make_wcexp_list
    @wcexp = @wcexp_list[@wclevel]
    $wclevel = wclevel
  end
  #--------------------------------------------------------------------------
  # * CALCULATE WC XP   
  #--------------------------------------------------------------------------
  def make_wcexp_list
     actor = $data_actors[@actor_id]
    @wcexp_list[1] = 0
    @wcexp_list[2] = 35 # Level 2 requires 35 exp
    for i in 3..100 # Now let's use an equation to do the rest of the exp values
      if i > actor.final_level
        @wcexp_list[i] = 0
      else
        @wcexp_list[i] = (35*(i-1) + @wcexp_list[i-1]) * 2
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Change WC EXP
  #     wcexp : new WC EXP
  #--------------------------------------------------------------------------
  def wcexp=(wcexp)
    @wcexp = [[wcexp, 9999999].min, 0].max
    # Level up
    while @wcexp >= @wcexp_list[@wclevel+1] and @wcexp_list[@wclevel+1] > 0
      @wclevel += 1
    end
    # Level down
    while @wcexp < @wcexp_list[@wclevel]
      @level -= 1
    end
  end
  #--------------------------------------------------------------------------
  # * Get WC EXP String
  #--------------------------------------------------------------------------
  def wcexp_s
    return @wcexp_list[@wclevel+1] > 0 ? @wcexp.to_s : "-------"
  end
  #--------------------------------------------------------------------------
  # * Get Next Level WC EXP String
  #--------------------------------------------------------------------------
  def next_wcexp_s
    return @wcexp_list[@wclevel+1] > 0 ? @wcexp_list[@wclevel+1].to_s : "-------"
  end
  #--------------------------------------------------------------------------
  # * Get Until Next Level WC EXP String
  #--------------------------------------------------------------------------
  def next_rest_wcexp_s
    return @wcexp_list[@wclevel+1] > 0 ?
      (@wcexp_list[@wclevel+1] - @wcexp).to_s : "-------"
  end
end
#----------------------------------------------------------------------------
# * draw wc level and exp
#----------------------------------------------------------------------------
class Window_Base
  def draw_actor_wclevel(actor, x, y)
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 32, 32, "WC")
    self.contents.font.color = normal_color
    self.contents.draw_text(x+24, y, 24, 32, actor.wclevel.to_s, 2)
  end
  def draw_actor_wcexp(actor, x, y)
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 32, 32, "exp")
    self.contents.font.color = normal_color
    self.contents.draw_text(x+32, y, 50, 32, actor.wcexp.to_s, 2)
  end
end
#----------------------------------------------------------------------------
# *add the wc level and xp to menu status
#----------------------------------------------------------------------------
class Window_MenuStatus
  alias refresh_mod refresh
  def refresh
    refresh_mod
    $game_party.actors.each_index {|i|
      draw_actor_wclevel($game_party.actors[i], 150, 96+(i*116))
      draw_actor_wcexp($game_party.actors[i], 360, 96+(i*116))}
  end
end

class Window_Status
  alias refresh_mod refresh
  def refresh
    refresh_mod
  self.contents.draw_text(320, 0, 80, 32, "WC EXP")
    self.contents.draw_text(320, 32, 80, 32, "NEXT")
    self.contents.font.color = normal_color
    self.contents.draw_text(320 + 80, 0, 84, 32, @actor.wcexp_s, 2)
    self.contents.draw_text(320 + 80, 32, 84, 32, @actor.next_rest_wcexp_s, 2)
  end
end
#---------------------------------------------------------------------------
# *class Interpreter(adds methods for the cutting timer and returning to norm)
#---------------------------------------------------------------------------
class Interpreter
  attr_accessor    :cutting
  attr_accessor    :old_graphic
 
  alias clear_mod clear
  def clear
    @wc_count = 0
    clear_mod
  end
 
  alias update_mod update
  def update
    update_mod
    if @wc_count > 0
        # Decrease wait count
        @wc_count -= 1
        if $game_player.moving?
          @wc_count = 0
          @cutting = false
        end
        return
      end
    if @cutting == true
      ctree = Wcconfig::tree_setup(@tree)
      if @wc_count == 0
        $game_player.cut_disable
        @cutting = false
        for i in 0...$game_party.actors.size
          a = $game_actors[1]
          a.set_graphic(@old_graphic, a.character_hue, a.battler_name, a.battler_hue)
          actor = $game_party.actors[i]
          actor.wcexp += ctree[1]
          $game_player.refresh
        end
      end
    end
  end
 
  def tree=(tree)
    @tree = tree
  end
  #--------------------------------------------------------------------------
  # *my call when cutting a tree
  #--------------------------------------------------------------------------
  def hacking
    a = $game_actors[1]
    @old_graphic = a.character_name
    wc_graphic = a.character_name + "_hack"
    a.set_graphic(wc_graphic, a.character_hue, a.battler_name, a.battler_hue)
    ctree = Wcconfig::tree_setup(@tree)
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      if actor.wclevel >= ctree[3]
        @cutting = true
        @wc_count = ctree[0] * 2 - 1
     
        #last_wclevel = actor.wclevel
        #gainitemhere
        $game_player.cut_enable
        $game_player.refresh
      end
    end
  end
end 
#----------------------------------------------------------------------------
# *Game player (activate/deactivate step_anime)
#----------------------------------------------------------------------------
class Game_Player
  def cut_enable
    @step_anime = true
  end
  def cut_disable
    @step_anime = false
  end
end

im now trying to figure out how the sprite is drawn on the map, as i want to add a sprite that runs when my call is made, i.e a hatchet, my problem is tracing the variables included in the drawing of the character sprite, from what i gather the sprite is drawn from the following classes: spriteset_map, sprite_character, game_player, game_character.
i can follow most of the variables and sort of understand how it is drawn but after a while my brain turns to mush, and i dont know where to start :(