Shooting fireballs - bug

Hey guys, I've got a tutorial for shooting fireballs in VX Ace,. which with some tweaks will probably work in MV as well,. but before i start on that,. I'd like some help with the existing script. You see, It's got an annoying bug and I'm not sure how or why it's not working as intended.


Problems to note before continuing:
* If you shoot and walk at the same time in different zones, you'll trigger a "transfer" - annoying bug.
* If you shoot in different zones, the fireball / arrow movement speed is lower than the one you've set in the main area.



Those issues aside, this is an interesting ability which will add a lot of fun puzzle abilities for your players.
 


----


Shooting fireballs

If you've played Lufia 2 (snes), then you will probably remember the player's ability to destroy bushes, or grappling hook. (we may get to those later) Let's look at a Zelda ability instead for now. Shooting fire or arrows, in order to solve puzzles. This ability is a bit buggy still so we'll have to edit this chapter with clarifications and improvements later. If you can figure out a solution to the issues listed, feel free to share them with the rest of us.


We will need to create 3 events, 2 common events, 2 switches, 2 variables. So this chapter should be classified as intermediate difficulty.
We'll create an event for the fireball itself (or arrow if you prefer).
An event for learning/unlocking the ability.
And an event to shoot at.

Start by creating 3 events on the map, not much script/contents yet, just create an event and give it a name.
* Shot: Priority below characters, Stepping animation, Through (disable the other 2 options), Frequency 5, Speed 2x faster.
* Target Practice: Priority same as characters, Trigger on Parallel Process.
* Learn Fireball (name doesn't matter though): Priority below characters, Trigger on player touch.

Next up, the common events (we'll get back to the other events soon), we'll need two events to make this work.
* Use Check. This one is a bit complicated, but easy to understand in the end.
Name the first event "Use Check". Set it to trigger on a "parallel process", and the conditional switch (create new) on "Ability Active". Feel free to rename it later.

Create a conditional branch on X being pressed (X translates to the letter A on your keyboard - don't ask why, it just does. Same a C is spacebar. Logic right?)
As below: (Note you'll probably need to create the 2 switches 7 and 8 mentioned below)





 

@> Conditional Branch: The X Button is Being Pressed
@> Control Variables: [0003😛layer-X] = Player's Map X
@> Control Variables: [0004😛layer-Y] = Player's Map Y
@> Set Event Location: [Shot], Variable [0003][00004]
@> Conditional Branch: The Player is Facing Down
@> Set Move Route: [Shot] (Wait)
: : $> Turn Down
@>
: Else
@> Conditional Branch: The Player is Facing Left
@> Set Move Route: [Shot] (Wait)
: : $> Turn Left
@>
: Else
@> Conditional Branch: The Player is Facing Right
@> Set Move Route: [Shot] (Wait)
: : $> Turn Right
@>
: Else
@> Conditional Branch: The Player is Facing Up
@> Set Move Route: [Shot] (Wait)
: : $> Turn Up
@>
: Else
@>
: Branch End
@>
: Branch End
@>
: Branch End
@>
: Branch End
@> Control Switches: [0007: Ability Active] = OFF
@> Control Switches: [0008: Ability Used] = ON
@>
: Else
@>
: Branch End
@>






Conditional Branch can be found on tab 1. (Flow Control)
Control Variables can be found on tab 1. (Game Progression)
Set Event Location can be found on tab 2. (Movement)
Set Move Route can be found on tab 2. (Movement)
Control Switches can be found on tab 1. (Game Progression)

What we're basically doing here, is check whether the player has pressed the A (X) button. If so, get the player's current XY map coordinates and store those for later use. Then move the [Shot] starting position and rotation accordingly. After that we set the "used" switch on, so that another event can pick up from there. (In theory this could be done in a single event, but it's neater this way.)

Save / Apply that common event and let's go on to the next one.
We'll name it "Use Function". This event basically tells the game what needs to happen when the shot has been fired.
Set the trigger to "autorun", and the condition switch to "Ability used"
 





 

@> Set Move Route: [Shot] (Skip, Wait)
: : $> Graphic: '!Flame', 4
: : $> 1 Step Forward
: : $> 1 Step Forward
: : $> 1 Step Forward
: : $> 1 Step Forward
: : $> 1 Step Forward
: : $> Graphic: (None)
@> Set Event Location: [Shot], (000,000)
@> Control Switches: [0008: Ability Used] = OFF
@> Control Switches: [0007: Ability Active] = ON
@>






This event will tell the fireball to "appear" and move 5 steps forward from it's starting point, then disappear, return to a set location, and reactivate the default switches.

Next up - making it all work together.

Go to the "Learn Fireball" event, and add the following contents:
 





 

@> Conditional Branch: Switch [0007: Ability Active] == OFF
@> Text: -, -, Normal Bottom
: : New ability learned! [Fireball]
: : Press [A] to shoot and activate torches.
@> Control Switches: [007: Ability Active] = ON
@> Control Switches: [008: Ability Used] = OFF
@>
: Branch End
@>





This will tell the player he's learned a new ability and how to use it, and set the "initial state" of the relevant switches so that the other events can begin monitoring the A key. You should already have set the other settings for this event above.

The shot event needs no further changes either.

Lastly, we'll set up the torch to shoot a fireball at. (or basic camp fire)
Open the "Target Practice" event and add the following contents:
 





 

@> Control Variables: [005: Shot-X] = [Shot]'s Map X]
@> Control Variables: [006: Shot-Y] = [Shot]'s Map Y]
@> Conditional Branch: Variable [0005: Shot-X] == 31
@> Conditional Branch: Variable [0006: Shot-Y] == 26
@> Set Move Route: [Shot] (Wait)
: : $> Graphic: (None)
@> Set Event Location: [Shot], (000,000)
@> Control Self Switch: A = ON
@>
: Branch End
@>
: Branch End
@>





Apply those changes, and create a new event page for this event.
Change the graphic to a "campfire with fire" and in the conditions set a check for "self switch A is on".
Set "stepping animation" in the options, and disable the other 3 options.
Trigger should be a "Parallel Process", and priority the "same as characters".
Lastly, we add just two more lines in the contents. Note these are optional, and control the fire going out on it's own. Useful for time based puzzles [IMG]http://www.mmo-champion.com/images/smilies/wink.png[/IMG]
 





 

@> Wait: 120 frame(s)
@> Control Self Switch: A =OFF





That's it.
If you now play test you should be able to shoot fireballs while walking around.
This is a great ability to give your player at a later stage in the game, to be used in unlocking switches on the other side of rivers, or through fences.

Note, there's still 2 bugs with this tutorial as mentioned above - if you can help out, please do so.

Shooting fireballs is based on:
* http://www.rpgmakervx.net/index.php?showtopic=57501
Bump.


Someone should have an idea what's not working surely?

Original thread: https://forums.rpgmakerweb.com/threads/shooting-fireballs-bug.57278/