Part 2! In this tutorial I'll be showing you how to do more advanced stuff like setting up controls, and possibly working with the battle system. Again, I'll be adding too this as I learn more.

Part 1 of part 2: Super Simple Scripted Sprinting System AKA S^5

The evented version is here: http://www.gdunlimit...ted-dash-system

 

This is super simple, but unfortunately doesn't fix the move route problem. It may however, reduce lag, but I'm not sure. Taking out the need for a switch to be on may fix the problem, which is actually possible using this method. Simply remove the first and last lines from what we'll be adding.

 

So first, setup your controls. My tutorial on how to do this with events explains how to set up the controls so they can be used effectively in scripts.

 

look for the script "Scene_Map"
Go to line 47, which should look like this

  def update
Highlight everything from that line down to 154
in other words, highlight the lines that define the function "update"

 

CTRL+C them and paste them into a new script above main, but below Scene_Map


Making a use for useless keys/buttons

Go down to around line 79.
You should see this:

# If B button was pressed
    if Input.trigger?(Input::B)
      # If event is running, or menu is not forbidden
      unless $game_system.map_interpreter.running? or
             $game_system.menu_disabled
        # Set menu calling flag or beep flag
        $game_temp.menu_calling = true
        $game_temp.menu_beep = true
      end
    end

 

This is super important. Here's what it does:
While on the map, if the "B" button is pressed (ESC key by default)
unless an event is running or the menu is disabled
open the menu

 

Pretty simple
Now copy/paste that below itself, but separate enough so you can clearly see where the new one is.
The first thing to do is to replace the "B" with the button you're using to make the player sprint.

 

In my game, I added this:

    # If A is pressed
        if Input.trigger?(Input::A)
      # If event is running, or menu is not forbidden
      unless $game_system.map_interpreter.running? or
             $game_system.menu_disabled
        # Set menu calling flag or beep flag
        $scene = Scene_Quest.new
      end
    end
to allow the player to access the quest log from the map whenever they want instead of using an event, or adding an option to the menu, which takes more time and takes up space in the menu.


Increasing player speed.

You should now have something like this:

    # If B button was pressed
    if Input.trigger?(Input::X)
      # If event is running, or menu is not forbidden
      unless $game_system.map_interpreter.running? or
             $game_system.menu_disabled
        # Set menu calling flag or beep flag
        $game_temp.menu_calling = true
        $game_temp.menu_beep = true
      end
    end

 

Next, delete the unnecessary " or $game_system.menu_disabled"
part, since we want the player to be able to sprint even if they can't pause.

 

Then replace

# Set menu calling flag or beep flag
$game_temp.menu_calling = true
$game_temp.menu_beep = true
with
$move ="@move_speed = 5"
$game_player.instance_eval($move)
so you'll have
    # If B button was pressed
    if Input.trigger?(Input::X)
      # If event is running, or menu is not forbidden
      unless $game_system.map_interpreter.running?
      $move ="@move_speed = 5"
      $game_player.instance_eval($move)
      end
    end


But what if the player isn't holding the button?

Below "$game_player.instance_eval($move)"
add:

        else
          unless $game_system.map_interpreter.running?
          $move ="@move_speed = 4"
            $game_player.instance_eval($move)
          end

 

so then you'll have:

        if Input.trigger(Input::X)
          # If event is running
          unless $game_system.map_interpreter.running?
          $move ="@move_speed = 5"
          $game_player.instance_eval($move)
        else
          unless $game_system.map_interpreter.running?
          $move ="@move_speed = 4"
            $game_player.instance_eval($move)
          end
        end
      end

 

finally, to make it so a switch is required to be on, add "if $game_switches[3] == true" right above " if Input.trigger(Input::X)" and an "end" right below the other 3 ends

 

You can use the

 if Input.trigger(Input::X)
CODE
end
thing to setup lots of cool stuff like custom battle systems and a jumping system, which is more complicated, since the you need to tell the game not to jump onto certain tiles and to jump over others.

 

UPDATE:
It should actually look something like this.
"SHIFT" makes only the shift keys work for this.

    # If Run is enabled
    if $game_switches[9] == true
      if Input.press?(Input::SHIFT) == true
        unless $game_system.map_interpreter.running?
        $move = "@move_speed = 5"
        $game_player.instance_eval($move)
        end
      end
      if Input.press?(Input::SHIFT) == false
        unless $game_system.map_interpreter.running?
        $move = "@move_speed = 4"
        $game_player.instance_eval($move)
        end
      end
    end
This should fix the issues that parallel processes cause as well as actually work properly.


Setting up bar colors

Ever wanted to display HP as a bar instead of just a number?
Well it's actually pretty simple. There are many ways of doing this, but this is the easiest.

 

All you have to do, is make a new script with class "Window_Base "
This will work with any script so don't worry about messing up your windows. This will only add to them

 

First add a function like this:

  def bar_color(n)
    case n
      when 0
        return Color.new(32, 31, 65)  # background
      when 1
        return Color.new(0, 235, 1)  # HP
      when 2
        return Color.new(0, 0, 255)  # MP
      when 3
        return Color.new(255, 0, 0)  # red
      when 4
        return Color.new(220, 220, 220) # EXP 2
      when 5
        return Color.new(206, 206, 206) # EXP
    end
  end
This is where we edit the bar colors
The first one is the color for the border around the bar. I have mine set to a weird dark blue color because I'm using 2 bar scripts. It's complicated.
Anywho, the next 2 are obviously HP and MP and then red(which i haven't used, so I'm not sure why I left it there), and EXP 2, and EXP.
EXP 2 is for making a second bar that is a slightly different color to add a shiny effect to the bar.

 

the colors of course, are set up like this: (Red, Blue, Green) 255 being full saturation and 0 being none.
Use your favorite image editor to decide what colors you want for your bars and add any colors you want if you want a shiny bar effect like this:

 


Making an HP or MP bar

  # HP
  def draw_hp_bar(actor, x, y, w = 100)
    hp = actor.hp
    max_hp = actor.maxhp
    border_color = bar_color(0)
    health_color = bar_color(1)
    hp_percentage = hp * 1.0 / max_hp
    health_fill = w * hp_percentage
    border = Rect.new(x - 1, y, w + 2, 8)
    health = Rect.new(x, y + 1, health_fill, 6)
    self.contents.fill_rect(border, border_color)
    self.contents.fill_rect(health, health_color)
  end
this will tell the game what to do when you type
"draw_hp_bar(@actor, 100, 50)" in your menu script

 

a lot of this is defining variables and, if you've read my first tutorial, this should all be pretty easy to figure out.
hp = actor.hp is "variable called 'hp' means the actor's current hp"

 

the bar colors is where you decide which color you want this bar to be. 0, 1, 2, 3, 4, etc.

 

hp_percentage and health_fill are the formula for how much the bar will be filled based on how much HP the character has.
w is the width of the bar when it's full in pixels. the "w=100" at the top just means that, if you don't put a value for w when calling this function, then the width will default to 100 pixels.

 

rect.new calls a rectangle. rectangles obviously allow you to make windows and bars and even pictures using only scripts.


Adding the shiny effect

to add the shiny effect to your bar, just add a couple lines

 

add the following below "health_color = bar_color(1)"

health2_color = bar_color(n)
n being the number of your second hp color

 

health2 = Rect.new(x, y-1, health_fill, 4)
would go right under "health ="
the numbers will probably need to changed a bit.

 

and

self.contents.fill_rect(health2, health2_color)
will go at the bottom above "end"

 

and then, to add it to your windows, just put something like
draw_hp_bar(@actor, 100, 50)


Making an EXP bar

EXP bars are a bit more complicated
before the "class Window_Base"
you'll want edit "class Game_Actor < Game_Battler"
and add

  def needed_exp(current_level)
    return @exp_list[current_level + 1] - @exp_list[current_level]
  end
 
  def gained_exp(current_exp, current_level)
    return current_exp - @exp_list[current_level]
  end
to tell the game how to check the player's current EXP and EXP needed to lvl up

 

so the code above class Window_Base should look like this:

 

class Game_Actor < Game_Battler
       
  def needed_exp(current_level)
    return @exp_list[current_level + 1] - @exp_list[current_level]
  end
 
  def gained_exp(current_exp, current_level)
    return current_exp - @exp_list[current_level]
  end
end

 

then, replace the

exp_percentage = blah blah
exp_fill = w * exp_percentage
part with

 

exp_fill = (gained_exp * 1.0 / needed_exp) * w
no need for the "exp_percentage" part.


Limiting Max Stats

I know for sure that this will let you lower the limits and probably will let you increase them, but you'll have to test that. There are plenty of scripts for increasing stat limits though.

 

Anywho, this is a super simple way to force the player's stats to max out at 100, or 255, or something.
This should work with any script since it literally only effects how stats are determined. You can even use this to edit custom stats if you already have a custom stat script.
This will NOT let you ADD custom stats however.

 

First, go to Game_Actor and scroll down to line 173
highlight everything from there down to line 316
Copy/Paste it to a new script below any Game_Battler/Game_BattleAction script
and add, to the very top "class Game_Actor < Game_Battler"

 

The first two "9999"s are for the Max HP
This hasn't been tested, but changing this SHOULD change the max HP

 

everything that follows HAS been tested, however.


Limiting STR, DEX, AGI, and INT

These stats are the easiest to limit since the code for them isn't stupid.

 

I'll use STR as an example.

def base_str
    n = $data_actors[@actor_id].parameters[2, @level]
    weapon = $data_weapons[@weapon_id]
    armor1 = $data_armors[@armor1_id]
    armor2 = $data_armors[@armor2_id]
    armor3 = $data_armors[@armor3_id]
    armor4 = $data_armors[@armor4_id]
    n += weapon != nil ? weapon.str_plus : 0
    n += armor1 != nil ? armor1.str_plus : 0
    n += armor2 != nil ? armor2.str_plus : 0
    n += armor3 != nil ? armor3.str_plus : 0
    n += armor4 != nil ? armor4.str_plus : 0
    return [[n, 1].max, 999].min
  end
the "999" just needs to be changed and you're done.

 

adding another "n+=" at the bottom will allow you to combine it with another stat, variable, or custom equipment slot for whatever reason
e.g. "n+= actor.dex" would make it so your dex is always added to your str so if you have 10 dex and 10 str, your str would actually be 20.


Limiting ATK

These ones are a little harder to edit, only because the way they're done seems to be based on the idea that no one would ever want to edit the battle system or how the stats are handled. "Which is gay as tits" -Tomo2000

 

I'll start with ATK since it's the weirdest.

  def base_atk
    weapon = $data_weapons[@weapon_id]
    return weapon != nil ? weapon.atk : 0
  end
srsly guyz? I know it's only determined by the character's weapon, but still.

 

All you really need to do is add
n = 0 above "weapon ="
and then
n += weapon != nil ? weapon.atk : 0
(look familiar?)
above return and below weapon =

 

and then, replace the return line with "return [[n,0].max, 999].min"
and then change 999 to your favorite limit. This isn't really important most of the times though since there's only one way to increase ATK in game, but could help with scripts that allow for two handed weapons and dual wielding.


Limiting PDEF, MDEF, and EVA

If you want to have two armors that go in different slots, but increase the same stat, and you don't want that to make the player's stats go higher than a certain number, you're going to want to set a limit for these stats.

 

by default, you have this scary looking thing for PDEF

  def base_pdef
    weapon = $data_weapons[@weapon_id]
    armor1 = $data_armors[@armor1_id]
    armor2 = $data_armors[@armor2_id]
    armor3 = $data_armors[@armor3_id]
    armor4 = $data_armors[@armor4_id]
    pdef1 = weapon != nil ? weapon.pdef : 0
    pdef2 = armor1 != nil ? armor1.pdef : 0
    pdef3 = armor2 != nil ? armor2.pdef : 0
    pdef4 = armor3 != nil ? armor3.pdef : 0
    pdef5 = armor4 != nil ? armor4.pdef : 0
    return pdef1 + pdef2 + pdef3 + pdef4 + pdef5
  end

 

What you need to edit is actually pretty similar to what we added to ATK

 

n = 0 at the top, and then, replace the 5 lines of "pdef1, pdef2, etc." with

 

    n += weapon != nil ? weapon.pdef : 0
    n += armor1 != nil ? armor1.pdef : 0
    n += armor2 != nil ? armor2.pdef : 0
    n += armor3 != nil ? armor3.pdef : 0
    n += armor4 != nil ? armor4.pdef : 0
This does pretty much the exact same thing, it just means you'll need to change the "return" line to something that looks a little scarier, but lets you change the limit.

 

It's probably pretty obvious now, but just replace the "return" line with
return [[n, 0].max, 999].min
change the "999" to your stat limit and you're done.

Share


About the Author

Comments

1,923 Posts
2,504 Points

Bob423  said 1st January 2014

Added some stuff about HP bars and stat limiting *grin*

1,923 Posts
2,504 Points

Bob423  said 15th April 2014

Update for step 4! "But what if the player isn't holding the button?"

 

It should actually look something like this.
"SHIFT" makes only the shift keys work for this.

    # If Run is enabled
    if $game_switches[9] == true
      if Input.press?(Input::SHIFT) == true
        unless $game_system.map_interpreter.running?
        $move = "@move_speed = 5"
        $game_player.instance_eval($move)
        end
      end
      if Input.press?(Input::SHIFT) == false
        unless $game_system.map_interpreter.running?
        $move = "@move_speed = 4"
        $game_player.instance_eval($move)
        end
      end
    end

 

This should fix the issues that parallel processes cause as well as actually work properly.

Quick Reply

Guest

Enter a username

Security check: What is 8 plus 2?