Weaken specific weapons with a state?

I created a new state for the Weaken Weapon state. From what I have been seeing it is possible weaken a damage type the weapon is doing also to check if the player the state is on has that weapon type equipped.

So what I want to do is weaken the damage type of a weapon if they have that weapon equipped. For example Weaken Swords would cause Slashing damage to be reduced to 75% if the player is equipped with a sword.

Here's what I got.


<JS Post-Apply>
//weapon ids 26-44 are all swords
if(target.equips[1].id>=26 && target.equips[1].id<=44)
{
//element 1 is slashing
target.element[1]=75%;
}
</JS Post-Apply>

Game crashes as soon as battle starts with an enemy that has an attack with the status.
I'm thinking the target.element[] is wrong, but not sure what would be correct in its place.
0.75

although I'm not sure about accessing the element directly.
if that's a weapon attribute, you have to pull the battler first, then the weapon, then the lot of attributes and THEN the one element.
I think one of the VisuStella MZ core plugins has a tag like <JS Pre-Damage as User> that can be used on states, with a value variable representing the actual damage/heal to apply? In that case maybe consider something like this:

<JS Pre-Damage as User> if ( this.isPhysical() && value > 0 && user.weapons?.().some(w => 26 <= w.id && w.id <= 44) ) { value = Math.floor(value * 0.75); } </JS Pre-Damage as User>
I.e. "if it's a physical hit, does damage, and the user has at least one relevant weapon equipped, multiply the damage output by 0.75". I haven't tested this...you might need different syntax.
So you're saying something like this but it still the same crash
I think target. works with someone that has a status effect. Maybe not though. If .target is the problem how do I do it without an individual if statement for every playable character that exists. with the actor(x) tag.

"if that's a weapon attribute, you have to pull the battler first, then the weapon, then the lot of attributes and THEN the one element."
I'm not sure what you mean here. Elements are the damage types in the system. I know you can assign element on a weapon and on any damaging skill. Maybe this is just something that can't be accessed as I haven't found anyone else even trying to do this and I'm just assuming .element[x] is how you'd access the element. There is no code in the Script calls for elements.

If this needs a plugin does anyone know one that may work? Below is my 2nd try and .element can't be used on .equips either. Even if that did work I think it would permanently change the value and I need it to go away when the status goes away.


<JS Post-Apply>
//weapon ids 26-44 are all swords
if(target.equips[1].id>=26 && target.equips[1].id<=44)
{
//element 1 is slashing
target.equips[1].element[1]=0.75;
}
</JS Post-Apply>

The other way to do this could be to check the weapon as I did then in the if check if attacking and what type of damage the weapon does. If it does slashing damage reduce the damage by 25%. Not sure how to code that also and still would have to check the element in that case.

caethyril
I don't fully understand this line
user.weapons?.().some(w => 26 <= w.id && w.id <= 44

user.weapons makes sense not sure if the ? is code or if I need to fill something in there and there's a . before the () and after the (). () usually is the end of a function to pass parameters the dot before it confuses me what you mean or if that is how it should be coded. some? I don't know of a some function or am I supposed to replace that. I'm assuming all the w's should have .id on them and w just is you abbreviating for weapon. As written it doesn't work that's why I'm trying to understand this line to fix it. And yes I do use the VisuStella core & battler.
  • ?. is the optional chaining operator:

  • Array#some is a method for array iteration:
Not sure why it isn't working, but it might be helpful if you could explain whether it's throwing an error or simply not affecting the damage. If there is an error message, what is it?

(You can press F8 during test to show the console, or F12 if it errors out before the game has booted.)

I checked and "Pre-Damage" seems to be one of the Battle Core notetags. Looks like there's some applicable settings available in the Plugin Manager in case that's relevant?

You might also want to make sure you've saved your project if you've only added the plugins recently. Any Plugin Manager changes made since you last saved the project will not be seen during test.
SyntaxError
Malformed arrow function parameter list

Shows up when I boot up the game.

So odd the error is
evTools failed to load SourceMap: Could not load content for chrome-extension://njgcanhfjdabfmnlmpmdedalocpafnhl/js/libs/pixi.js.map: System error: net::ERR_FILE_NOT_FOUND

But if I remove the code there is no error. Not sure what this is even about. Not sure what pixi.js.map is but I have pixi.js in my libs folder.

Ok your code is working for some reason my troop slot 2 is crashing the game no matter what enemies I put in that space. It crashes when I encounter them. Slots 1 and 3 are working fine moving the test monster there fixed it.
SyntaxError
Malformed arrow function parameter list

Shows up when I boot up the game.
I see nothing wrong with my arrow function, so I guess that's from something else...
So odd the error is
evTools failed to load SourceMap: Could not load content for chrome-extension://njgcanhfjdabfmnlmpmdedalocpafnhl/js/libs/pixi.js.map: System error: net::ERR_FILE_NOT_FOUND

But if I remove the code there is no error. Not sure what this is even about. Not sure what pixi.js.map is but I have pixi.js in my libs folder.
It's a harmless warning (yellow/brown text). To remove it, you can either:
  • Edit out the source map reference from your project's pixi.js file. It's a comment near the end of the file, see this post for a screenshot:

  • Or download the source map file and include it in your project alongside pixi.js:
Ok your code is working for some reason my troop slot 2 is crashing the game no matter what enemies I put in that space. It crashes when I encounter them. Slots 1 and 3 are working fine moving the test monster there fixed it.
Oh nice, good to know my code isn't at fault! 😂

Maybe check your plugins, one or more of them might be trying to do something with troop 2? Not sure what might be happening there. 😴
Try deleting troop 2 and recreating it - if you made the troop then deleted enemies it references, that could cause crashing.
Try deleting troop 2 and recreating it - if you made the troop then deleted enemies it references, that could cause crashing.
I've deleted and recreated Troop 2 many times. I have been working on the database and not the game so I only have 1 map so far that is blank with a few sample events and the battle test event is the only one that references troops.

Ok I've put the same enemy on Troop 2 and Troop 3. If I fight Troop 2 here is the error that pops up:

Spoiler: Error Message
TypeError: Cannot read property 'height' of undefined
at Sprite_Enemy.<computed>.<computed> [as updateFrame] (VisuMZ_1_BattleCore.js:16049)
at Sprite_Enemy.Sprite_Battler.updateMain (rmmz_sprites.js:504)
at Sprite_Enemy.Sprite_Battler.<computed>.updateMain (VisuMZ_1_BattleCore.js:16049)
at Sprite_Enemy.Sprite_Battler.update (rmmz_sprites.js:485)
at Sprite_Enemy.Sprite_Battler.<computed>.<computed> [as update] (VisuMZ_1_BattleCore.js:16049)
at Sprite_Enemy.update (rmmz_sprites.js:962)
at Sprite_Enemy.<computed>.update (VisuMZ_1_BattleCore.js:16049)
at Sprite_Enemy.<computed>.update (VisuMZ_3_VisualStateEffects.js:1168)
at Sprite.update (rmmz_core.js:1973)
at Sprite.update (rmmz_core.js:1973)
SceneManager.catchNormalError @ rmmz_managers.js:2030
SceneManager.<computed> @ VisuMZ_0_CoreEngine.js:7271
SceneManager.update @ rmmz_managers.js:1941
Graphics._onTick @ rmmz_core.js:801
TickerListener.emit @ pixi.js:9474
Ticker.update @ pixi.js:9928
Ticker._tick @ pixi.js:9679
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682


No error shows up with the same enemy on troop 3. I've deleted and recreated troop 2 several times.
Attached are the plugins I'm using.
1625763487892.png
the last 3 couldn't fit on the last screen shot.
1625763692900.png


Ok I fixed it by copying troop 1 and pasting it on troop 2 then changing the enemy in the troop back to the origional. Still no idea why that happened. But least it works now.
My guess about the error would be that it's trying to reference an enemy with no image assigned. That could be for various reasons, e.g. maybe the enemy has no image in the database (or was deleted), or a plugin is replacing its image with undefined (maybe due to a mistake in a notetag somewhere).

Since it only happens for troop 2, my only suggestion is to double-check everything (troop events, enemy notetags, plugin parameters, etc) that might apply to that troop to see what might be wrong. In the meantime, I guess you can just avoid using that troop.

Also, I'd suggest turning off the first ----- plugin in your list, because it's blocking any potential warning messages from plugins below it.
My guess about the error would be that it's trying to reference an enemy with no image assigned. That could be for various reasons, e.g. maybe the enemy has no image in the database (or was deleted), or a plugin is replacing its image with undefined (maybe due to a mistake in a notetag somewhere).

Since it only happens for troop 2, my only suggestion is to double-check everything (troop events, enemy notetags, plugin parameters, etc) that might apply to that troop to see what might be wrong. In the meantime, I guess you can just avoid using that troop.

Also, I'd suggest turning off the first ----- plugin in your list, because it's blocking any potential warning messages from plugins below it.
After copying and pasting troop1 over troop 2 the error vanished so it isn't there anymore. It was weird. Before I did that I tried copying and pasting the one giving the error onto troop 4 and it started giving troop 4 the error. I also tried deleting all enemies on the troop and reapplying new ones but error remained. But like I said I fixed it now just by copying a good troop over them and changing the enemies to ones that I want.

I do still have one problem and looking at how they do a boosted elemental damage it wouldn't work. I was hoping to be able to take the same code that made attacks with slashing weaker to make an accessory equipment or a wizard staff that would make all fire magic 25% more powerful. Unless there is something to do this already. It seems a pretty common wizard type accessory to make one element more powerful when equipped.
After copying and pasting troop1 over troop 2 the error vanished so it isn't there anymore. ... I also tried deleting all enemies on the troop and reapplying new ones but error remained.
Ah right, I thought you'd already tried deleting the troop, not just clearing its members. Good to know it's fixed! 😂

I do still have one problem and looking at how they do a boosted elemental damage it wouldn't work. I was hoping to be able to take the same code that made attacks with slashing weaker to make an accessory equipment or a wizard staff that would make all fire magic 25% more powerful. Unless there is something to do this already. It seems a pretty common wizard type accessory to make one element more powerful when equipped.
Note that my original suggestion doesn't have an element check, this.isPhysical() just checks the hit type. If everything you want is related to elements, I suggest VisuStella MZ Elements and Status Menu Core instead, since it has tags specifically for this purpose, e.g.

<Dealt Element id Rate: x%>
Sorry for overcomplicating things earlier... 😴

Spoiler: Battle Core tag stuff
Otherwise, let's say you have Fire as element 2, then I think this Battle Core tag would increase all outgoing fire damage by +25%:

<JS Pre-Damage as User> if ( this.item().damage.elementId === 2 && value > 0 ) { value = Math.floor(value * 1.25); } </JS Pre-Damage as User>
This tag could go on the wizard hat/staff/whatever equipment, so I don't think there's a need to check equipment IDs. If necessary, that check could be something like this:

user.armors?.().some(a => [12, 23, 45].includes(a.id))
I.e. "does the user have armor ID 12, 23, or 45 equipped?"
Ah right, I thought you'd already tried deleting the troop, not just clearing its members. Good to know it's fixed! 😂


Note that my original suggestion doesn't have an element check, this.isPhysical() just checks the hit type. If everything you want is related to elements, I suggest VisuStella MZ Elements and Status Menu Core instead, since it has tags specifically for this purpose, e.g.

<Dealt Element id Rate: x%>

Sorry for overcomplicating things earlier... 😴

Spoiler: Battle Core tag stuff
Otherwise, let's say you have Fire as element 2, then I think this Battle Core tag would increase all outgoing fire damage by +25%:

<JS Pre-Damage as User> if ( this.item().damage.elementId === 2 && value > 0 ) { value = Math.floor(value * 1.25); } </JS Pre-Damage as User>

This tag could go on the wizard hat/staff/whatever equipment, so I don't think there's a need to check equipment IDs. If necessary, that check could be something like this:

user.armors?.().some(a => [12, 23, 45].includes(a.id))

I.e. "does the user have armor ID 12, 23, or 45 equipped?"
Thank you that fixed the problem I combined the 2 things you provided for it all to work correctly.
So if anyone else needs it here is the code all together. 26-44 on weapons is pointing to the ids of the swords in my database. And element id===1 is checking that it is of Slashing damage type.

Code:
<<JS Pre-Damage as User>
if (
  (this.isPhysical() || this.item().damage.elementId === 1) &&
  value > 0 &&
  user.weapons?.().some(w => 26 <= w.id && w.id <= 44)) {
  value = Math.floor(value * 0.75);
}
/* add the following replacing weapons to the if
user.armors?.().some(a => [12, 23, 45].includes(a.id))
if needing armor equip check */
</JS Pre-Damage as User>

I had to use both because the one with weak slashing damage if I only used the isPhysical() it didn't alter the damage when using skills with that damage type. So combined the two with an or. Now it works 100% and I just remove the weapons check for fire.

Thanks for the help

Original thread: https://forums.rpgmakerweb.com/threads/weaken-specific-weapons-with-a-state.138233/