Skill problem

Some enemies in my game have charge attacks. They cast Charge and get inflicted with the Charge condition. If an enemy is inflicted with Charge, they have a 100% chance to cast a special skill to do a lot of damage. Makes sense, and so far so good.

I made a skill for a character that removes the Charge condition from one enemy to prevent them from using their special skill on the coming turn. The problem I'm having is that the enemy is still casting its special skill after being targeted by the player skill.

This is what the player skill looks like, and below that what the monster's skill triggers are:

spZFS4K.png


I'm probably missing something obvious here, but I'm not seeing it...
What you're missing is the action order.


All actors and enemies get to select their used skill before the first skill is ever executed - which means that if the players select the skill on turn 2, it will only be executed after the enemy AI already selected the power skill.


And the conditions are only on the skill selection, not on the skill execution.


To change that, you'll really need scripts.
If your problem is only related to THAT specific skill there are ways to do that just using skill formula.

Since your enemy rate for the "Charged Smash" skill is 10 and there are no other skills between rate 8 and 12 when state is charged, you could just cancel enemy action with your "Compassion" skill, or you could add a state check in the "Charged Smash" formula to check if the charged state is still active.

a.state?(X) ? damage_formula : something_elseSomething like this should work. X is your charged state and "something_else" could be 0 or another damage formula, as you like.

Of course this only works if you problem is related to that particular skill. If you want to change skill execution then you need a script.

EDIT: to cancel enemy action through your "Compassion" formula it should be something like
 

b.remove_current_actionI never used such formula so this is untested.
That sucks, suppose I'll skip that until MV releases then, or change it into something else if I come up with something better.

If your problem is only related to THAT specific skill there are ways to do that just using skill formula.

Since your enemy rate for the "Charged Smash" skill is 10 and there are no other skills between rate 8 and 12 when state is charged, you could just cancel enemy action with your "Compassion" skill, or you could add a state check in the "Charged Smash" formula to check if the charged state is still active.

a.state?(X) ? damage_formula : something_elseSomething like this should work. X is your charged state and "something_else" could be 0 or another damage formula, as you like.Of course this only works if you problem is related to that particular skill. If you want to change skill execution then you need a script.

EDIT: to cancel enemy action through your "Compassion" formula it should be something like

b.remove_current_actionI never used such formula so this is untested.
The second formulae seems to simply stun the enemy for 1 turn, but what I want it do is for the enemy to cancel its charged attack, then select a new move from its skillset to immediately use on the same turn. But it looks like I'll need a script for that.
I have created a somewhat clunky event system that does exactly what you want, an enemy charges up and can't use any other skills for 2 turns and attacks on the 2nd turn. However it's a bit clunky and only 1 enemy can have a charge in a troop at a time without making it more complicated but it uses no scripting at all.

if you give me a minuet I'll organize some screenshots for you... 

Edit-

Forgot to mention, it uses a common event for every charge skill you will have

Edit 2- Here is my event system, I'll try to explain it best I can

Most important part is you have a disabled state that prevents movement

Disabled.png

The first skill is a generic charge skill that any enemy can have, have it apply the disabled state and call the first common event

Charge Skill 1.png

The first common event only sets a variable to say hey I got a guy charging over here

Common Event 1.png

Set up a 1+1*x turn span battle event that checks for a charging enemy and call the 2nd common event, the one unique to the attacking monster in that troop

Troop Event Page 1.png

Force the action that the enemy will use the skill and change the charging variable to 2, this is so another battle event can detect that the move is done and reset the enemy's state

Common Event 2.png

Charge Skill 2.png

Detect the new variable and remove the state and set the variable to 0

Troop Event Page 2.png

The way this works the enemy only needs to know the generic charge, the troop events takes care of the rest.

Enemy.png

This is a bit clunky and can be modified with more complicated events to have multiple enemies use charge attacks, and it's very heavy on Troop events and common events, but it works!

BTW, I missed an entire match of the LoL worlds to make this, lmao
The second formulae seems to simply stun the enemy for 1 turn, but what I want it do is for the enemy to cancel its charged attack, then select a new move from its skillset to immediately use on the same turn. But it looks like I'll need a script for that.
Since the enemy didn't act that turn you should be able to force an action against a random target. Now, I am not sure you can do it via formula with

b.force_action(new_action, -1)or with a battle event from the troop tab to force that action at the end of turn. This second option should work, I used it in a project and it was fine.

If you give me few minutes I can test the formula option and tell you if it works.

EDIT: of course, using the event you need to check if the state has been removed and then trigger the event.

EDIT 2: I ran few tests with formulae and it seems I was able to let it work.

First of all check enemy state when using "Compassion". My "Charged" state was state(26) so i used:

if b.state?(26); (b.remove_state(26); b.force_action(1, -1)); endthen add the previous formula to your "Charged Smash" skill to cancel action if the enemy is not charged.

(Skill 1 is Attack. You can change it if you want the enemy to use a different skill). If you want the enemy to use a random skill from its moveset then you probably want to randomize the skill number.

This solution works for every enemy using charged attacks with high rating as the example in your screenshot. If you have another skill with a rating between -2 and +2 from your charged attack then you will probably need to modify your formula and then I am not sure this way is the best one. For a single state that triggers a certain skill with a 100% chance it works fine and it is quite simple.
lol Seems I misunderstood what you were asking and made an entire event system HAHAHA

but the formula should work 

or the event system I made could be interrupted if you have a skill that resets the charge skill variable to 0 before the 2nd part of the move, If you already have a charging attack thing going on the formula should probably work.
...


This solution works for every enemy using charged attacks with high rating as the example in your screenshot. If you have another skill with a rating between -2 and +2 from your charged attack then you will probably need to modify your formula and then I am not sure this way is the best one. For a single state that triggers a certain skill with a 100% chance it works fine and it is quite simple.
Thanks a lot, this worked perfectly. So smooth. 😀
Just 1 more question about the formulae, how do I randomise the skill number if I'd want that? Like what if I'd want the enemy to have a 50% chance to use attack, and a 50% chance to use Charge again?

lol Seems I misunderstood what you were asking and made an entire event system HAHAHA


but the formula should work 


or the event system I made could be interrupted if you have a skill that resets the charge skill variable to 0 before the 2nd part of the move, If you already have a charging attack thing going on the formula should probably work.
Lol, it's fine. I like systems that run on just events since I'm so used to RM2K3. 😀 Besides, your tutorial above gave me some ideas for other things.
Glad you can get some use out of it, I like making Event systems that exploit things that are only thought possible with scripting, even if the event system is a bit of a mess lol
Thanks a lot, this worked perfectly. So smooth. 😀

Just 1 more question about the formulae, how do I randomise the skill number if I'd want that? Like what if I'd want the enemy to have a 50% chance to use attack, and a 50% chance to use Charge again?
I am glad my formula worked. About random skills is a bit different but it is basicly the same formula.

In my opinion the best (and probably fastest) way to do it is to have skills with skill ID between two integers.

EXAMPLE:

I have 2 skill: "Enemy_Attack" and "Enemy_Charge". "Enemy_Attack" skill ID is 100 and "Enemy_Charge skill ID is 101.

in the formula, instead of forcing action 1, i can force action  r where r is a random integer between 100 and 101.

r=100+rand(2)syntax should be this one. Now you only have to add it to your formula to get something like:

r=100+rand(2); if b.state?(26); (b.remove_state(26); b.force_action(r, -1)); end#you can do it with more than 2 skills changing the value of rand()It is much easier if you use random skills between two integers than using two skill with a gap between respective skill ID. Don't misunderstand me, it is still possible, but then you probably need more characters than those allowed by a simple formula.

r=rand(3)if r==0 b.force_action(n, -1) #n is the 1st skill ID (Example: for attack is 1)elsif r==1 b.force_action(m, -1) #m is the 2nd skill IDelse b.force_action(y, -1) #y is the 3rd skill IDendThis way you can pick skills with very different skill IDs but as you can see you need a lot of characters to do it.

The short way to do it (only if you need 2 different skills) is this one:

r=rand(2)if b.state?(26) b.remove_state(26) r==1 ? b.force_action(r, -1) : b.force_action(n, -1) #============================================================================================================= #n is the id of the skill you want to use instead of normal attack whith 50% chance #since i used b.force_action(r, -1) you can change the r formula and check for a different skill ID to use #two different skills without including the normal attack in this formula. #=============================================================================================================endThis formulae are untested but they should work. Unfortunatly I am not able to test them right now. I will probably do it in a couple of hours.

What I suggest is to create new skills with very similar IDs so you can easy pick a random skill between a very large pool of skills (assuming you need a very large pool of skills, of course).

NOTE: I am not sure that you can use a skill if you don't meet requirements. Talking about your "Charged Smash" I am not sure you can cast it once you removed the "Charged" state.
For the code at the bottom, am I supposed to put that in the battle formulae? Because I tried pasting it all in, but it won't fit on the single line.
This is the code I'm currently using, which forces it to use just Attack:

if b.state?(28); (b.remove_state(28); b.force_action(1, -1)); endAdding the code you wrote above gives me this; it isn't able to fit the last line on it:

if b.state?(28); (b.remove_state(28); b.force_action(r=rand(2) if b.state?(26) b.remove_state)); end
NOTE: I am not sure that you can use a skill if you don't meet requirements. Talking about your "Charged Smash" I am not sure you can cast it once you removed the "Charged" state.
Yes, you can. Just tried it out.
For the code at the bottom, am I supposed to put that in the battle formulae? Because I tried pasting it all in, but it won't fit on the single line.

This is the code I'm currently using, which forces it to use just Attack:

if b.state?(28); (b.remove_state(28); b.force_action(1, -1)); endAdding the code you wrote above gives me this; it isn't able to fit the last line on it:

if b.state?(28); (b.remove_state(28); b.force_action(r=rand(2) if b.state?(26) b.remove_state)); end
In this formula there is a double check for the state. You are checking state 28 and then state 26. I don't know which one is your "Charged" state but you probably want to check that one. However formulae limit is their characters limit. When something doesn't fit the formula's box you need scripts. You can also call them via formula but they are the only way if you need to write more.

What I mean with "I don't know if you can use a skill if you don't meet its requirements" is that it is up to how you check if you meet the requirements. If an enemy has a set percentage of using a skill based of something (HP, state, etc.) then you can, because they are not skill requirements, they are just situations where that specific enemy uses that skill. You could have a different enemy which uses that skill under different circumstances.

If you check for a requirement in the skill formula is something different.

Example:

a.state?(26) ? do_something : do_something_elsemeans that even if you cast this skill when state 26 is not active on you, the skill applies the second option (the one applied when a.state?(26) is false). In this case is "do_something_else".

This way I used that skill, but with a different effect, which is probably something I don't need/want.

Then there are weapon requirements. I never tried to force such kind of action when requirements were not met so I cannot tell you how it works.
In this formula there is a double check for the state. You are checking state 28 and then state 26.
Yeah, the 26 was meant to be 28, since I use 28 for Charge but forgot to change it in the post, but it was just to show how your formulae wouldn't fit on the line.

However formulae limit is their characters limit. When something doesn't fit the formula's box you need scripts. You can also call them via formula but they are the only way if you need to write more.
How do I link a script to a formulae, then?

What I mean with "I don't know if you can use a skill if you don't meet its requirements" is that it is up to how you check if you meet the requirements. If an enemy has a set percentage of using a skill based of something (HP, state, etc.) then you can, because they are not skill requirements, they are just situations where that specific enemy uses that skill. You could have a different enemy which uses that skill under different circumstances.
I tested it with the formulae of my Charged Smash skill, which he was able to perform, despite not meeting the requirement:

Code:
a.state?(28) ? damage_formula : a.atk*2 - b.def * 0.5
How do I link a script to a formulae, then?

I tested it with the formulae of my Charged Smash skill, which he was able to perform, despite not meeting the requirement:

a.state?(28) ? damage_formula : a.atk*2 - b.def * 0.5
In this formula you are not using a skill when not meeting the requirement, you have a skill with a different effect based on state(28). Anyway if this is what you need it works, if state(28) is active it applies damage_formula, if not it deals (a.atk*2 - b.def*0.5).

To link a script to a formula you should create the script you want and then call that in the formula (just name it). Assuming in your script you name the formula you need "millennin_rand_skill" you can write it in the formula box instead of the formula itself. There are many examples of scripts for custom formulae and you can find a lot of them in RGSSx Script Support.

if b.state?(28); (b.remove_state(28); b.force_action(r=rand(2) if b.state?(26) b.remove_state)); end
Assuming 28 is your state. What's the point of checking it, removing it, then forcing an action to check it and remove it again?

r=150+rand(2); if b.state?(28) (b.remove_state(28); b.force_action(r, -1)); endThis one is even shorter and allows you to randomize a lot of skills just changing value of the number inside rand().

I didn't test this one but essentially what it does is randomize a skill which skill ID is between 150 and 150+rand_value-1.

You can do many things with custom formulae. Fomar0153 made a very nice guide to custom formulae. You can find it here on this forum or you can check his blog at http://cobbtocs.co.uk/wp/?p=271.

I am not a script pro and so I won't give you an untested script which may or may not work. It could cause more troubles instead of solving them. I am sure if you ask in RGSSx Script Support somebody will give you a script for that. For what I see you don't need a huge script. The most of what you need fits in the formula box so it should be a very short script.

I am here to learn too 🙂

Original thread: https://forums.rpgmakerweb.com/threads/skill-problem.45674/