Help With an Enemy Skill I've designed

So I've designed this enemy skill based around the fact that the enemy is giant pile of Gold Coins. The skill works like this: The enemy's HP get below a certain percentage and it wants to heal itself. What does it do? It steals gold from the party and uses it to replenish itself.

Pretty cool, right?

Well, I have worked out how to get it to do all that of that... for the most part.

The first time the enemy uses the skill it works beautifully... No problems what so ever.

But - Any subsequent attempts to heal itself ends in failure. The skill goes off, it run through all the same stuff, the variables seem to have the appropriate information, but the enemy is not healed and the action effect doesn't go off.

I don't know what to do... I've tried all I can think of.

Here is the Skill:
Skill 1.png


This is the Notetag:
Code:
<damage formula>
 value = $gameVariables.value(165);
</damage formula>
<setup action>
 display action
</setup action>
<target action>
 motion Attack C: user
 wait: 30
 ACTION ANIMATION: all actors
 WAIT FOR ANIMATION
 COMMON EVENT: 81
 wait: 10
 animation 416: user
 WAIT FOR ANIMATION
 wait: 5
 action effect: user
 wait: 30
 COMMON EVENT: 14
</target action>

And these are the Common Events that are used to pull the gold information and balance the amounts so the skill isn't too overpowered:
This is the parallel event that constantly updates itself so that the information is ready when needed...
Common Event 1.png


This the common Event that the skill uses:
Common Event 2.png



I honestly have no idea where I'm going wrong here and how to fix it... Any help would be great.
Off the hat it looks like there are way too many instances of variables edits, which could lead in one interfering with one another.

You have a common event that runs every frame (common event 1.png) and updates the values every frame.
Then, when the skill must be used, it is still running every frame, yet in your skill common event (common event 2.png) you are modifying the values again before processing it, and again after processing it.

Since you already have a common event doing this, I'm wondering why you need 2 other instances of variable edits.


So, the skill looks ok in my opinion but
The first common event (running every frame) looks a bit overkill imo, you could achieve the same result with less power by editing the skill as follow :
value = $gameParty.gold();
Rpg maker already has a way to access the current gold value, there is no need to have a common event running constantly to update a variable with the same value

This would allow you to drop that first common event, saving some memory in the process.

It seem you are using variables 165 and 239 to calculate the minimum values between a number and the gold value, I'm not sure why you are doing this twice,
but you can simplify the variable edits using a similar approach using a single call for each, as follow :
◆ Control Variables : #0165 Gold Replenish = Math.floor(Math.min($gameParty.gold()/2.5, 350))
◆ Control Variables : #0239 Gold Replenish II = Math.min(1000, $gameParty.gold())

Though, again, I'm not sure why you have two different Replenish formula, since the skill seems to be using only one of them (Gold Replenish #0165)

Then you are using labels Gold and End in your common event 81, but never use the gold label, making it useless, you could achieve same result with an "If Else" since there seem to be only true or false output
Making gold - Replenish II (0239), while using Replenish (0165) in the formula is a mystery also to me ^^, but at least is should update gold correctly.

Then you have a script line saying variable 166 = variable 166 + variable 239 (Replenish II)
Then once more, you edit the variables, but I'm clueless as to why or what you want to do, it seems to me there is no need for that, since you will do it every time you call for the event anyway



In a nutshell, since the above might not be very clear :

- change the skill's damage formula to be : value = Math.floor(Math.min($gameParty.gold()/2.5, 350)); (According to replenish from #0165)
- Delete (
or at least make it inactive if you want to use it later) common event 14
- Update the skill's target action and remove wait: 30 & COMMON EVENT: 14 (
or at least the common event 14)
- Update the common event 81 to look like something like this :


Code:
◆ Control Variables : #0239 Gold Replenish II = Math.min(1000, $gameParty.gold())
◆ If : Gold = 0
    ◆ text : Not succes
◆ Else :
    ◆ text : Succes
    ◆ Change Gold : - {Gold Replenish II} 
◆ : End
◆ Wait : 5 frames
◆ Script : $gameVariables.setValue(166, ($gameVariables.value(166) + $gameVariables.value(239)));


This should do the trick, removing all unnecessary actions and editting, aswell as a parrallell common event.
Let me know if this works. 🙂
Are you using yep_battleenginecore?
Maybe it is ACTION COMMON EVENT instead of COMMON EVENT?
as a general rule, you should NEVER call a triggered common event.

only call common event's that are set to trigger = none

The reason is that triggered common events (autorun or parallel) are expected to loop eternally, while a call common event expects the CE to run once and then returns to the call.

The engine has been known to hickup in those cases, especially if the common event interacts with others or is more complex.
And that completely ignores the fact that parallels are automatically stopped while on battlescreen, because the battleinterpreter (which is different from the map interpreter) cannot handle them.

If the ninja'd solution above does not help, make a non-parallel copy of event 14 to use
Off the hat it looks like there are way too many instances of variables edits, which could lead in one interfering with one another.

You have a common event that runs every frame (common event 1.png) and updates the values every frame.
Then, when the skill must be used, it is still running every frame, yet in your skill common event (common event 2.png) you are modifying the values again before processing it, and again after processing it.

Since you already have a common event doing this, I'm wondering why you need 2 other instances of variable edits.


So, the skill looks ok in my opinion but
The first common event (running every frame) looks a bit overkill imo, you could achieve the same result with less power by editing the skill as follow :
value = $gameParty.gold();
Rpg maker already has a way to access the current gold value, there is no need to have a common event running constantly to update a variable with the same value

This would allow you to drop that first common event, saving some memory in the process.

It seem you are using variables 165 and 239 to calculate the minimum values between a number and the gold value, I'm not sure why you are doing this twice,
but you can simplify the variable edits using a similar approach using a single call for each, as follow :
◆ Control Variables : #0165 Gold Replenish = Math.floor(Math.min($gameParty.gold()/2.5, 350))
◆ Control Variables : #0239 Gold Replenish II = Math.min(1000, $gameParty.gold())

Though, again, I'm not sure why you have two different Replenish formula, since the skill seems to be using only one of them (Gold Replenish #0165)

Then you are using labels Gold and End in your common event 81, but never use the gold label, making it useless, you could achieve same result with an "If Else" since there seem to be only true or false output
Making gold - Replenish II (0239), while using Replenish (0165) in the formula is a mystery also to me ^^, but at least is should update gold correctly.

Then you have a script line saying variable 166 = variable 166 + variable 239 (Replenish II)
Then once more, you edit the variables, but I'm clueless as to why or what you want to do, it seems to me there is no need for that, since you will do it every time you call for the event anyway



In a nutshell, since the above might not be very clear :

- change the skill's damage formula to be : value = Math.floor(Math.min($gameParty.gold()/2.5, 350)); (According to replenish from #0165)
- Delete (
or at least make it inactive if you want to use it later) common event 14
- Update the skill's target action and remove wait: 30 & COMMON EVENT: 14 (
or at least the common event 14)
- Update the common event 81 to look like something like this :


Code:
◆ Control Variables : #0165 Gold Replenish = Math.floor(Math.min($gameParty.gold()/2.5, 350))
◆ Control Variables : #0239 Gold Replenish II = Math.min(1000, $gameParty.gold())
◆ If : Gold = 0
    ◆ text : Not succes
◆ Else :
    ◆ text : Succes
    ◆ Change Gold : - {Gold Replenish II} //This would remove Replenish II #0239, but the fomula uses Replenish #0165
◆ : End
◆ Wait : 5 frames
◆ Script : $gameVariables.setValue(166, ($gameVariables.value(166) + $gameVariables.value(239))); // Here again,
this would increase the value of 166 by Replenish II #0239, but the skill uses Replenish #0165


This should do the trick, removing all unnecessary actions and editting, aswell as a parrallell common event.
Let me know if this works. 🙂
I'll have to give these suggestions a try.

Just for clarification:
variable 165 is the damage formula variable. I made so it takes the gold and adjusts it to a maximum of 350 but can have any number in-between. This means that the enemy steals up to 875 gold before ignoring any amount above that.
Variable 239 is the actual amount stolen. I wanted them to be different. So he can steal more gold than he actually uses to heal. I'm actually thinking of adjust these values after I get this to work since it kills the parties gold too fast. So there's a text box that shows up and tells you how much was stolen buts its different the amount that is used to heal.

I wanted to add a randomizong option so that the healing amount and gold stolen is randomized, but I could figure out how to implement it. I might be able to do that now... maybe.

as a general rule, you should NEVER call a triggered common event.

only call common event's that are set to trigger = none

The reason is that triggered common events (autorun or parallel) are expected to loop eternally, while a call common event expects the CE to run once and then returns to the call.

The engine has been known to hickup in those cases, especially if the common event interacts with others or is more complex.
And that completely ignores the fact that parallels are automatically stopped while on battlescreen, because the battleinterpreter (which is different from the map interpreter) cannot handle them.

If the ninja'd solution above does not help, make a non-parallel copy of event 14 to use
I actually knew that common events stopped during battle... that's why I called the parallel common event from the skill. I have another skill for the same enemy that attacks the player with the gold stolen. Calling the common event fixed the problem I was having on that one.

Plus, the parallel common event is loading up the variables with the latest data so it's up to date whenever you might encounter this enemy.

‐--------------

Thanks for the help guys... I'll try the suggestions soon and let you all know how it turns out.
I'll have to give these suggestions a try.

Just for clarification:
variable 165 is the damage formula variable. I made so it takes the gold and adjusts it to a maximum of 350 but can have any number in-between. This means that the enemy steals up to 875 gold before ignoring any amount above that.
Variable 239 is the actual amount stolen. I wanted them to be different. So he can steal more gold than he actually uses to heal. I'm actually thinking of adjust these values after I get this to work since it kills the parties gold too fast. So there's a text box that shows up and tells you how much was stolen buts its different the amount that is used to heal.

I wanted to add a randomizong option so that the healing amount and gold stolen is randomized, but I could figure out how to implement it. I might be able to do that now... maybe.


I actually knew that common events stopped during battle... that's why I called the parallel common event from the skill. I have another skill for the same enemy that attacks the player with the gold stolen. Calling the common event fixed the problem I was having on that one.

Plus, the parallel common event is loading up the variables with the latest data so it's up to date whenever you might encounter this enemy.

‐--------------

Thanks for the help guys... I'll try the suggestions soon and let you all know how it turns out.

Indeed :
165: Math.floor(Math.min($gameParty.gold()/2.5, 350)) will pick the smallest number if smaller than 350, else it will pick 350.
239: Math.min(1000, $gameParty.gold()) will pick 1000, or gold value if its more than 1000.

Meaning you want to deal damage/heal hp based on the 165 formula, and steal gold based on the 239 formula.
This makes sens, so the solution I proposed should work regardless of that, since I used the 239 variable for gold modification. 🙂

If you want to randomize the amount of healing and gold stolen, you can use the same formula, but change Math.min() to Math.random().
It's a bit more difficult to use in javascript dued to its behavior (it will return a float between 0 and 1), so you would have to adjust the formula to keep that scaled correctly.
So say you want to randomize 165 (damage/heal), you could do something like this :
Math.floor(Math.random() * Math.min($gameParty.gold() / 2.5, 350)) (This will return a value between 0 and gold/2 if lower than 350)
Math.random() will be worth anything between 0 and 1, while Math.min() will be worth anything between gold/2.5 and 350, then multiply the two values, say random number is 0.16 and min is 200, this will return a value of 32.

You can apply the same logic to 239 for randomness. Note however that this is nowhere near true randomness, but for the purpose needed, it will do just fine.
If you want a minimum value you can wrap it in another Math.max() syntax. 🙂
Math.max(minimumValue, Math.floor(Math.random() * Math.min($gameParty.gold() / 2.5, 350)))
Indeed :
165: Math.floor(Math.min($gameParty.gold()/2.5, 350)) will pick the smallest number if smaller than 350, else it will pick 350.
239: Math.min(1000, $gameParty.gold()) will pick 1000, or gold value if its more than 1000.

Meaning you want to deal damage/heal hp based on the 165 formula, and steal gold based on the 239 formula.
This makes sens, so the solution I proposed should work regardless of that, since I used the 239 variable for gold modification. 🙂

If you want to randomize the amount of healing and gold stolen, you can use the same formula, but change Math.min() to Math.random().
It's a bit more difficult to use in javascript dued to its behavior (it will return a float between 0 and 1), so you would have to adjust the formula to keep that scaled correctly.
So say you want to randomize 165 (damage/heal), you could do something like this :
Math.floor(Math.random() * Math.min($gameParty.gold() / 2.5, 350)) (This will return a value between 0 and gold/2 if lower than 350)
Math.random() will be worth anything between 0 and 1, while Math.min() will be worth anything between gold/2.5 and 350, then multiply the two values, say random number is 0.16 and min is 200, this will return a value of 32.

You can apply the same logic to 239 for randomness. Note however that this is nowhere near true randomness, but for the purpose needed, it will do just fine.
If you want a minimum value you can wrap it in another Math.max() syntax. 🙂
Math.max(minimumValue, Math.floor(Math.random() * Math.min($gameParty.gold() / 2.5, 350)))
So I've implemented some of those changes you suggested and the Skill works like a charm, though I did fiddle with it a little and changed some of its mechanics.

But then I thought I could streamline the other skill I had for this enemy and the skill works, but one of its mechanics got broken.

This is the Skills Notetag:
Code:
<Custom Target Eval>
  for (var i = 0; i < $gameVariables.value(163); i++)
      targets.push(foes.aliveMembers()[Math.randomInt(foes.aliveMembers().length)]);
</Custom Target Eval>
<setup action>
 display action
 motion Attack C: user
 wait: 30
 ANIMATION 293: all actors
 WAIT FOR ANIMATION
 wait: 10
 animation 40: user
 WAIT FOR ANIMATION
 wait: 5
 COMMON EVENT: 102
 wait: 10
 motion Attack C: user
 wait for motion
 CAMERA FOCUS: focus, CENTER, 10
 ZOOM: 150%, 20
 wait: 10
</setup action>
<target action>
 motion Damage: user
 projectile icon 634: start user, goal target, duration 7, spin 6
 wait for projectile
 action animation: target
 animation wait: 5
 action effect: target
 wait: 30
</target action>
<finish action>
 reset camera: 10
 reset zoom: 10
 wait for zoom
 CLEAR BATTLE LOG
</finish action>

And this is the common event for it, after the changes...
Common 3.png

I added a show text to help me with the visualization... If you need a hand to figure it out then here is the explanation.

This skill steals gold from the party and uses that gold to attack the party. It's set so that it can take a max of 200 gold coins with no minimum. The gold is then divided by 20 to get a number for the amount of time the skill is allowed to attack the party.
So, for example... the enemy steals 100 gold and that gold is divided by 20 to get 5... That number [5] is then used so the enemy can attack the party 5 times... The enemy picks a random target each time it repeats a round. So if it attacks 5 times then the enemy will attack one member of the party randomly each time.

Here is a video to show you what happening:


So basically, the skill is randomly assigning a number [between 1 and 9] for the number of times it's attacking... It's not supposed to do that. It's supposed to be using the variable to determine that.

Can you help me out?
So I've implemented some of those changes you suggested and the Skill works like a charm, though I did fiddle with it a little and changed some of its mechanics.

But then I thought I could streamline the other skill I had for this enemy and the skill works, but one of its mechanics got broken.

This is the Skills Notetag:
Code:
<Custom Target Eval>
  for (var i = 0; i < $gameVariables.value(163); i++)
      targets.push(foes.aliveMembers()[Math.randomInt(foes.aliveMembers().length)]);
</Custom Target Eval>
<setup action>
 display action
 motion Attack C: user
 wait: 30
 ANIMATION 293: all actors
 WAIT FOR ANIMATION
 wait: 10
 animation 40: user
 WAIT FOR ANIMATION
 wait: 5
 COMMON EVENT: 102
 wait: 10
 motion Attack C: user
 wait for motion
 CAMERA FOCUS: focus, CENTER, 10
 ZOOM: 150%, 20
 wait: 10
</setup action>
<target action>
 motion Damage: user
 projectile icon 634: start user, goal target, duration 7, spin 6
 wait for projectile
 action animation: target
 animation wait: 5
 action effect: target
 wait: 30
</target action>
<finish action>
 reset camera: 10
 reset zoom: 10
 wait for zoom
 CLEAR BATTLE LOG
</finish action>

And this is the common event for it, after the changes...
View attachment 311415
I added a show text to help me with the visualization... If you need a hand to figure it out then here is the explanation.

This skill steals gold from the party and uses that gold to attack the party. It's set so that it can take a max of 200 gold coins with no minimum. The gold is then divided by 20 to get a number for the amount of time the skill is allowed to attack the party.
So, for example... the enemy steals 100 gold and that gold is divided by 20 to get 5... That number [5] is then used so the enemy can attack the party 5 times... The enemy picks a random target each time it repeats a round. So if it attacks 5 times then the enemy will attack one member of the party randomly each time.

Here is a video to show you what happening:


So basically, the skill is randomly assigning a number [between 1 and 9] for the number of times it's attacking... It's not supposed to do that. It's supposed to be using the variable to determine that.

Can you help me out?

The issue the video is displaying (and the custom event aswell) is that you are actually using the previous value of 163 for your combo count.
If you pay attention, you will notice when it says "163 : 9", it will attack 4 times, then it says "163 : 7", but it will attack 9 times, then it says "163 : 5" but it will attack 7 times.

This is because you are rewriting the current value in the common event after processing it in the skill.

So you are asking in the skill :
JavaScript:
<Custom Target Eval>
  for (var i = 0; i < $gameVariables.value(163); i++)
      targets.push(foes.aliveMembers()[Math.randomInt(foes.aliveMembers().length)]);
</Custom Target Eval>

This means it will take the value of 163 and check for 0,1,2,... untill the value of 163
So this is what you want, correct?
But at that point, you haven't called the common event yet, meaning it will use the current value of 163 (In combat that would mean the last known value of it)
Then, you call the common event, which will rewrite the value of 163 (and 165), and base the text on those values.

So you are actually basing the skill on previous value, and the text on the new value, meaning there is a disparity in the data.

Easy fix would be to store the value of 163 before rewriting it, but this could create a problem in the 1st instance of it.
So I think you should drop the 163 value writing in the event and directly add that in the skill itself.

Fix :
In the common event, delete the two first variable controls
In the skill, add this :

JavaScript:
let atkI = Math.random() * Math.min($gameParty.gold(), 200);
let atkII = Math.ceil(atkI / 20);

$gameVariables.setValue(165, atkI);
$gameVariables.setValue(163, atkII);
before this :
JavaScript:
  for (var i = 0; i < $gameVariables.value(163); i++)
      targets.push(foes.aliveMembers()[Math.randomInt(foes.aliveMembers().length)]);

This will ensure you will have to correct data every time you use the skill and the common event will reflect that data in real time.


Btw, I like the Boss sprite! nice job ^^
Thank you @Artille! You've been a tremendous help. The skills are perfect and I can't wait to see how the battle will unfold. Now I have to get back to all the rest of my long list of things that need to get done.

Thank you again!

Edit: Yeah, it took a while to find that battler. It's on Aekashics designs. Incredibly talented person that one is.
Thank you @Artille! You've been a tremendous help. The skills are perfect and I can't wait to see how the battle will unfold. Now I have to get back to all the rest of my long list of things that need to get done.

Thank you again!

Edit: Yeah, it took a while to find that battler. It's on Aekashics designs. Incredibly talented person that one is.
Just to make sure, I made a mistake
JavaScript:
let atkI = Math.random() * Math.min($gameParty.gold(), 200);
let atkII = Math.ceil($gameVariables.value(165) / 20);

$gameVariables.setValue(165, atkI);
$gameVariables.setValue(163, atkII);

Should, of course be :

JavaScript:
let atkI = Math.random() * Math.min($gameParty.gold(), 200);
let atkII = Math.ceil(atkI / 20);

$gameVariables.setValue(165, atkI);
$gameVariables.setValue(163, atkII);

As variable 163 and variable 165 will have no new values at that point.


Glad I could help! Feel free to come back if you need something else ^^
You should rewrite everything from scratch using Battle Events instead. Things there are "too messy" to work properly, like many persons stated above.
You should rewrite everything from scratch using Battle Events instead. Things there are "too messy" to work properly, like many persons stated above.
Battle Events? You mean in the Troops tab? I'm sorry, I'm confused... The skills work great as is now, so what do you mean they're "too messy" to work properly?

I'm not trying to be rude, I just don't understand what you mean... Can you maybe provide an example?
You should rewrite everything from scratch using Battle Events instead. Things there are "too messy" to work properly, like many persons stated above.
"many people" ?

Utunels asked : Are you using yep_battleenginecore?
Andar explained why you should never call a trigerred common event

I suggested to clean things up, which he did apparently, since it works fine now.
I haven't read the whole thread, but if this hasn't been addressed yet, I wanted to point this out:
This is the parallel event that constantly updates itself so that the information is ready when needed...
1) Never run a parallel event without wait frames.
2) If you can avoid using a parallel event, you should do it. You don't need this information constantly being updated. You only need it when you enter battle right?
So either:
A) For on map encounters, just run the variable updates at the trigger of the battle.
B ) In troop events, run the variable updates on Turn 0 of battle.
C) On skills, just run the variable updates before the execution of the attack.

Anyways, glad you got it solved. I assume this is part of what Cleanwater is suggesting you clean up.
I haven't read the whole thread, but if this hasn't been addressed yet, I wanted to point this out:

1) Never run a parallel event without wait frames.
2) If you can avoid using a parallel event, you should do it. You don't need this information constantly being updated. You only need it when you enter battle right?
So either:
A) For on map encounters, just run the variable updates at the trigger of the battle.
B ) In troop events, run the variable updates on Turn 0 of battle.
C) On skills, just run the variable updates before the execution of the attack.

Anyways, glad you got it solved. I assume this is part of what Cleanwater is suggesting you clean up.
Probably, but I've already cleaned out all the parallel common events for these two skills. Artille was a big help in streamlining the skills to get the variables updated. The skills still use the common events, but they have a much better function now. I condensed the variables from 5 to 3 and everything works exactly how I wanted it to.

The Replenish skill is the one that I changed the most from what was helped with:
The skill:
Replenish Skill.png


The Common Event:
Replenish Common Event.png


The Variable Script:
Code:
Variable 164: Gold Replenish = Math.max(Math.floor(Math.random() * Math.min($gameParty.gold(), 240)), 50)

The Attack Skill:
Attack Skill.png


The Common Event:
Attack Common Event.png


The Custom Targeting script for the skill:
Code:
<Custom Target Eval>
  let atkI = Math.random() * Math.min($gameParty.gold(), 200);
  let atkII = Math.ceil(atkI / 20);
  $gameVariables.setValue(165, atkI);
  $gameVariables.setValue(163, atkII);
  for (var i = 0; i < $gameVariables.value(163); i++)
     targets.push(foes.aliveMembers()[Math.randomInt(foes.aliveMembers().length)]);
</Custom Target Eval>

If you compare my SS from the first post and the one now, I think it's pretty streamlined and they work way better than I could. Thanks to all who helped me. I'm sure I'll have more things I'll need help with in the future.

I have a couple of common events that are continuously updating.... but they are checking the map ID of the player so that certain items are disabled on certain maps... and a bank system that has a time-based interest rate.

I happen to love common events for the very reason that they are so versatile. I've randomized my chests and gold... Opening doors is a common event so I can make one change and all the doors are also changed. They make things a lot easier.

Oops... started rambling. Anyway. Thanks for the advice and thanks for the help.

Original thread: https://forums.rpgmakerweb.com/threads/help-with-an-enemy-skill-ive-designed.170276/