Movable State/Robot/Pet...things.

So...one of the characters in my game is a summoner, of sorts. She doesn't work by summoning new actors to fight for the party, but her modus operandi is to summon little robot companions who do her bidding, help out the party, and are generally awesome and adorable. I wanted to reflect this in the gameplay itself (because character and setting should ALWAYS come through in gameplay), but doing so is pretty far beyond my meager programming capabilities, so I thought I'd ask for help. Here's how I imagine it working (both from a lore and a programming standpoint):

Basically, she uses a skill that costs 'X' mana (let's say 35) to summon a little robot friend and have it attach to an ally (allies only, by the way. That's my one rule with these things). She only has 5 of them, but they last 15 turns (the longest-lasting states in the game), and apply some pretty powerful effects. Things like zapping enemies who attack their host, applying a lot of HP and MP regen, or boosting the damage an ally does. However, she only has one of each type of robot, so when she re-casts the skill on a different target, she doesn't summon a new robot. Instead, the robot of that type will jump from its current host to the new one. This doesn't consume any of her mana, but it also doesn't reset the timer that dictates how long the robot can continue to function. Once the timer runs out, the robot "returns to its master" to recharge, and you need to spend the MP cost to send it back out.

From a programming standpoint, the easiest way to pull off this effect is probably just to have a state representing the robot (which contains the intended effect), and each time you use the corresponding skill, the following procedure occurs:

-- Is the state currently applied to any ally?
if yes:
1. Reduce the MP cost to zero.
2. Save the turn counter on the state in a temporary variable.
3. Remove the state from whichever ally currently has it (probably with a little animation, because animations woo!).
4. Apply the state to the target (also, probably, with an animation).
5. Change the state counter on the target to the saved value.
if no, the skill operates normally.

This definitely seems like something that's possible with the Lunatic Mode functions of Yanfly's Skill Core and Buffs & States Core, both of which I'm using. However, I'm not sure about the specifics of how to program this, as it's all pretty far beyond my meager programming knowledge. So if anyone who knows their stuff is willing to help me out on this, I'd seriously appreciate it!

Thanks a bunch! ^^
Bump...
Boop...
Bomp...
...blerp.
...man, it's been a while. Still would love assistance on this, though. ^^
Okay...this is gonna be my last reply, because this is getting a little ridiculous. However, I do have a rough prototype code crudely cobbled together. It has...SOME of the functionality I'm after. The MP cost gets modified without issue. The rest of the intended functionality of the skill, though...struggles. The state gets applied without issue if nobody else has it, but it's when someone else in the party has the state that I run into the infamous "undefined is not a function" error.

This is the full code I slapdashed together (though I'm almost certain the issue is in the last third. I marked the most likely culprit):

<Select Conditions>
Not State: 74
</Select Conditions>

<Custom MP Cost>
var group = user.friendsUnit().aliveMembers();
for (var i = 0; i < group.length; ++i) {
var ally = group;
if (ally && ally.isStateAffected(74)) {
cost = 0;
break;
} else {
cost = 35;
}
}
</Custom MP Cost>

<After Eval>
var robotstate = 74;
var group = user.friendsUnit().aliveMembers();
for (var i = 0; i < group.length; ++i) {
var ally = group;
if (ally && ally.isStateAffected(robotstate)) {
var turns = ally.stateCounter(robotstate); <--Probably the line that's messing things up the most.
ally.removeState(robotstate);
break;
} else {
var turns = 15;
}
}
target.addState(robotstate);
target.setStateCounter(robotstate, turns);
</After Eval>


Any assistance at all with this issue is massively appreciated!
I'm not 100% sure, but I think you have to make your "troubled" line read like this:

Code:
var turns = ally._stateCounter[robotstate];

Note the change from ( ) to [ ].
See if that helps.
Thanks so much for the assistance, Maliki!

As for the line of code, the errors are no longer an issue. However, the turn counter is still stubbornly locked to 15 when recast. I tried tweaking around with the lines of code here and there, but nothing worked out. So...sorry for the mixed results, I guess. XD
I see. Sorry. I didn't look over all the code thoroughly enough.
I fixed the erroneous line.

Code:
if (ally[i] && ally[i].isStateAffected(robotstate)) {

Try that.

Original thread: https://forums.rpgmakerweb.com/threads/movable-state-robot-pet-things.77143/