custom skills?

Started by diagostimo, June 07, 2012, 09:09:30 pm

Previous topic - Next topic

diagostimo

hi guys, i have been trying to create a custom skill in my game, and i have based it on how the characters lvl is built in game_actor, so here is my code at the moment:
Spoiler: ShowHide
#---------------------------------------------------------------------------
# *create new skills
#---------------------------------------------------------------------------
class Game_Actor
 
  attr_reader   :wclevel                    # wood cutting level
  attr_reader   :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]
    #------------------------------
  end
 
  #--------------------------------------------------------------------------
  # * CALCULATE WC EXP   
  #--------------------------------------------------------------------------
  def make_wcexp_list
    actor = $data_actors[@actor_id]
    @wcexp_list[1] = 0
    pow_i = 2.4 + 35 / 100.0
    for i in 2..100
      if i > 99
        @wcexp_list[i] = 0
      else
        n = 1 * ((i + 3) ** pow_i) / (5 ** pow_i)
        @wcexp_list[i] = @wcexp_list[i-1] + Integer(n)
      end
    end
  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 + 32, 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, 24, 32, actor.wcexp.to_s, 2)
  end
   
end

#----------------------------------------------------------------------------
# * draw wc level and xp in the menu
#----------------------------------------------------------------------------
class Window_MenuStatus
 
  alias refresh_mod refresh
  def refresh
    refresh_mod
    $game_party.actors.each_index {|i|
      draw_actor_wclevel($game_party.actors[i], 310, 0)}
    $game_party.actors.each_index {|i|
      draw_actor_wcexp($game_party.actors[i], 370, 0)}
  end
end


i can get the values to show in the window i set them to, im at the point in trying to add exp to the the skill to see if it lvls up corectly, but i get an error when i try adding to it, heres what im using to add the xp:
exp = 100
      for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
     
        last_wclevel = actor.wclevel
        actor.wcexp += exp
      end

im not sure if i have set up the exp right but as i can see from how it is setup in game_actors and how it adds it in Scene_battle it should work  :???:

KK20

When you use actor.wcexp += exp, it's looking for the 'write' method. However, you set wcexp as an attr_reader. So it's probably best to change that to an attr_accessor.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

diagostimo

thanks man, it adds the exp now, the only problem is im setting it to add 100 but its adding 400, also i have spammed loads of xp into the lvl but it doesnt seem to lvl up, i dont understand how the calculation for the xp breaks it up and forces the variable to increase, do i have etherything? if you could break it up so i understand how it is calculated that would be great :)

KK20

Tried to replicate the '400 exp error' but couldn't. I have no idea what could be causing that other than something in your code shouldn't be there.

As for making the wood cutting level actually level up, I'd take a look at how EXP is added in Game_Actor (I removed some of the unnecessary stuff):
Spoiler: ShowHide
  #--------------------------------------------------------------------------
  # * Change EXP
  #     exp : new EXP
  #--------------------------------------------------------------------------
  def exp=(exp)
    @exp = [[exp, 9999999].min, 0].max
    # Level up
    while @exp >= @exp_list[@level+1] and @exp_list[@level+1] > 0
      @level += 1
    end
    # Level down
    while @exp < @exp_list[@level]
      @level -= 1
    end
  end
I'm pretty sure you can modify it to fit your needs now.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

diagostimo

cool, i am now gaining levels after inserting that code, but its still adding 400 xp when i specify it to add 100, also theres a minior glitch in the menu when showing the level, it constantly shows the default level behind the current one, heres my full script as of now:
#---------------------------------------------------------------------------
# *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]
    #------------------------------
  end
  #--------------------------------------------------------------------------
  # * CALCULATE WC XP   
  #--------------------------------------------------------------------------
  def make_wcexp_list
    actor = $data_actors[@actor_id]
    @wcexp_list[1] = 0
    pow_i = 2.4 + 100 / 100.0
    for i in 2..100
      if i > actor.final_level
        @wcexp_list[i] = 0
      else
        n = 1 * ((i + 3) ** pow_i) / (5 ** pow_i)
        @wcexp_list[i] = @wcexp_list[i-1] + Integer(n)
      end
    end
  end
#--------------------------------------------------------------------------
  # * Change EXP
  #     exp : new 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
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

#----------------------------------------------------------------------------
#
#----------------------------------------------------------------------------
#class Game_Party
#  alias setup_battle_test_members_mod setup_battle_test_members
#  def setup_battle_test_members
#    setup_battle_test_members_mod
#----------------------------------------------------------------------------
# * draw wc level and xp in the menu
#----------------------------------------------------------------------------
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, 95)}
    $game_party.actors.each_index {|i|
      draw_actor_wcexp($game_party.actors[i], 360, 95)}
  end
end








class Interpreter
 
  alias update_mod update
  def update
    update_mod
    if @wait_count == 0
      $cutting = false
    end
   
  end
  def my_call
    $cutting = true
    if $game_switches[1]
      a = $game_actors[1]
      a.set_graphic('aluxeswc', a.character_hue, a.battler_name, a.battler_hue)
      $game_player.refresh
     
      @wait_count = 200 * 2 - 1
     
      for i in 0...$game_party.actors.size
      actor = $game_party.actors[1]
     
        #last_wclevel = actor.wclevel
        actor.wcexp += 100
      end
      $game_player.refresh
   
    end
  end
end 



class Game_Player
  alias initialize_mod initialize
  def initialize
    initialize_mod
  end
 
  alias update_new update
  def update
    update_new
   
    if $cutting == true
      @step_anime = true
    end
    if $cutting == false
      @step_anime = false
    end
  end
end
 

i am pretty stumped on what is wrong :/

KK20

Now I can clearly see why it's adding 400 instead of 100. In your first post you showed me this:
for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
And now you're showing me this:
for i in 0...$game_party.actors.size
      actor = $game_party.actors[1] #<--- Here's your problem
I'm assuming your party size is 4 (4 * 100 = 400).

As for the window thing, you're drawing all of your party member's WC level and EXP at the exact same coordinates. Do something like this:
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
However, note that the stats are cut off the screen for the 4th actor. Thus, you're going to need to change your x/y values.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

diagostimo

thanks man your help is much appreciated :D i have now added this code to class Game_Actor:
#--------------------------------------------------------------------------
  # * Get EXP String
  #--------------------------------------------------------------------------
  def wcexp_s
    return @wcexp_list[@wclevel+1] > 0 ? @wcexp.to_s : "-------"
  end
  #--------------------------------------------------------------------------
  # * Get Next Level EXP String
  #--------------------------------------------------------------------------
  def next_wcexp_s
    return @wcexp_list[@wclevel+1] > 0 ? @wcexp_list[@wclevel+1].to_s : "-------"
  end
  #--------------------------------------------------------------------------
  # * Get Until Next Level EXP String
  #--------------------------------------------------------------------------
  def next_rest_wcexp_s
    return @wcexp_list[@wclevel+1] > 0 ?
      (@wcexp_list[@wclevel+1] - @wcexp).to_s : "-------"
  end
end

and this to class Window_Status:
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

i have added these so i have a way of viewing what xp i need to reach the next level, when using this i can see the inflation of the xp and mod it as required, the only issue is to reach lvl 2 i only need 1 xp no matter the inflation, how can i raise this to a set number?

KK20

Looking at this
  #--------------------------------------------------------------------------
  # * CALCULATE WC XP   
  #--------------------------------------------------------------------------
  def make_wcexp_list
    actor = $data_actors[@actor_id]
    @wcexp_list[1] = 0
    pow_i = 2.4 + 100 / 100.0
    for i in 2..100
      if i > actor.final_level
        @wcexp_list[i] = 0
      else
        n = 1 * ((i + 3) ** pow_i) / (5 ** pow_i)
        @wcexp_list[i] = @wcexp_list[i-1] + Integer(n)
      end
    end
  end
Specifically this
n = 1 * ((i + 3) ** pow_i) / (5 ** pow_i)
No matter how much you change 'pow_i', you will always get a value of 1 for WC Level 2. If you want to make some customization as to how much exp per level it should be, you can always do something like:
Spoiler: ShowHide
  #--------------------------------------------------------------------------
  # * CALCULATE WC XP   
  #--------------------------------------------------------------------------
  def make_wcexp_list
    @wcexp_list[1] = 0
    @wcexp_list[2] = 5 # Level 2 requires 5 exp
    @wcexp_list[3] = 15 # Level 3 requires 15 exp
    pow_i = 5.5
    for i in 4..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
        n = 1 * ((i + 3) ** pow_i) / (5 ** pow_i)
        @wcexp_list[i] = @wcexp_list[i-1] + Integer(n)
      end
    end
  end
If you have any experience with Microsoft Excel/spreadsheets, I'd suggest playing with your equation until you find something that fits your needs. Of course, you can manually set the exp amounts for every single level (tedious, but still an option).

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

diagostimo

ok thanks man, i do have experience in excel the bit im having a hard time with is figuring out how the equation works in the first place, i actually tried to change the equation to this:
def make_wcexp_list
     actor = $data_actors[@actor_id]
    @wcexp_list[1] = 0
    @wcexp_list[2] = 35

    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] = (@wcexp_list[2] * i)
      end
    end
  end

i would actually prefer it to be like this, so it keeps stacking 35 every lvl, this worked at lvl 3 but then every other lvl after that only required 35 to lvl up, so lets say lvl 2 requires 35, lvl 3 requires 70, lvl 4 requires 105 etc, but when im higher than lvl 3 it only requires 35  :O.o:

KK20

def make_wcexp_list
     actor = $data_actors[@actor_id]
    @wcexp_list[1] = 0
    @wcexp_list[2] = 35

    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]
      end
    end
  end

:P Writing equations is fun :P

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

diagostimo

cool thats sweet as, i made a minor ajustment so it times the value by 2 just so the xp raises abit steaper as it levels up, looking at that equation, 32*(i-1) thats times it by the current i value - 1, so say im lvl 3 it times it by 2, then you + @wcexp_list[i-1] is this part adding that calculation adding on to the previous value so it raises?

KK20

Level 2 Total EXP Required: 35
Equation:
@wcexp_list[i] = 35*(i-1) + @wcexp_list[i-1]

Level 2 to Level 3:
i = 3
@wcexp_list[3] = 35*(3-1) + @wcexp_list[3-1]
@wcexp_list[3] = 35*2 + 35
@wcexp_list[3] = 105

Level 3 Total EXP Required: 105
Amount of EXP needed to get from Level 2 to Level 3: 105 - 35 = 70

Can't really explain it better than that.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

diagostimo

cool i get it now, the part that stresses my brain is when they start using variables then i just get lost, but over time i think ill get the hang of it :)