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.

Special Support - A great place to learn to Script

Everyone wants to learn to script, but no one really knows where to start. In my honest opinion, the best place to learn is just by reading the default scripts. I learned to script with the japanese RMXP, so I didn't have English comments at my disposal, so everyone of the new generation has that upperhand. Anyways, what I think the best thing to do to learn to script is read the default scripts, and understand each line.

So what I am offering here is support for anyone trying to learn to script. If there is a line of code you don't understand, ask me here. If there is something you want to know, like where in the script editor does something happen, ask here.
  • Ask about a certain line of code : What it means, does, etc.
  • Ask where the coding is for a certain function
PLEASE DO NOT ASK SOMETHING OTHER THAN EXISTING CODE, OR WHERE IN THE DEFAULT SCRIPTS TO FIND A CERTAIN BLOCK OF CODE. Your post will be deleted.

This is a Trial and Error topic. Hopefully, it can lead to more a use full FAQ for beginners.
 
Hi guys. I came here cause i need help with 2 things.

"Things" 1:

I want to cap the stats of the actors. Basically, i can set the actor stats for different level in the database BUT the cap is 9999 for hp/sp and 999 for the other stats. Let's take an example; Actor 1 has a minimum of INT of 50 and MAX 500. Actor 1 can always use ton of seed of inteligence to increase his stats to 999, THIS IS EXACTLY WHAT I DON'T WANT! I would like to cap his intelligence at (for example) 750.

I have check the default script and i have been able to set the cap i want, everything is found in "Game_Battler 1". Intelligence stats are as follows by default:

Code:
  #--------------------------------------------------------------------------
  # * Get Intelligence (INT)
  #--------------------------------------------------------------------------
  def int
    n = [[base_int + @int_plus, 1].max, 999].min
    for i in @states
      n *= $data_states[i].int_rate / 100.0
    end
    n = [[Integer(n), 1].max, 999].min
    return n
  end

and i have change it into this to cap INT at 750

Code:
  #--------------------------------------------------------------------------
  # * Get Intelligence (INT)
  #--------------------------------------------------------------------------
  def int
    n = [[base_int + @int_plus, 1].max, 750].min # Moded
    for i in @states
      n *= $data_states[i].int_rate / 100.0
    end
    n = [[Integer(n), 1].max, 750].min # Moded
    return n
  end

As i said, it works and i have been able to set a cap BUT when i scroll a little in the "Game_Battler 1", i found this:

Code:
  #--------------------------------------------------------------------------
  # * Set Intelligence (INT)
  #     int : new Intelligence (INT)
  #--------------------------------------------------------------------------
  def int=(int)
    @int_plus += int - self.int
    @int_plus = [[@int_plus, -999].max, 999].min
  end

I have not change the value since the 750 cap is working. I just want you guys to confirm me that i have do everything right, if there is something wrong then tell me and point me where i should modified in order to implement stats cap.



"Things" 2:

I wanted to know what are the normal attack damage formula and skill damage formula but the help file is too vague and didn't really help me. So, after searching the default script inside out i pin pointed where the formula was; in the "Game_Battler 3". I have been able to understand the normal attack damage formula but the skill damage formula is a pain. Here is the code for the skill damage formula:

Code:
      # Calculate power
      power = skill.power + user.atk * skill.atk_f / 100
      if power > 0
        power -= self.pdef * skill.pdef_f / 200
        power -= self.mdef * skill.mdef_f / 200
        power = [power, 0].max
      end
      # Calculate rate
      rate = 20
      rate += (user.str * skill.str_f / 100)
      rate += (user.dex * skill.dex_f / 100)
      rate += (user.agi * skill.agi_f / 100)
      rate += (user.int * skill.int_f / 100)
      # Calculate basic damage
      self.damage = power * rate / 20

With the almost no knowledge of RGSS i have tried to rewrite the formula in a simple math form, the result is as follows:

Code:
1) Power:

      Skill Power + User Attack * Skill AttackF / 100
      - Target Pdef * Skill PdefF / 200
      - Target Mdef * Skill MdefF / 200

2) Rate:

     20 + (User str * Skill StrF / 100)
        + (User dex * Skill DexF / 100)
        + (User agi * Skill AgiF / 100)
        + (User int * Skill IntF / 100)

Final damage will be calculated as follows = Power * Rate / 20

Now the problem is when i applied the formula and make a test battle, things don't turn out well. The damage is much more than i calculated. The skill i used was Spiral Blade(skill 60) and i have set variance to 0. Also, no element damage are set. I would like to know whether my rewritten formula is right; if not then please can anybody tell me the formula for Skill Damage?

It was lot of reading but i hope that someone might come to my rescue.

Thanks for your time and patience,
SBS

P.S: I don't know much about RGSS but i trying to learn 1-2 thing so(and maybe later write some script ;) ), please don't be hard on me ;)
 
I'm re-learning how to do window/selectable crap, as my old computer suffered some errors and I lost my ability to testplay...

Anyways, I'm (attempting to) create a visual banking script, perferrably one that can work independantly with messages.

This screenshot is an example of what I'm aiming for...

http://i224.photobucket.com/albums/dd28 ... Sample.jpg[/img]

There's already tuts out there I'm reading that tell me how to do Window/Selectables, but I need to know how to do an Input Number request within my script (and the BankStatus with all the variables needs to update respectively when dialing in your desired deposit/withdrawl.)

The question is; How I can call that Input Number request in my script without having to re-write the whole class in my own script? I know you can do inheritence with Window_Base and Window_Selectable, can you do inheritence with InputNum though?

And a second question; This might sound dumb, but how can I call a message within a script (not a p or a print, but an actual message?) I obviously know how to use an event, but I always wondered how to do that within a script.
 
I've been looking over the scripts for some time and I understand how, for the most part, a script is run (such as classes and functions, and all that fun stuff :P). However, there are still some contents of the scripts I don't understand. Particularly this one from Game_Battler 1:

Code:
304 def resting?
305   return (@current_action.kind == 0 and @current_action.basic == 3)
306 end

I'm thinking that it might be applied when you're checking to see if the player is in the battle commands menu, but I'm not too sure. If anyone has any idea what this line does, that would be awesome.  :thumb:

Thanks in advanced to anyone who helps.
 
NeoSamurai":20e1h87r said:
Code:
304 def resting?
305   return (@current_action.kind == 0 and @current_action.basic == 3)
306 end

Neo, that is shorthand for..
Code:
304 def resting?
305   if @current_action.kind == 0 and @current_action.basic == 3
306      return true
307   end
308 end

from Game_BattleAction:
  attr_accessor :kind                    # kind (basic / skill / item)
  attr_accessor :basic                    # basic (attack / guard / escape)

Since Attack=0, Guard=1, Escape=2,  3 must equal "Not doing anything"

However, I don't see anywhere in the default scripts where "resting?" is used.

the only logical place where it could be used (I think) is to determine when to
start the action phase. (after all actors have selected an action)

Did that clear it up, or muddy it more?  :scruff:
 
Silencher":1woyka7r said:
How would I use a script to transfer the entire party to another map?

Also, what would I do to suddenly remove a party members sword and replace it with another weapon?

From this forum's FAQ:
Code:
 $game_temp.player_transferring = true
  $game_temp.player_new_map_id = #
  $game_temp.player_new_x = #
  $game_temp.player_new_y = #
  $game_temp.player_new_direction = #
  $scene = Scene_Map.new
  $game_map.autoplay
Change # to the numbers you need (for directions 2 is down, 8 is up, 4 is left, 6 is right I think)

For your second question it's something like $game_party.actors[n].equip(type, ID), where type is 0 for weapon, 1 for shield, 2 for head gear, 3 for body and 4 for accessories, and ID is the equipment's ID in the database). n is the party member's index in party (0 is first party member etc.), if you want to target a specific actor instead (instead of based on party position), use $game_actors[n].equip(type, ID), here you'd use the specific actor's number in the database for the n.

Edit: Damn, I had a long post to all other questions but somehow closed the tab...
In short:
Kain Nobel: Look at how Window_Message does it. No need to inherit something unless you want to add to it or change it a bit. Pay attention to:
Code:
    if $game_temp.num_input_variable_id > 0
      # Get maximum number of digits, number at variable,
      # and create the input number window
      digits_max = $game_temp.num_input_digits_max
      number = $game_variables[$game_temp.num_input_variable_id]
      @input_number_window = Window_InputNumber.new(digits_max)
      @input_number_window.number = number
      @input_number_window.x = self.x + 8
      @input_number_window.y = self.y + $game_temp.num_input_start * @line_height
    end
in particular.

SilentBackstabber: The first thing... that'd work, although the cap would affect all battlers. The second thing, I'm not sure what's wrong. How did you test it?

NeoSamurai: Brewmeister did a great job explaining it. That particular method isn't actually used in the default scripts, as the battle system checks the action variable directly instead, but what 'do nothing' or 'resting' does is waste the turn doing nothing. It's an action you could set to an enemy in the database, or force on any battler using the Force Action event command. It's a nice utility method to have nonetheless.
 
Okay, this actually is an item I could use. If you've ever played Suikoden this would make sense, but I'm looking for an item that returns you to your home base.

Let's assume the item number is like.. 25. How could I do basically what you just did, but this time it would ask, "Do you really want to use the ITEM?", it would show a choice, then if you did Yes, it would teleport you to wherever?
 
Brewmeister":20a85c41 said:
NeoSamurai":20a85c41 said:
Code:
304 def resting?
305   return (@current_action.kind == 0 and @current_action.basic == 3)
306 end

Neo, that is shorthand for..
Code:
304 def resting?
305   if @current_action.kind == 0 and @current_action.basic == 3
306      return true
307   end
308 end

from Game_BattleAction:
  attr_accessor :kind                     # kind (basic / skill / item)
  attr_accessor :basic                    # basic (attack / guard / escape)

Since Attack=0, Guard=1, Escape=2,  3 must equal "Not doing anything"

However, I don't see anywhere in the default scripts where "resting?" is used.

the only logical place where it could be used (I think) is to determine when to
start the action phase. (after all actors have selected an action)

Did that clear it up, or muddy it more?  :scruff:

Cowlol":20a85c41 said:
NeoSamurai: Brewmeister did a great job explaining it. That particular method isn't actually used in the default scripts, as the battle system checks the action variable directly instead, but what 'do nothing' or 'resting' does is waste the turn doing nothing. It's an action you could set to an enemy in the database, or force on any battler using the Force Action event command. It's a nice utility method to have nonetheless.

Yeah. It makes a lot more sense now. Thanks for clearing it up, Brewmeister and Cowlol. :)
 
In the script "Interpreter 7", there is this that I don't understand.
Code:
result = eval(script)

More specifically, I don't understand what the "eval" means. Could somebody give me a bit of a hand?
 
Thanks Brewmeister.

Another question, the reason I wanted to know, is because I wanted to edit the Steps in Scene_Menu with the current map ID that the main party is on, so I figured as such, that I would just go to Window_Steps and replace:
Code:
    self.contents.draw_text(4, 32, 120, 32, $game_party.steps.to_s, 2)

To:

Code:
    self.contents.draw_text(4, 32, 120, 32, $game_map.map_id)

I thought it would be that simple, but I'm sure I'm missing something, any help? (and explanation as to why that didn't work? o.o)

Thanks again.
-Krobe
 
I think it's because you're not giving any teleport instructions. All you are doing is telling it to go somewhere, not even which map it is on. I wouldn't use it in a self.contents script at all, I'm afraid, Krobe. It just wouldn't work, because there are 6 lines which you need to fill in. Everything else is fine.
 
I KNEW you were going to ask that.....  :scruff:

$data_map_infos[$game_map.map_id].name

BUT....  you have to load map_infos first...

in Scene_Title, where all the "load_data" statements are,  add

    $data_map_infos = load_data("Data/MapInfos.rxdata")

Be Well
 

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