RMMV States that are removed after X amount of battles

Status
Not open for further replies.

thepsyche

Veteran
Veteran
Joined
Nov 16, 2016
Messages
324
Reaction score
75
First Language
English
Hi everyone,

I'm trying to do some basic tests with a state that is applied in the menu onto an actor. Using YEP's Buffs & States core, I'm trying to get this state to remove itself after a certain amount of battles.

This is what I have written inside the notebox:


Code:
<Custom Battle Effect>

var battleCount = battleCount || 0;

battleCount + 1;

</Custom Battle Effect>

<Custom Victory Effect>

if (battleCount > 2) {

$gameActors.actor(this._actorId).removeState(57);

}

</Custom Victory Effect>

<Custom Escape Effect>

if (battleCount > 2) {

$gameActors.actor(this._actorId).removeState(57); 

}

</Custom Escape Effect>
This doesn't work - the state remains on the actor affected by the state. Probably for obvious reasons.

1) I don't temporary created inside a state using YEP's plugin remain constant outside of battle if the state is still applied.

2) I'm very sketchy on how to remove the state from the actor affected without using an actor slot. I'm almost certain I've used "$gameActors.actor(this._actorId).removeState(57)" incorrectly here.

Anyway, thanks for any light anyone can shed on this!
 

Dopan

Veteran
Veteran
Joined
Mar 27, 2020
Messages
542
Reaction score
255
First Language
German
Primarily Uses
RMMV
About:
I'm almost certain I've used "$gameActors.actor(this._actorId).removeState(57)" incorrectly here.
---

this could help..

JavaScript:
for (var i = 1; i <= $gameActors._data.length; i++) {
    // insert stuff here
}

// this will use Var i to adress all Actors
JavaScript:
$gameActors.actor([i]).removeState(57);
// this should affect all existing Actors


Edit (edited again)
more detailed:
JavaScript:
for (var i = 1; i <= $gameActors._data.length; i++) {
    if ($gameActors.actor([i]).isStateAffected(57)) {
        $gameActors.actor([i]).removeState(57);

    }
};
//this will only use those Actors who are StateAffected
(I am not using "Party member" or "Battle member" in SRPG thats why i cant add a proper If Condition to ask if the Actor is also a BattlePartyMember.. which could be usefull aswell)
 
Last edited:

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,117
Reaction score
1,525
First Language
EN
Primarily Uses
RMMZ
There are a few mistakes here, but the main thing is that the state will never expire because your battleCount variable is local to each notetag, i.e. in <Custom Battle Effect> it is always set to 0, then +1; in the other two tags it is always undefined. :kaoswt:

Instead, try defining it as a property on the state bearer, user, e.g. (untested):
Code:
<Custom Battle Effect>
user._battleCount = user._battleCount || 0;
user._battleCount += 1;
</Custom Battle Effect>

<Custom Victory Effect>
if (user._battleCount > 2) {
  user.removeState(57);
  delete user._battleCount;
}
</Custom Victory Effect>

<Custom Escape Effect>
if (user._battleCount > 2) {
  user.removeState(57);
  delete user._battleCount;
}
</Custom Escape Effect>
You might also want a <Custom Defeat Effect> tag, depending on your game's mechanics.
 

thepsyche

Veteran
Veteran
Joined
Nov 16, 2016
Messages
324
Reaction score
75
First Language
English
Hi @caethyril ,

Thanks for your solution - I just tested it and it works.

A couple of questions pertaining to this:

So, by putting a "._ "after "user" I am assigning a "property" to it, that I can assign a number that functions in a similar way to a variable?

If I use "user._battleCount" in that state, and that state has more than once instance per battle (it is active on different actors) - will these conflict with each other?
 

thepsyche

Veteran
Veteran
Joined
Nov 16, 2016
Messages
324
Reaction score
75
First Language
English
Hi @Dopan ,

Thanks for your suggestion, I can use this piece of code in other areas of my project. Cheers!
 

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,316
Reaction score
537
First Language
indonesian
Hi @caethyril ,

Thanks for your solution - I just tested it and it works.

A couple of questions pertaining to this:

So, by putting a "._ "after "user" I am assigning a "property" to it, that I can assign a number that functions in a similar way to a variable?

If I use "user._battleCount" in that state, and that state has more than once instance per battle (it is active on different actors) - will these conflict with each other?
for ._anyNameYouWant usually means for making a private variable for an object...
It is convention to precede the name of a private variable with an underscore (_).

also it won't conflict... each actor will have individual private ._battleCount property...

hope this help.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,117
Reaction score
1,525
First Language
EN
Primarily Uses
RMMZ
Yep, like estriole says, the underscore is optional; it's the dot that's important. :)

Note that if you have multiple states like this and you don't want them to share the counter, then you'll need to use a different property for each state.

Happy RPG Making~ :kaojoy:
 

thepsyche

Veteran
Veteran
Joined
Nov 16, 2016
Messages
324
Reaction score
75
First Language
English
Yeah, awesome. Thanks so much for all your help! The possibilities with adding properties are indeed vast.
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
7,867
Reaction score
5,240
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.

Forum statistics

Threads
106,035
Messages
1,018,455
Members
137,821
Latest member
Capterson
Top