HOW TO STEAL LIKE A HERO

A tutorial on Hero's Realm Steal command (RM2k3)

  • kentona
  • 06/19/2007 12:00 AM
  • 4971 views
Steal like a Hero
A tutorial on Hero's Realm Steal command by kentona

This tutorial outlines the steps you need to take to implement a Steal command similar to the one found in Hero's Realm. That is, a Steal command that targets a single monster, and has a chance to steals a common item (a chest), where that chance depends on the relative agilities of the Hero and the targetted monster.

Prerequisites

10 Switches
Steal_GO The steal command has been issued
StealTarget1_DONE Monster 1 has been successfully stolen from
StartTarget2_DONE Monster 2 has been successfully stolen from
StartTarget3_DONE Monster 3 has been successfully stolen from
StartTarget4_DONE Monster 4 has been successfully stolen from
StartTarget5_DONE Monster 5 has been successfully stolen from
StartTarget6_DONE Monster 6 has been successfully stolen from
StartTarget7_DONE Monster 7 has been successfully stolen from
StartTarget8_DONE Monster 8 has been successfully stolen from
Chest_OPENED Switch thrown when a chest is opened

4 Variables
RandomNumber Variable used to hold a randomly generated number
AGL_Hero Variable used to hold a hero's agility value
AGL_Monster Variable used to hold a monster's agility value
StealRnd Variable used to hold the Steal random number

1 special item
Chest The item that you steal from monsters

1 Skill
Steal The skill selected when you want to steal

1 Battle Command
Steal The battle command that contains the Steal skill

1 Condition
No Item The condition inflicted upon stolen from enemies

1 Attibute
StealAttr The steal attribute - just something to check for your Steal skill

1 Battle Event
Steal The single battle event that holds all your stealing code

2 Common Events
Chest A common event that is run when you open a chest
AfterBattle This common event is to run after battle to turn off the StealTarget_DONE switches


4 Battle Animations
Steal Animation A little anim played when a character attempts to steal
Steal Successful! Anim played when a steal attempt is successful
Couldn't Steal! Anim played when a steal attempt is unsuccessful
Has no item! Anim played when a steal attempt is performed on a monster with no item left


Set Up

This section describes the steps you need to take to set up the Steal command.

The idea is to have a single target Skill under a Steal battle command that steals a common item called Chest, which itself will call a common event that gives you a random item. I used the Chest concept to ease the burden of working with Battle Events - I didn't have to worry about giving each monster it's own item in each and evey one of the battles, which is tedious and time consuming. I'm a copy & paste kinda guy.


1. The Steal skill
Basically, you set up a Battle Command of type Skill Subset, a skill called Steal that targets a single enemy that inflicts a No Item status that uses a StealAttr attribute.
a. Under the Battle Layout tab, set a new Battle Command
b. Add a new command called Steal and make it of the Skill Subset type.
c. Under the Conditions tab, add a new condition called No Item
i) Ends after Battle
ii) Priority 1
iii) Susceptibility at 100% to A B C D and E
iv) Abates after 1 turns
v) 100% chance of recovery
vi) 100% chance of recovery after hit
vii) No Restriction
d. Under the Attributes tab, add a new attribute called StealAttr of type Magic. % are irrelevant.
e. Under the Skill tab, add a new skill called Steal:
i) Type Steal (battle command)
ii) MP = 0
iii) Single Enemy
iv) Effect rating 0
v) 100 % Success rate
vi) Animation Movement: Move to Target (in a crouch stance, if possible)
vii) Animation: Steal Animation - A little anim played when a character attempts to steal
viii) 0 to all the stats, 0 influence
ix) Condition: Inflict No Item
x) Attribute: StealAttr


2. The Chest item
You add a Switch item that turns on a switch that activates a autostart common event which in turn adds a random item to your inventory
a. Under the Item tab, add a new item called Chest
i) Type: Switch
ii) Price: 0 (or whatever you want, if you would like to be able to sell unopened chests)
iii) Number of uses: 1
iv) "Something is hidden inside..."
v) Turn ON switch; Chest_OPENED
vi) Use: Field only.
b. Under the Common Events tab, add a new common event Chest
i) Trigger: Auto-Start
ii) Trigger Switch: Chest_OPENED

Now, the common event should be tailored for your game, but I'll describe what I did for Hero's Realm:


Message: \N[0] opens the chest...
Variable: [XXXX: RandomNumber], set Rnd[0-7]
Branch if Var [XXXX: RandomNumber] is 0
Variable: [XXXX: RandomNumber] Set Holdana Level
Variable: [XXXX: RandomNumber] * Party Size
Change Money: [XXXX: RandomNumber] Add
Message: Found \V[XXXX] gold!
: End
Branch if Var [XXXX: RandomNumber] is 1
Change Items: [Medicinal Herb] Add
Message: Found Medicinal Herb!
: End
[i]....etc etc for each item...[/i]
Switch Operation: [Chest_OPENED] OFF



3. The Battle Event
There are actually 8 different types of battle events, but only 1 would be in any particular battle. It depends on how many monsters appear in the battle. I will describe a 1 monster battle, but indicate where you have to duplicate code for multiple monsters.

a. Add a new blank Page to the Battle Events
b. Trigger: Turns Elapsed
c. Now, for each character that can Steal, add this:\


Branch if [Bob] [Steal battle command] Used
Switch Operations: [Steal_GO] ON
Variable Operations: [XXXX: AGL_Hero] Set, [Bob] Agility
: End

Save the hero's agility (used later) and turn on a switch so we know Steal was enacted. Repeat for each hero.

d. After all that, within the same battle event, add this code:


Branch if Switch [Steal_GO] is ON
Switch Operation: [Steal_GO] OFF
Comment: Steal was called, check to see if monster 1 was targetted
Branch if 1:Greywolf Targetted
Comment: Has monster 1 been stolen from already?
Branch if [StealTarget1_DONE] is ON
Comment: Show the Has no item animation
Show Battle Animation: [Has no item!], 1:Greywolf
: Else Handler
Comment: This is the actual Steal code
Variable Operation: [XXXX: AGL_Monster] Set 1:Greywolf Agility
Variable Operation: [XXXX: AGL_Monster] + Var[XXXX: AGL_Hero]'s value
Variable Operation: [XXXX: StealRnd] Set, Rnd [80-120]
Variable Operation: [XXXX: AGL_Hero] * Var[XXXX: StealRnd]'s value
Variable Operation: [XXXX: AGL_Hero] / Var[XXXX: AGL_Monster]'s value
Variable Operation: [XXXX: RandomNumber] Set, Rnd[1-100]
Branch if [XXXX: RandomNumber] is [XXXX: AGL_Hero] Less/Equal
Comment: Steal Attempt was successful!!
Change Items: Chest 1 Add
Switch Operations: [StealTarget1_DONE] ON
Show Battle Animation: Steal Successful!
: Else Handler
Show Battle Animation: Couldn't Steal!
: End
: End
: End
Comment: If there was more than one monster, the code for that monster would go here.
Comment: ...Starting with "Branch if 2:Leafer Targetted ...etc...
: End


Now, this might be a little confusing, but let me explain my reasoning.

The formula I am implementing is this:

(([Hero's Agility] +/- 20%) * 100) / ([Monster's Agility] + [Hero's Agility])


or in english:

The Hero's agility, plus or minus 20%, divided by the sum of Hero's Agility and the targetted monster's agilty, all multiplied by 100.

The result of this will (almost) never be greater than 100. The +/- 20% just adds a little randomness to the equation, and the Multiply by 100 thing is used since RM2k3 can't handle fractions. After calculating the formula, I generate a number between 1 and 100 and if the formula's result is greater than the random number, the Steal is successful. But let's go through some examples to test the results.

Let's say the Hero and the Monster have the same agility (ie- 25), and let's ignore the +/- 20%. Plugging in the numbers, we get this:

(25 * 100)/(25 + 25) = 2500/50 = 50

So, this indicates that we have a 50% success rate (when we compare it against a randomly generated number between 1 and 100). Which seems reasonable considering the hero's agility is the same as the monster's.

Now let's say the Hero has 4x the agility than the monster (ie- 100 vs 25). Again, ignoring the 20%...

(100 * 100)/(25 + 100) = 10000/125 = 80

So, this indicates that we have a 80% success rate, which, too, seems reasonable considering the hero's agility vastly outranks the monster's.

Flip the situation and let's say the Hero has 1/4 the agility of the monster (ie- 25 vs 100). Again, ignoring the 20%...

(25 * 100)/(100 + 25) = 2500/125 = 20

So, this indicates that we have a 20% success rate. Neat, eh?

The beauty of this formula is that the actual values of the agilities is completely irrelevant - it's the relative values that matter. Now, working in the +/- 20%, it just affects the final result, really. So, without the +/-, if it is 50%, then after applying the +/- 20%, your result would range between 40% to 60%. For base 80%, it'd range between 64% and 96%. On a side note, only if you have a base greater than 83% and were lucky enough to get a +20% would you have a Steal % > 100%.

NOTE:
For multiple monsters, you would copy the code contained in the "Branch if 1:Greywolf Targetted" block and replace 1:Greywolf with 2:Leafer, and StealTarget1_DONE with StealTarget2_DONE. Rinse and repeat for more monsters. Make sure that the number of blocks match the number of monsters in the battle or you get "Target not defined" crashes. To save work, I make 8 different battles, for monster groups containing 1, 2, 3...8 monsters, and customize my Steal battle event to 1 thru 8 monsters. Then, when I want a new monster group, I copy the appropriate base group, and replace those monsters with the desired ones for my new monster group.

NOTE 2:
For those of you with a lot of time on your hands, you could just ignore the Chest idea and customize FOR EACH BATTLE and FOR EACH MONSTER what item they have for you to steal. I would not recommend this.


4. The Clean Up
After every battle, you need to turn off the StealTarget( 1 thru 8 )_DONE switches. Otherwise, you'd only ever be able to steal once per game, which would suck.

Now, I have a common event that runs after every battle, that handles all of my after battle clean up, which happens to include StealTarget1_DONE: OFF etc.. stuff. How you handle this is up to you.


5. Applying the skill
To use the Steal skill, give a Character (or Class) the Steal battle command and the Steal skill. Voila.

To use it in a battle, choose the Steal command, "cast" the Steal skill and select the monster you wish to steal from. If you are lucky, you'll steal an item. After the battle, you can go to your inventory and open the Chest you stole and get a random item!? Yay!



Conclusion
This concludes the tutorial on Steal like a Hero.

For questions or comments, email kentona at kenton007@hotmail.com or PM me in the RMN forums. Thanks for reading!

Posts

Pages: 1
Complex, but more than worth it. Thanks for sharing your trade secrets with us, Kentona!
This is all very impressive. Not going to use it myself, but I had to at least try it out.
pianotm
The TM is for Totally Magical.
32388
This is a very nice system!
author=pianotm
This is a very nice system!
I've improved it in later games by extracting the "is the steal successful?" code to a common event that the Battle Event calls. So I set the HeroAGL, set the MonsterAGL, and call a STEAL_CHECK common event.

That way, if I want to tweak how I do the calculation for successful stealing checks, I only have to do it once, instead of 4000 times for every battle event. The common event sets a boolean "STEALsuccess" True/False and the battle event simply checks to see if the steal check was successful or not, and show the associated battle anim.

You could further improve it by setting some sort of "ItemID" or "MonsterID" variable in the battle event, and have the Common Event manage what the party receives as an item, based on a lookup (ie- if "MonsterID == 14" (the greywolf), then give the party a Wolf Pelt item on stealSuccess==TRUE). That way both the steal check and the steal item reward is managed in a single place, instead of duplicated across 400 battle groups.
pianotm
The TM is for Totally Magical.
32388
Since the most important part of this goes into troop events, I've simply created a range of chest items and given them their own switches (I probably could have nested some branches and put them all in the same common event, but it was easier just to make separate common events for the chests.). I'm not going super specific. Just a range of level-appropriate items. Like...a slime isn't going to drop Excalibur, but it'll drop potions and mana potions.

Then I just have those different items for different troops.
OzzyTheOne
Future Ruler of Gam Mak
4696
Am I missing something? I don't think the "No Item" state gets referenced anywhere, as in, a enemy gets afflicted with it, but nothing checks if an enemy has said state on them.
OzzyTheOne
Future Ruler of Gam Mak
4696
I found out why you put that in! In case a damage doesn't deal any damage, and doesn't inflict any state, it always shows as having missed. But if a skill deals no damage but inflicts a state, it doesn't show as having missed.
Pages: 1