Summon Shield

Reddit user bik1230 wants to give his warrior the ability to equip a shield mid-battle. In fact, the party doesn’t even need the shield in the inventory – the warrior will summon the shield, equip it for a few turns, and then the shield will break. Because of potential abuse, we don’t want the shield to stay in inventory after battle is over, otherwise the player could have a limitless supply of shields to sell. Think of this like a defense boost, but with an inventory item attached to it.

Let’s get started!

States, Skills, and Shields

You’re going to need a handful of basic things in the database for this to work. Specifically, you’ll need:

  1. A skill – the actual skill that the warrior casts to equip his shield. You’ll need to set the resource costs (things like TP or MP), animations, graphics, etc. accordingly
  2. A state – specifically a dummy state. I talked about why we want dummy states in a previous post.
  3. The shield – the shield you want the warrior to equip. It can be something already in your game which the player can find/buy, or it can be a shield made only for this purpose. The choice is yours!

Once you’ve got all three in place, we’ll move on to….

Common Events

This skill is a big one – it takes 3 common events to do well. We need one event to equip the shield, one to remove it after a time limit, and one to remove it at the end of battle.

Equipping the Shield

Equipping the shield itself is pretty easy, and can be done exclusively with event commands. You’ll need to add the shield to inventory, equip it, and show a little text.

Our first common event - Equipping the Shield. MAKE SURE YOU ADD IT TO THE INVENTORY BEFORE EQUIPPING IT!

Our first common event – Equipping the Shield. MAKE SURE YOU ADD IT TO THE INVENTORY BEFORE EQUIPPING IT!

We add it to inventory because that “Equip” function won’t do anything if the party doesn’t have the shield! Also, the text lets us know that the skill was used successfully.

Here’s the catch: we probably don’t want this skill to work if the player already has a shield equipped. There are two ways we can do this. We can make it so that the skill fails if the player has a shield equipped, or we can seal the skill (prevent the player from ever using it) if he already has a shield.

Failing the skill means that we use a conditional branch in the common event. If the player doesn’t have a shield equipped, we do everything we just covered; but if the player has a shield equipped, we say “Eric’s already got a shield equipped!” To check to see if Eric has something in the shield slot, we use a script call in a conditional branch:

$data_armors.index($game_actors[1].equips[1]) == 0

So our common event would read:

With this method, Eric won't equip a shield if he already has one he's using - but he'll still expend the resources, and waste his turn.

With this method, Eric won’t equip a shield if he already has one he’s using – but he’ll still expend the resources, and waste his turn.

This is nice and clean, but feels a little mean to the player. The player can potentially expend resources in battle to cast Summon Shield, and then get nothing out of it. So if we want to be nice to the player, we can seal that skill if they have a shield equipped. We do this in the “features” section of each shield.

To prevent Eric from using the skill if he already has a shield equipped, you need to add this feature to *every possible shield* Eric can equip - including the summoned one.

To prevent Eric from using the skill if he already has a shield equipped, you need to add this feature to *every possible shield* Eric can equip – including the summoned one.

This is nicer to the player, but if you have 100 shields to add this feature to, can get a little tedious. The choice is yours.

Controlling a Turn Variable

The last thing we need to do is set a variable to the number of turns the shield will last. Do this after the shield is equipped. In general, you’ll want 1 more turn than you think you need – 1 turn will be used when the warrior actually casts Summon Shield.

Remember the ID of the variable (here, 0001) - we'll need it later.

Remember the ID of the variable (here, 0001) – we’ll need it later.

Removing the Shield

We now need two common events that look almost identical. One for if the shield is removed in battle, the other if battle is over before our number of turns has expired. For the first, we’ll de-equip it, remove it from battle, and use a little text to say that Eric’s shield is gone.

This common event triggers if the length of the skill ends but the player is still in battle.

This common event triggers if the length of the skill ends but the player is still in battle.

The second will need a conditional branch (asking whether there are still turns left on our variable), and will do the same thing. We probably don’t need any text though – this is going to be called after battle is over. Think about how you’d like poison to work if it was removed at the end of battle. You wouldn’t expect a little text pop-up telling you every time “Oh, FYI, poison was removed.”

This common event will trigger if the player wins (or escapes, or loses) the battle before the shield breaks - we still need to get it out of Eric's hands.

This common event will trigger if the player wins (or escapes, or loses) the battle before the shield breaks – we still need to get it out of Eric’s hands.

Calling the Common Events

Here’s where things get tricky. We need to call all 3 of our common events at the right time. Let’s start with the first, equipping the shield. We’ll call it in the skill itself.

Shield7

The dummy state is to take care of text; the Common Event is to actually handle our logic every time the skill is used.

 

As I mentioned a little while ago, we use the dummy state so we don’t get some error message like “It had no effect on Eric!” every time you cast it. We do it purely for aesthetic reasons, it has no real impact on the game.

We need to call the remove-in-battle common event once the turns have expired. Specifically, at the end of each turn, we want to decrement our variable by 1 and, if it’s 0, call the event. I’ve discussed an extremely similar concept in the Arrow Rain skill tutorial I wrote a while back. As a reminder, we need to put a little script call into the function “turn_end” under Scene_Battle. Something like:

class Scene_Battle
  alias :old_turn_end :turn_end

  def turn_end
    if $game_variables[n] > 0
      $game_variables[n] -= 1
      $game_temp.reserve_common_event(y) if $game_variables[n] == 0
    end
    old_turn_end
  end
end

In the above script, replace “n” with the ID of the variable you’re storing turns in. Replace “y” with the ID of the common event you want to call – here, removing shield when the correct number of turns expire. The script checks to see if the variable is above 0 – if it is, decrement by 1 and, if it’s now at 0, remove the shield.

Finally, we need to call our last common event – removing the shield if the entire battle is over. In your Scripts, under BattleManager, go to about line 268, where you’ll see a section captioned “*End Battle.” There, in the function, we’re going to add a line to call our common event. Specifically:

$game_temp.reserve_common_event(x)

Where x is, you guessed it, the ID of our final common event. This is the function that happens when battle is over – whether that’s a win, lose, or escape situation. Perfect for taking away Eric’s shield after battle.

Be careful modifying the base script - since we're only adding one line here, it's not a big deal. But don't play around unless you know what you're doing ;)

Be careful modifying the base script – since we’re only adding one line here, it’s not a big deal. But don’t play around unless you know what you’re doing 😉

Wrap-Up and Challenge

Give it a whirl and see how it looks – you may notice things you want to change like the duration of the buff, the text, how the ability actually functions. All of those things can be tweaked using the method above. Here’s a little challenge for ya. How can we make a similar skill that summons a sword (instead of a shield) which lasts so long as the player attacks with it? The turn that a player doesn’t attack with a sword, the summoned sword will disappear.

We’ll talk about answers in the coming weeks!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s