Check states using a common event script?

Hi, I'm trying to do something strange I suppose. I'm trying to set up a battle system which allows players to essentially build combos through only through menu navigation (like most old rpgs handle their combat) and I'm not sure how to lock the moves so that a move of each category cannot be used more than twice? I know of states allowing me to lock away certain skill types but I'm not sure how to apply these to the player. (Or if there's a better way.)

I'm using the VCM Action Points and Action Order plugins to allow the user to strike multiple times. , gave the class I want this to work with have six skills (Light punch, medium punch, heavy punch, light kick, medium kick, heavy kick), each with their own skill type to seal away. I made statuses named light hit 1, light hit 2, medium hit 1, medium hit 2 and heavy hit, where light hit 1 isn't meant to lock away anything, light hit 2 locks both light punch and kick, medium hit 1 also locks both light attacks and medium hit 2 does the same while also locking away all medium attacks. Heavy hit is singular as heavy attacks are meant as forced combo finishers therefore locking away all forms of combat further and forcing the player to skip their turn.

My problem is that I don't really know scripting, so I don't know how to check for the current player's selection in the battle menu and then based on that being able to apply the appropiate state. I tried running this short script as part of an attack effect, but it doesn't work (the former tells me a is null and the latter says "cannot read property 'isStateAffected' of null")

Code:
if ( a.isStateAffected(11) ) { a.addState(12); } else { a.addState(11) }

Code:
if ( BattleManager.actor().isStateAffected(11) ) { BattleManager.actor().addState(12); } else { BattleManager.actor().addState(11) }

And even then it doesn't lock the option to use the light attack skills - since it doesn't iniciate the turn right away, it still lets me pick as many light attacks in a row as i want as long as I have the AP, which is not what I want.

Doing all this with an AP system already in place may seem a bit redundant but I intend for the player to be able to gain AP so their combos get more complicated as time goes on.

Thank you so much.
You say "like most old RPGs" but I'm pretty sure I have never played or heard of a system like this 😛 What would be an actual example?

The easiest way to do this would be to incorporate some free Yanfly plugins. Yanfly's Skill Core has notetags to determine whether a skill is enabled for use, and you shouldn't need to use any states.

So try this. Go to your light punch skill and put in there the notetag:
Code:
<Custom Requirement>
value = !user._actions.some(action => {action && action.isSkill() && action.item().stypeId == 3});
</Custom Requirement>

where 3 is the skill type ID (as on your Types page) of your medium attacks. That should, theoretically, cause the light punch to be greyed out in your skill list if you have a medium attack queued up.

I tried running this short script as part of an attack effect
I'm not sure what "running a script as part of an attack effect" means, but I'm assuming from the title of the thread that you mean you put it in a common event attached to the skill.

That could never do anything, because the skill's effects (and specifically common events) don't execute until the entire skill has resolved.
You say "like most old RPGs" but I'm pretty sure I have never played or heard of a system like this 😛 What would be an actual example?
Haha, what I meant was simple command selection, a counter-example would be FF6, Sabin uses button inputs to determine special moves - I don't want that, I just want basic menu navigation, just in succession.

So try this. Go to your light punch skill and put in there the notetag:
That doesn't seem to be doing anything, I'm able to choose a light attack regardless of the move that comes after. I'm not sure what's wrong exactly, tried writing my own thing to no avail:

Code:
<Custom Requirement>
set $var20 = $dataSkills[id].stypeId
   if ($var20 > 4) {
     value = true;
   } else {
     value = false;
   }
  </Custom Requirement>

where $var20 is variable 0020 in the database, labeled as "Move Used Last". Skill types 05 through 08 correspond to the higher intensity attacks so in theory if the skill type ID is higher than 4 it should hide/grey it out, but that doesn't do anything either. I also tried swapping out true and false in case I had misread/messed that up but it still doesn't lock the skill away.

I'm not sure what "running a script as part of an attack effect" means, but I'm assuming from the title of the thread that you mean you put it in a common event attached to the skill.

That could never do anything, because the skill's effects (and specifically common events) don't execute until the entire skill has resolved.
Yep, that's exactly what I tried and ended up realizing. Sorry for the poor wording, but I'm very glad you understood exactly what I did!
That doesn't seem to be doing anything, I'm able to choose a light attack regardless of the move that comes after.
You mean before, not after, right?

When you're selecting skills for a battler, after you've selected a medium attack, press F8, go to the Console tab, paste in
Code:
BattleManager._subject._actions
click the little arrow to expand the result, and take a screenshot of it. For example:
1729649703089.png


Also include a screenshot of that skill's entry in your database and the exact notetag in your light attack.

I'm not sure what's wrong exactly, tried writing my own thing to no avail:
Yes, that will be to no avail, because several pieces of it aren't valid JavaScript syntax. There's no such thing as set and no such variable as id.

where $var20 is variable 0020 in the database
How?
You mean before, not after, right?
Yeah, before.

When you're selecting skills for a battler, after you've selected a medium attack, press F8, go to the Console tab, paste in
Spoiler: Images Attached
Screenshot_13.png

Screenshot_14.png

Sorry for the awful js code, I have no real idea what I'm doing but I was like 30% sure that's how variables worked
That's...weird. You're getting that while the battle screen is waiting for you to choose your second action?

Try putting it into the notetag, then.

Code:
<Custom Requirement>
console.log("Actions are ", user._actions);
value = !user._actions.some(action => {action && action.isSkill() && action.item().stypeId == 3});
</Custom Requirement>
where $var20 is variable 0020 in the database, labeled as "Move Used Last".
that is not how variables work, at least not without a lot of additional code.
can you show us where you linked the variables?

and NEVER use leading zeroes when using variable IDs in code, the variable is 20 and not 0020.
That is because 00 is the prefix for an octal number, and octal 0020 is decimal 16 - the leading zeroes will mess up your variable IDs.

That said, a different question:
how exactly are you starting the battle for your testing? Only one of the following possibilities is guaranteed to work correctly:
playtest, start new game, have an event start battle processing
playtest, continue saved game, have an event start battle processing
database troop tab, start battletest
That's...weird. You're getting that while the battle screen is waiting for you to choose your second action?
Yep. I also tried the new code and it doesn't seem to do it either. I think it's because when the next selection comes up, the first doesn't go yet? The turn hasn't iniciated so the medium punch hasn't actually attacked.
that is not how variables work, at least not without a lot of additional code.
can you show us where you linked the variables?
I don't think I did, I was just a bit sure that was how they work. All I did was name variable 20 in the event searcher and then dumped $var20 in the code which I was 99% sure wasn't gonna work. I figured if I was in the right track though, someone would tell me.
That said, a different question:
how exactly are you starting the battle for your testing?
Usually with the troop tester, tried just now to do a game test, save the game, load the game and then run into an encounter and I get this:

Spoiler: Image attached
Screenshot_15.png
Yep. I also tried the new code and it doesn't seem to do it either.
I'm not sure what you mean it "doesn't seem to do it" - you have an entire window full of the logs it added to the console.

So the action array is there, just for some reason the next line of code isn't picking out the skill type.

So we'll break it out of the array function and do it more manually:
Code:
<Custom Requirement>
console.log("Actions are ", user._actions);
for (let i = 0; i < user._actions.length; i++)
{
    if (user._actions[i].isSkill() && user._actions[i].item().stypeId == 3)
        value = false;
}
</Custom Requirement>
Again, change the 3 to whatever the skill type of your medium attacks is.

Any time you add/modify plugins or notetags, you need to start a new play test. Just put an event on the first map of your game you can talk to and it calls Battle Processing.
Usually with the troop tester,
and that is the least reliable option, because battletest skips too much of the general code to go directly to the battle.
the default engine was made so that works, but as soon as you add plugins there will be quite a number of plugins that do not work correctly in battletest (those that have their initialisation in the skipped parts of the engine)
I'm not sure what you mean it "doesn't seem to do it" - you have an entire window full of the logs it added to the console.
I meant it didn't lock away the skills, the log actually working I assumed was due to me doing a full game test, sorry.
Again, change the 3 to whatever the skill type of your medium attacks is.
This new code does it, but now I have a different problem, it DOES lock the skills - it also prevents them from happening at all unless I use a single skill type. The game will ignore the fact that the skills have been already selected and the character won't deal a single point of damage if a higher-intensity skill has been used.

Spoiler: Log
pixi.js:27682
PixiJS 4.5.4 - ✰ WebGL ✰ http://www.pixijs.com/ ♥♥♥


(unknown) Actions are Array(0)length: 0__proto__: Array(0)clone: ƒ ()concat: ƒ concat()constructor: ƒ Array()contains: ƒ (element)copyWithin: ƒ copyWithin()entries: ƒ entries()equals: ƒ (array)every: ƒ every()fill: ƒ fill()filter: ƒ filter()find: ƒ find()findIndex: ƒ findIndex()forEach: ƒ forEach()includes: ƒ includes()indexOf: ƒ indexOf()join: ƒ join()keys: ƒ keys()lastIndexOf: ƒ lastIndexOf()length: 0map: ƒ map()pop: ƒ pop()push: ƒ push()reduce: ƒ reduce()reduceRight: ƒ reduceRight()reverse: ƒ reverse()shift: ƒ shift()slice: ƒ slice()some: ƒ some()sort: ƒ sort()splice: ƒ splice()toLocaleString: ƒ toLocaleString()toString: ƒ toString()unshift: ƒ unshift()Symbol(Symbol.iterator): ƒ values()Symbol(Symbol.unscopables): {copyWithin: true, entries: true, fill: true, find: true, findIndex: true, …}__proto__: Object
VM249:1 Actions are Array(0)length: 0__proto__: Array(0)
VM249:1 Actions are Array(0)length: 0__proto__: Array(0)
VM249:1 Actions are Array(0)length: 0__proto__: Array(0)
VM249:1 Actions are Array(0)length: 0__proto__: Array(0)clone: ƒ ()concat: ƒ concat()constructor: ƒ Array()contains: ƒ (element)copyWithin: ƒ copyWithin()entries: ƒ entries()equals: ƒ (array)every: ƒ every()fill: ƒ fill()filter: ƒ filter()find: ƒ find()findIndex: ƒ findIndex()forEach: ƒ forEach()includes: ƒ includes()indexOf: ƒ indexOf()join: ƒ join()keys: ƒ keys()lastIndexOf: ƒ lastIndexOf()length: 0map: ƒ map()pop: ƒ pop()push: ƒ push()reduce: ƒ reduce()reduceRight: ƒ reduceRight()reverse: ƒ reverse()shift: ƒ shift()slice: ƒ slice()some: ƒ some()sort: ƒ sort()splice: ƒ splice()toLocaleString: ƒ toLocaleString()toString: ƒ toString()unshift: ƒ unshift()Symbol(Symbol.iterator): ƒ values()Symbol(Symbol.unscopables): {copyWithin: true, entries: true, fill: true, find: true, findIndex: true, …}__proto__: Object
VM249:1 Actions are Array(0)length: 0__proto__: Array(0)
VM249:1 Actions are Array(0)length: 0__proto__: Array(0)
VM249:1 Actions are Array(0)length: 0__proto__: Array(0)clone: ƒ ()concat: ƒ concat()constructor: ƒ Array()contains: ƒ (element)copyWithin: ƒ copyWithin()entries: ƒ entries()arguments: (...)caller: (...)length: 0name: "entries"__proto__: ƒ ()apply: ƒ apply()arguments: (...)bind: ƒ bind()call: ƒ call()caller: (...)constructor: ƒ Function()length: 0name: ""toString: ƒ toString()Symbol(Symbol.hasInstance): ƒ [Symbol.hasInstance]()get arguments: ƒ ()set arguments: ƒ ()get caller: ƒ ()set caller: ƒ ()__proto__: Object[[FunctionLocation]]: <unknown>[[Scopes]]: Scopes[0][[Scopes]]: Scopes[0]equals: ƒ (array)arguments: nullcaller: nulllength: 1name: "value"prototype: {constructor: ƒ}__proto__: ƒ ()apply: ƒ apply()arguments: (...)bind: ƒ bind()arguments: (...)caller: (...)length: 1name: "bind"__proto__: ƒ ()[[Scopes]]: Scopes[0]call: ƒ call()caller: (...)constructor: ƒ Function()length: 0name: ""toString: ƒ toString()Symbol(Symbol.hasInstance): ƒ [Symbol.hasInstance]()get arguments: ƒ ()set arguments: ƒ ()get caller: ƒ ()arguments: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
at Function.remoteFunction (<anonymous>:2:14)]caller: (...)length: 0__proto__: ƒ ()[[Scopes]]: Scopes[0]set caller: ƒ ()arguments: (...)caller: (...)length: 0__proto__: ƒ ()[[Scopes]]: Scopes[0]__proto__: Objectconstructor: ƒ Object()hasOwnProperty: ƒ hasOwnProperty()isPrototypeOf: ƒ isPrototypeOf()propertyIsEnumerable: ƒ propertyIsEnumerable()toLocaleString: ƒ toLocaleString()toString: ƒ toString()valueOf: ƒ valueOf()__defineGetter__: ƒ __defineGetter__()__defineSetter__: ƒ __defineSetter__()__lookupGetter__: ƒ __lookupGetter__()__lookupSetter__: ƒ __lookupSetter__()get __proto__: ƒ __proto__()set __proto__: ƒ __proto__()[[FunctionLocation]]: <unknown>[[Scopes]]: Scopes[0]No properties[[FunctionLocation]]: rpg_core.js:89[[Scopes]]: Scopes[1]every: ƒ every()fill: ƒ fill()arguments: (...)caller: (...)length: 1name: "fill"__proto__: ƒ ()[[FunctionLocation]]: <unknown>[[Scopes]]: Scopes[0]filter: ƒ filter()find: ƒ find()findIndex: ƒ findIndex()forEach: ƒ forEach()includes: ƒ includes()indexOf: ƒ indexOf()join: ƒ join()keys: ƒ keys()lastIndexOf: ƒ lastIndexOf()length: 0map: ƒ map()pop: ƒ pop()push: ƒ push()reduce: ƒ reduce()reduceRight: ƒ reduceRight()reverse: ƒ reverse()shift: ƒ shift()slice: ƒ slice()arguments: (...)caller: (...)length: 2name: "slice"__proto__: ƒ ()[[Scopes]]: Scopes[0]some: ƒ some()sort: ƒ sort()splice: ƒ splice()toLocaleString: ƒ toLocaleString()toString: ƒ toString()unshift: ƒ unshift()Symbol(Symbol.iterator): ƒ values()Symbol(Symbol.unscopables): {copyWithin: true, entries: true, fill: true, find: true, findIndex: true, …}__proto__: Object
BattleManager._subject._actions
VM275:1 Uncaught TypeError: Cannot read property '_actions' of null
at <anonymous>:1:24
(anonymous) @ VM275:1
--enable-logging --v=1
VM279:1 Uncaught SyntaxError: Unexpected identifier

I've figured out how to copy and save the log file, though I hope I did it correctly so this can be troubleshot much easier.
I meant it didn't lock away the skills, the log actually working I assumed was due to me doing a full game test, sorry.
You don't need to be able to code in JavaScript, but you might see the one line of difference had the words "console log" in it.

This new code does it, but now I have a different problem, it DOES lock the skills - it also prevents them from happening at all unless I use a single skill type. The game will ignore the fact that the skills have been already selected and the character won't deal a single point of damage if a higher-intensity skill has been used.
Alright, well, sorry - I don't know what else I can do. Nothing in the Custom Requirement tag would affect a skill being used or not, the only thing it does is make the skills greyed out or selectable.

So between that and the odd behavior of the code I had you try earlier, I suspect there's something funky in your project from some combination of plugins or how you have it set up or...something. I don't know.

If you really want this system, I think you'll have to either see if there's some other existing plugin to do it (which I don't know of), or see if you can commission someone to take a copy of your entire project and troubleshoot it and get it set up for you.

I've figured out how to copy and save the log file, though I hope I did it correctly so this can be troubleshot much easier.
Can you read that? I can't.
If you really want this system, I think you'll have to either see if there's some other existing plugin to do it (which I don't know of), or see if you can commission someone to take a copy of your entire project and troubleshoot it and get it set up for you.
Yeah, that's no problem. I appreciate your help nonetheless, this was a pretty big ask after all. Thank you for your time.

I'll find someone to properly code it eventually, this is definitely beyond the scope of what free plugins can offer. For now I can balance it around AP and damage formulas to incentivize players not to spam a specific type of attack.

Original thread: https://forums.rpgmakerweb.com/threads/check-states-using-a-common-event-script.172766/