Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

hopfully simple, increase variable when a skill is used

I'm looking for a script that when a certain skill is used then a variable is increased by 1

At the moment it only needs 2 skills in it, but would like the ability to easily add more skills when I've made them

So when the user is in battle and they use the particular skill, the a variable is increased by 1. I would prefer it not to work via the menu if possible

The two skills and their variables

Heal (ID: 1) Variable: (ID) 9
Fire (ID: 2) Variable: (ID) 10


Thanks to anyone who attempts this


PS: I know i could do this using common events, but i would then have 50+ common events, and i think scripting would be easier
 
Try this:
Code:
class Change_with_id_skl
  
  
  #EDIT THIS!
  #Is the ID of the variable where the values will be saved with the saves
  #You can't use it for other purpose in your game  
  Number_of_variable_to_save=1
  #END OF 1st EDIT
  
  @data_set={}
  
=begin
Type of edit:
-------------------------------------------------------
1st:
@data_set[id_of_player]={}
2nd step:
@data_set[id_of_player][id_of_skill]=0  #Or use some the default value
                                        #when "new game"
#id_of_player is the id of the player that cast the skill
              two players with the same magic have separate values
              To use the same value only sum both when needed
              Use a negative value for monsters!
#id_of_skill is the id of the skill used

And repeat for others skills
-------------------------------------------------------
=end


  
  #MUST EDIT FOR YOUR PLAYERS
#------------------------------------------------------


  #example (delete it!)
  @data_set[1]={}
  @data_set[1][57]=0
  @data_set[1][7]=0
  
  @data_set[-1]={}
  @data_set[-1][1]=0
  
  @data_set[7]={}
  @data_set[7][1]=0
  #end example

  
#------------------------------------------------------
  #END MUST EDIT

  
  @data_set_starts=@data_set.dup
  
  
  
#To know a value:
#variable = Change_with_id_skl.returner(id_name,id_skill)

#To change a value:
#Change_with_id_skl.returner(id_name,id_skill,new_value)


  def self.returner(id_name,id_skill,value=nil)
    if value == nil
      if $game_variables[Number_of_variable_to_save] != 0
        @data_set=$game_variables[Number_of_variable_to_save].dup
      else
        @data_set=@data_set_starts.dup
      end
      if @data_set[id_name] == nil
        return nil
      else
        return @data_set[id_name][id_skill]
      end
    else
      @data_set[id_name][id_skill]=value
      $game_variables[Number_of_variable_to_save]=@data_set.dup
    end
  end
  
  
  def self.data(name,id_skill,value)
    if $game_variables[Number_of_variable_to_save] != 0
      @data_set=$game_variables[Number_of_variable_to_save].dup
    else
      @data_set=@data_set_starts.dup
    end
    if @data_set[Change_with_id_skl.id_searcher(name)] != nil
      if @data_set[Change_with_id_skl.id_searcher(name)][id_skill] != nil
        @data_set[Change_with_id_skl.id_searcher(name)][id_skill]+=value
        $game_variables[Number_of_variable_to_save]=@data_set.dup
      end
    end
  end
  
  def self.id_searcher(name)
    j=0
    $data_actors.each do |i|
      if i != nil
        if i.name == name
          return j
        end
      end
      j+=1
    end
    j=0
    $data_enemies.each do |i|
      if i != nil
        if i.name == name
          return -j
        end
      end
      j+=1
    end
  end
end

class Scene_Battle
  alias change_vars_with_id_name_MSAR make_skill_action_result
  def make_skill_action_result
    change_vars_with_id_name_MSAR
    Change_with_id_skl.data(@active_battler.name,
           @active_battler.current_action.skill_id,1)
  end
end

You must edit a few lines:
---------1st:
Number_of_variable_to_save=1

Change the '1' to a number of an ID of a variable that you will not use.
The changes will be saved in that $game_variables

---------2nd:
You need to add the skills that affects this script.
In the script is explained how to make it.



To retrieve the value use:
variable = Change_with_id_skl.returner(id_name,id_skill)

'variable' it's the variable where you want to save it.
If you make this call with invalids id_name or id_skill then returns nil.

(Put that script above main and under Scene_battle)
I don't know if admits SDK but... maybe yes...
 
thank you, i think i understand it

i have a question though, if i want to display the variable in a text box how would i do it, and does this not work in the menu or when enemies use that skill? (i don't it does work which is fine by me)

Havn't tested it yet as i'm going straight to work now but will when i get home

Will find out if it works with SDK later as i'm using it (Version: 1.5 i believe)
 
I've changed a little bug (repaired in the post of the script).

Also, there is a problem with the names...
Don't name two players (or two monsters or a monster and a player if you also use the skills of the monsters) with the same name.
If you use a 'name yourself' input try to compare the new name with all the names and do not accept an already used name.

OK, to use it in a message box use:
First do a script call with
Code:
$game_variables[33]=
Change_with_id_skl.returner(1,57)
(Change:
33->id of an unused or only used temp variable
1->id of the battler with the skill
You can use a negative value for the monster type
57->id of the skill required to know times done in combat

Next, in the message box use "\v[33]" to show the value of than variable (change the 33).

If you want a customed text box, use the string "#{(Change_with_id_skl.returner(1,57)).to_s}" when draw_text.
If don't work, use
a_temp=(Change_with_id_skl.returner(1,57)).to_s
and use the variable a_temp with the draw_text.

If want to know all the times that the skill was used in your party do:
a_temp=(Change_with_id_skl.returner(1,57)).to_i +
(Change_with_id_skl.returner(2,57)).to_i +
(Change_with_id_skl.returner(3,57)).to_i + etc...

About the monsters no problem because uses the id of the casters to save it. Positive for the players and negative for the monsters, and only stores it if you used an starter value (see the script and the lines you must edit).


The skills used in the menu are not considered. It only works in the battle and only in battles kind of the default system. If it not work it's for a big change done. In that case, say what scripts use and somebody can make it compatible.
 
thanks, i'll try it when i get home. Monstars aren't going to have the ability as its to do with a skill level up system which is why i dont want it in the menu as it can be abused with healing spells#

thanks for your help, i'll post again if i run into any problems with it later
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top