Changing the cost of a skill mid game

Creating the duplicate/triplicate skills isn't difficult, but as we both agree, it's having all those parallel processes running that is potentially a seriously bad thing.



Wouldn't you have to create only one Parallel Process event? That contains all your conditional branches and variables, and learn/forget skills?


I haven't tinkered with VX/ACE in a good long while.. but I kinda feel like it still operates as such. If I had my copy of Ace I would try it.. but perhaps you could try a little sample of this? Create a sample map, set up a couple of skills, create the event as Parallel Process, set starting character, change maps, and then see if the Parallel Process events conditions still apply. I'm not 100% certain, but I kinda feel like they do..
I've searched through the list of scripts on Yanfly's site and can't see one which addresses skill costs, though I may have missed something.


All of the Lunatic scripts emphasize that they are for advanced users.  I'm barely above the idiot level myself. I can configure and do very minor tweaks but there is no way that I'm an advanced user.





Yanfly's Skill Cost Manager for Ace should do the trick... 
Parallel processes run across maps only if they are common events.  Map parallel processes stop when you leave the map.  However a small script to turn on a switch when the conditions change is better than even a single parallel process that runs constantly.


@ksjp17 here you go:
Couldn't you create all the skill changes etc., as a Common Event, and have that called as a Parallel Process on the first map and it would carry on through the rest of the maps/game?
Yes, that's what I said in the post immediately above yours.
@Shaz Thank you so much.  A simple, elegant solution for something that appeared to be becoming more complex every time I thought about it.


My game and my stress levels are both improved by this.
What's your plan for the common event?  There are several ways you can go about it ... I can list a few of them if you like, but the following suggestion would only require one variable and you wouldn't need to keep track of levels.  Let's say you want Actor 1 to start with skill 10, to upgrade to skill 11 at level 5, upgrade to skill 12 at level 10, and upgrade again to skill 13 at level 20:

Code:
Control Variables [x] = Actor 1's level
Conditional Branch: Variable [x] >= 20
  Conditional Branch: Actor 1 knows Skill 13
    # do nothing
  Else
    Change Skills - Actor 1 forgets Skill 12
    Change Skills - Actor 1 learns Skill 13
  end
Else
  Conditional Branch: Variable [x] >= 10
    Conditional Branch: Actor 1 knows Skill 12
      # do nothing
    Else
      Change Skills - Actor 1 forgets Skill 11
      Change Skills - Actor 1 learns Skill 12
    End
  Else
    Conditional Branch: Variable [x] >= 5
      Conditional Branch: Actor 1 knows Skill 11
        # do nothing
      Else
        Change Skills - Actor 1 forgets Skill 10
        Change Skills - Actor 1 learns Skill 11
      End
    End
  End
End

What's happening here is, after each battle, instead of seeing if they've leveled up, you're just checking what level they are at, and if they know the correct version of the skill for their current level.  If they don't know it, it means they've just leveled up to a 'relevant' level, so you get rid of the old skill and add the new one.  You start with the highest relevant level and each time the condition isn't met you move to the next relevant level (doing it the other way would cause only the first upgrade to happen and none of the others).  If you want a message to indicate the skill has been upgraded, you'd do it in the blocks where the skills are changed.


Then you just repeat that block (including setting the variable) for each actor, adjusting the skills and levels as necessary.
No concept of game specific skill information exists in the default VX Ace scripts. You only have the RPG::Skill data structure which stores static information about skills.


To handle skill change during game play I recommend creating a Game_Skill class to encapsulate how skill data changes during the course of a game, a bit similar to how you have Game_Actor.


class Module
def attr_sec_accessor(sym, default = 0)
attr_writer sym
attr_sec_reader sym, default
end

def attr_sec_reader(sym, default = 0)
sym = sym.id2name
string = "def #{sym} ;" +
" @#{sym} = #{default} if @#{sym}.nil? ;" +
" @#{sym} ;" +
"end ;"
module_eval(string)
end
end

##
# Game_Skill encapsulates the changes that may occur to skills during game play
# It uses the RPG::Skill objects for fetching default values
#
class Game_Skill
ATTRIBUTES = ['stype_id', 'mp_cost', 'tp_cost', 'message1', 'message2',
'required_wtype_id1', 'required_wtype_id2']

for attribute in ATTRIBUTES
# Computes the setter and getter code for the specific attribute
PROG = <<FIN
attr_writer :#{attribute}
def #{attribute}
if @#{attribute}.nil?
return @data.#{attribute}
else
return @#{attribute}
end
end

def #{attribute}_check(default)
return default if @#{attribute}.nil?
return @#{attribute}
end
FIN
# Evaluates the method definitions
eval(PROG)
end

#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(data_item)
@data = data_item
end
end

##
# Hack for a simple copy-paste integration.
# Uses the $game_system god object to look at the current state of the game
# specific data. The cost is increased coupling probably more difficult
# debugging scenarios.
#
class RPG::Skill < RPG::UsableItem
for attribute in Game_Skill::ATTRIBUTES
PROG = <<FIN
def #{attribute}
return $game_system.skills[id].#{attribute}_check(@#{attribute}) if $game_system
return @#{attribute}
end

def #{attribute}=(value)
if $game_system
$game_system.skills[id].#{attribute} = value
else
@#{attribute} = value
end
end
FIN
# Evaluates the method definitions
eval(PROG)
end
end


#==============================================================================
# ** Game_Skills
#------------------------------------------------------------------------------
# This class handlesskiils. It's a wrapper for the built-in class "Array."
# Refer to "$game_system.skills" for the instance of this class.
#==============================================================================

class Game_Skills
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
if $data_skills.nil?
@data = []
else
@data = Array.new($data_skills.size)
end
end
#--------------------------------------------------------------------------
# * Get Skill
# skill_id : skill ID
#--------------------------------------------------------------------------
def [](skill_id)
if @data[skill_id] != nil
return @data[skill_id]
else
if $data_skills[skill_id] != nil
@data[skill_id] = Game_Skill.new($data_skills[skill_id])
return @data[skill_id]
end
return nil
end
end
#--------------------------------------------------------------------------
# * Set Armor
# skill_id : skill ID
# skill : a Game_Skill
#--------------------------------------------------------------------------
def []=(skill_id, skill)
@data[skill_id] = skill
end
end

##
# Putting the game skills collection in the game system class allows the changes
# to be stored in save files with low risk of compatibility issues
#
class Game_System
attr_sec_accessor :skills, 'Game_Skills.new'
end




I have included a bit of a hack so you can simply copy-paste code into your editor.


For changing mp and tp cost you can use these lines in script calls:


$data_skills[42].mp_cost = 20
$data_skills[42].tp_cost = 13
$game_system.skills[42].mp_cost = 120
$game_system.skills[42].tp_cost = 31




*hugs*


 - Zeriab
@Shaz yes, that seems the easiest way to run it.  Nice to have all the logic worked out for me.  This is all becoming easier by the minute.


@Zeriab  Now that looks a useful method for a little something else I had in mind, but had thought I wouldn't be able to do, so I'm really benefiting here.  Thank you.
@ksjp17 there is another option I just remembered: SP-Parameter MCR - MP cost rate


This would not work for skills with TP cost, and it will affect every MP cost of every skill - but if you use a script for dynamic traits, then you can add an increase of the effective MP cost at any time you want in your game.
Arghh!! I'm in fact using that script, so I had a solution all along and didn't realise it.  Oh well, I'll know for another time.  


Thanks for the tip.


Closing

Original thread: https://forums.rpgmakerweb.com/threads/changing-the-cost-of-a-skill-mid-game.70895/