Part Two: It's Time for School!

Part A: Shooting Practice
After reading part 1 of this installment, you should have a primitive strike and strike back battle engine. But the player can't learn moves and the enemy only gets one attack. Remember the two groups you created at the end of Part 1 called "Level UP" and "Level UP Yes"? Now we are going to use those. The first group is not as complex as the second group. Think of the first group as a button and the second group as the computer. You push the button to turn the computer on. The button is a simple device with only the function of turning the computer on. The computer, on the other hand, is much more complex with hardware, operating systems, applications, etc that can or can not be turned on. With that basic understanding in place, lets begin.
Inside the "Level Up" group the first thing we need to take care of is not the level up code. First, we need to do updating. If you remember, every time the player levels up is the result of a pirate getting destroyed. Also, the pirate is regenerated each time he does get destroyed. But what if the regeneration was stopped midway because of a level up? The health wouldn't be right. So, first, we need to establish the pirates health so it looks right. The code is very simple:

CONDITIONS
Number of Pirate >= 0
EVENTS
Pirate: Set PirateHealth to 100
END

The player has to be notified somehow that they are going to learn a new move. So lets make a string object and put it below the interface. Lets call it, “InfoStr”. That way we know that any relevant information will be placed here. Set its text box to say "Ready...". Now, back in the event editor, in the group “Level UP!” we need to add some new code. In order for this to work, we need a few things. First, we need to ask the player if they want to learn a new move. Then, we need to gather their choice whether it be yes or no. If it is yes, we move on to ask them to forget a move (which is handled in another group). If not, then we need to resume play as normally. The yes/no system is very simple and requires a couple simple loops and a text box and some user input. To begin, first we need to check for the group to be active. Then, we need to ask the player if they want to learn a new move. This code is very simple:

CONDITIONS
Group “Level UP” is activated
EVENTS
InfoStr: Set alterable string to “Learn new move? Y/N”
END

Now that was simple wasn’t it? Now we need to get some input from the user. As you may have guessed, this is a key press of either Y or N. On the Y press, we need to do a couple things. First, we need to activate the group level up yes. Then, we need to deactivate the group “Level Up”. We need to activate the group first because input would not be correct or it wouldn’t work if we didn’t. Trust me, I’ve tried. So, what if the player doesn’t want to learn any new moves? Simple. We deactivate the “Level Up” group and return to the “Hunters” group. To get a yes answer from the player, simply code the following:

CONDITIONS
Upon pressing “Y”
EVENTS
Stop loop “Move”
Activate group “Level UP Yes!”
Deactivate group “Level UP”
END

HEY now, you say, where’d that other loop come from!? Well, let me tell you. When I first started doing this several months ago, I thought that a loop would be best to tell the computer that something is happening. So I plugged it in and had a few problems. So I thought, hmm, lets take the loop out. So I did, and I must have forgot about that piece or it is a necessary part. I do not know which. So, its going to stay there, for I have no desire to split up and rip out and dissect the program while accomplishing nothing but a headache and wasted time. Now, the rejection code is a little different. First, we have to get key press input, then, we need to stop one loop and start another, and have the loop go around once. Then, during the second loop, stop the new loop, activate and deactivate different groups. It’s a lot simpler then it sounds really:

CONDITIONS
Upon pressing “N”
EVENTS
Stop loop “Move”
Start loop “Move No” 1 times

CONDITIONS
On loop “Move No”
EVENTS
Stop loop “Move No”
Activate group “Hunters Turn”
Deactivate group “Level Up”
END

Now, that was very simple wasn’t it. Just a few lines of code and not much fuss. This next part, however, made me almost lose my mind! =< You’ll see why later. But first, some coding. Now, if the player wants to learn a new move, we need to give them the opportunity to do so. And the option to learn a few new attacks. Since we have only four slots at the beginning at the game, we need to check for key presses 1,2,3, and 4. Then we need to match the new move with the appropriate level. We do this by checking the value of the “NewSkill.” Again quite simple. While on key press, we need to set a couple things about the new move. We need to set its skill position according to the key and we need to set its flag 0 on.
If you have any buttons for numbers, then enable the corresponding button with the number pressed and disable the rest. Remember the first four moves? Well, suppose the player would want to keep that move for a while, then, once they got a more powerful move and wanted to delete the old one, they should be able to. To do this, we need to set the first flags skill position to 0 and set its flag 0 off. Now, why should this be such a problem? Perhaps you’ll understand it better in code. Remember, the buttons are for graphical purposes only. I’m only going to do one number for example purposes right now, not all four. So, lets say the move is dark crusher, the code should look like this:

//The first thing we need to do, is start a loop and tell the engine what to do with it.
//First, check to make sure the group is active.
CONDITIONS
Group “Level Up Yes” is active
EVENTS
Start loop “Move Yes” 1 times
//The loop is to insure that nothing else can happen during game play, and that the process will //not be interrupted until the loop is over.
CONDITIONS
On loop “Move Yes”
EVENTS
InfoStr: Set alterable string to “Forget which one move: 1,2,3,4? Press control when finished.”
//Not only does this inform the player that the engine is ready to begin with a new move, it also //tells the player which keys to press.
END
Now, on to the Activation Deactivation system. This segment of code does a few things. First, it turns the beginning move that corresponds with the number off. Then, it turns the new move on. Take note that once a move has been selected, it is impossible to turn it back on. Therefore, limiting the user to only one move choice. It also changes the shelf to the slot of the corresponding number.

CONDITIONS
Upon pressing “1”
Newskill of Hunter is = 13
//The newskill number is a variable. It represents the level that the player is at which signifies that //the player can learn a new move.
EVENTS
Dark Crusher: Set Skill Pos to 1
//Stupid spell checker. The skill Pos is supposed to be one word. I kept getting scallops out of //it so I had to split it.
Dark Crusher: Set internal flag 0 on
//Now, why is the flag being turned on at this point? Because that tells the engine that the move //is learned. When it is off, it does not appear in the text box nor does it appear as a shot.
SkillSelector: Change animation sequence to shelf 1
//If you have buttons, you should disable the ones that aren’t selected and enable the one that is. //In this case, it would be button one enabled, and the others disabled.
Button 1: Enable
Button 2: disable
Button 3: disable
Button 4: disable
//Remember the first move? Well, we have to make sure that that move is forgotten when //replaced by the new one.
Fireball: Set skill pos to 0
Fireball: Set internal flag 0 off
END
//Press control to confirm the selection
//this is only inputted after the code that deals with the fourth slot
CONDITION
Upon pressing “Control”
EVENTS
Special: Deactivate group “Level UP Yes”
Special: Activate group “Hunters Turn”
Special: Stop loop “Move Yes”
END

Now, that wasn’t so bad, was it? Now, you might be wondering what the skill pos is for. You may be thinking that it might have something to do with the skillselector, but it doesn’t. What it does is tells the engine what text box to change according to the value number. If you’ve read part I, then you remember I had you program all the attacks at once in the hunters group. Now, in the code, when pressing control, if the moves internal flag 0 was on, and if the skill position value of the skill selector matched the skill position of the move, then the player would fire the move. Two things have to be correct that we just set in the above code, first, the flag 0 has to be on, and the move position must match the selector position. Well, this should be easy to do right? Perhaps to some of you. Lets use our first new move as an example. The first new move from part 1 was called Ground Gulp. Now, what we’re doing, is putting the move name in the text box based on its skill position value. Go back to the hunters group and begin the following code underneath the last code. (Which should be the condition Level of Hunter is equal to four, then it sets positions, flags, and text boxes.) :

CONDITIONS
Skill pos of Ground Gulp = 1
//Remember that ground gulp is the first new move
EVENTS
Fireball: Set skill pos to 0
StringMove1: Set alterable string to “Ground Gulp”
//We need to set the skill position to 0 so it won’t show in the text box.

Well, that’s good, you think. Now the program knows which attack is where and puts it in the proper place. We clear up the fact that the fireball no longer is the first move and does not need to be concerned with any more. It also sets the text box with the correct message. SO, we have one spot taken care of, but what about the other spots? There is a simple, yet time consuming solution to this. We need to check the skill position for each beginning move when we tell it to replace the text. As the player learns more moves, each move must be made to check for first, the beginning moves, then for the newer moves. Lets however, concentrate on only the first four. I’ll give another example, only replacing the second move:

CONDITIONS
//checking value
Skill Pos of Ground Gulp = 2
EVENTS
//the second move, omega-bolt, gets its skill pos value set to 0
Set Skill Pos of Omega-bolt to 0
StringMove2: Set alterable string to “Ground Gulp”

Now you should know what to do about the other 2 moves. Well, you say, supposing a more powerful move then ground gulp comes up and the player wants to forget ground gulp in favor of the new move? No problem here, just follow the same code skeleton. Checking the value, setting the old move to 0, and replacing the text. The same does not hold true for the “Level Up Yes” group. Yes, back to that now. You only know how to learn the first of the new moves and not the others. Well, the first part is simple, merely check for a key press and set some flags. For each new move that is learned, they have to be able to replace the first old moves and the newer moves as well. Let me show you what I mean. Lets use the next learned move as an example. In our case, this would be Crystal Spike:

CNDITIONS
//The basic system
Upon pressing 1...etc
Upon pressing 2...etc
Upon pressing 3... Etc
Upon pressing 4... Etc
//Then, what you need to do, is check with the new move matches the skill pos of any of the //older new moves. Then set its position to 0 and its flag 0 off
CONDITIONS
Skill Position of Crystal Spike = Skill Pos of Ground Gulp
EVENTS
Ground Gulp: Set Skill Pos to 0
Ground Gulp: Set internal flag 0 off

So basically what we’re doing is seeing if a newer move matches an older new moves values and if it does, we’re setting the older move off. We do not need to check for the values of the first four moves because those are taken care of with the key presses. Lets say the player has leveled up some and is getting ready to learn their last move. They have a nice variety and are getting ready to pick the replacement. But, how do we check for each new move and each previous move in each spot? Simple, just do the above and set values and flags for each learned move. Here’s an example using our last learned move, dark crusher:

//Remember, the first four moves aren’t taken care of here. Just all the learned one.
CONDITIONS
//Ground Gulp
Skill Pos of Ground Gulp = Skill Pos of Dark Crusher
EVENTS
Ground Gulp: Set Skill Pos to 0
Ground Gulp: Set internal flag 0 off
//Crystal Spike
CONDITIONS
Skill Pos of Crystal Spike = Skill Pos of Dark Crusher
EVENTS
Crystal Spike: Set Skill Pos to 0
Crystal Spike: Set internal flag 0 off
//Seedlings
CONDITIONS
Skill Pos of Seedlings = Skill Pos of Dark Crusher
EVENTS
Seedlings: Set Skill Pos to 0
Seedlings: Set internal flag 0 off
//Matter Bend
CONDITIONS
Skill Pos of Matter Bend = Skill Pos of Dark Crusher
EVENTS
Seedlings: Set Skill Pos to 0
Seedlings: Set internal flag 0 off

The only moves that the engine needs to worry about concerning their skill pos is the moves that will be learned. The reason is because the first four moves are taken care of with the key presses. So, to learn a new move, we must first check to see if the players level is equal to the stored value of new skill. If it is, we activate the group “Level UP” and ask the player if they want to learn a new move. If they say yes, activate the group “Level Up Yes” and start the activation deactivation code. If they say no, act as it never happened by deactivating group “Level Up Yes” and reactivating the group “Hunters Turn”. In the “Level Up Yes” group, however, ask the player which one move they are willing to forget. Tell them to also press control if they are finished. Then, check the key press for 1,2,3, or 4. On the key press, zero out the beginning move that corresponds to that number. This is done by setting the internal flag off and setting its skill position to zero. If there are other learned moves before this move, and they equal the new moves position, then zero out those as well. Remember, each key press and each learned move must be covered.
For example, a player can’t forget the old move number two if the new move they want to learn doesn’t support key press number 2. Or, if the player wants to learn a newer move, the newer move must make sure that any older moves don’t have its spot. If the player is sure about their choice, then on the control key press, the engine deactivates the “Level Up Yes” group and reactivates group “Hunters Turn”. That’s it for the players code. If you are still not sure about something then post it below. I tried my best to break it down as simple as possible.

Part B: Evil Genius
Having a smarter enemy is really easy. Some of you may remember the enemies code and said, gee, he’s really stupid. So, to make him “smarter”, lets add a couple more attacks to his arsenal. To recap, the enemies code goes something like this. First, we check to see if his group is activated. We set his flag 0 on and the Hunters flag 0 off. The difference is, we tell the strategy object to use five tactics instead of 0. We initialize the attack the same way. We check to see if the enemies internal flag 0 is on, an attack is not in progress, and we need to check to see if the enemies health is greater then 0. Then, we tell the strategy object to use a random tactic and begin the attack. (Special thanks goes to tiger-works (dang spell checker!) for that section of code.) Now, to begin the attack. We check to see if the enemies flag 0 is on, and to see if the strategy object current tactic is #0, and we need to make it only one action when the event loops.
Then, we have the enemy shoot the object we want him to. Hey, wait, isn’t this just like last time? Why, of course, you stupid simpleton, but this time, we flesh it out. The basic code checks to see if only one attack hit the player, now, we need to check for the other attacks. So if the strategy object picks number five, then the enemy will shoot the Crystal Spike at the player. If the strategy object picks zero, then the enemy will shoot the fireball at the player. So, we set off each individual attack in accordance with its number. It doesn’t end there! Since the enemy knows a number of attacks now, we need to stop all those attacks when they hit the player. Again, this is quite easy. Just check which tactic the enemy strategy object is using, and check to see if the corresponding move has hit the player. Then, subtract the amount of damage that that attack does, set the pirates flag 0 off, destroy the attack graphic, then tell the enemy strategy object to end the attack. An example code would be:

CONDITIONS
Pirate S.O.: Current Tactic is #0
Collision between fireball and Hunter:
EVENTS
Fireball: Destroy
Pirate: Set flag 0 off
Hunter: Sub 5 to health
Pirate S.O.: End Attack
*The S.O. stands for strategy object

Repeat this logic for all the attacks you choose to let your enemy know. Make your enemy only as smart as many lines you want to code. Each attack should follow this basic skeleton as a guideline for the enemy. So, now your good guys know how to learn moves and your enemies know a better variety. You don’t need to give your enemy everything the player know. For example, you might want to keep all the good moves to your player and give the enemy some crappy ones and maybe one or two good ones. I know this isn’t all there is to a RPG battle system. I have yet to include certain directional attacks, status ailments, and moves that repeat more then once or repeat over turns. I’ll try to find some way to bring those secrets to the community. I hope everyone finds this useful and if they find an easier way to do things other then this then please share it with the community. Questions, comments, bugs, or something you think I forgot? Post it here.

p.s. to the person who was complaining about rubbish articles, hope this helps