Attack anyone, attack is self too?

jakr8911

Veteran
Veteran
Joined
Feb 18, 2017
Messages
34
Reaction score
1
First Language
english
Primarily Uses
Other
So when i have a state that restriction is attack anyone, my guy actually attack him self. I dont want him to do that, i want him to attack ally or enemies. I already make two different state, one that attack enemies, one that attack ally. And my guy still attack him self
Is this what they meant by attack ally?
 

Doktor_Q

I'm not a real doktor, but I am a real Q
Veteran
Joined
Aug 1, 2016
Messages
653
Reaction score
379
First Language
English
Primarily Uses
RMMV
Characters are their own allies, so "attack ally" and "attack anyone" can both potentially make someone attack themselves. It's pretty typical of how it behaves in turn-based RPGs in general, not just RPGMaker.
 

Zevia

Veteran
Veteran
Joined
Aug 4, 2012
Messages
622
Reaction score
329
First Language
English
Primarily Uses
RMMV
Try this Plugin. It should make it so that the restriction "target anyone" will no longer make a battler target themselves. If they are the only living member of the party left, then they should pick a random target in the enemy party.

Code:
/*:
* @plugindesc This Plugin makes it so that Battlers cannot target themselves when
* affected by a state where the restriction is "target anyone."
* @author Zevia
*
* @help If the battler is the only member of the party, they will
* automatically target a unit in the opponents' party.
*/

(function(module) {
    'use strict';

    module.Zevia = module.Zevia || {};
    var IgnoreSelfTargetConfusion = module.Zevia.IgnoreSelfTargetConfusion = {};

    IgnoreSelfTargetConfusion.startAction = BattleManager.startAction;
    BattleManager.startAction = function() {
        $gameParty._subject = undefined;
        $gameParty._friendsUnit = undefined;
        $gameParty._targetUnit = undefined;
        $gameTroop._subject = undefined;
        $gameTroop._friendsUnit = undefined;
        $gameTroop._targetUnit = undefined;
        IgnoreSelfTargetConfusion.startAction.call(this);
    };

    IgnoreSelfTargetConfusion.randomTarget = Game_Unit.prototype.randomTarget;
    Game_Unit.prototype.randomTarget = function() {
        if (
            !this._subject ||
            !this._subject.isConfused() ||
            this._friendsUnit !== this._targetUnit
        ) { return IgnoreSelfTargetConfusion.randomTarget.call(this); }

        var tgrRand = (Math.random() * this.tgrSum()) - this._subject.tgr;
        var target = null;
        this.aliveMembers().filter(function(member) {
            if (this._subject._actorId) { return member._actorId !== this._subject._actorId; }
            else { return member.index() !== this._subject.index(); }
        }.bind(this)).forEach(function(member) {
            tgrRand -= member.tgr;
            if (tgrRand <= 0 && !target) { target = member; }
        });
        return target;
    };

    IgnoreSelfTargetConfusion.confusionTarget = Game_Action.prototype.confusionTarget;
    Game_Action.prototype.confusionTarget = function() {
        var subject = this.subject();
        var confusionLevel = subject.confusionLevel();
        var targetUnit = this.friendsUnit();
        targetUnit._friendsUnit = targetUnit.constructor;
        if (targetUnit.aliveMembers().length === 1) { targetUnit = this.opponentsUnit(); }

        if (confusionLevel === 1 || (confusionLevel === 2 && Math.randomInt(2) === 0)) { targetUnit = this.opponentsUnit(); }
        targetUnit._targetUnit = targetUnit.constructor;
        targetUnit._subject = subject;
        return targetUnit.randomTarget();
    };
})(window);
Fun side note: I thought this would be a fairly quick thing to implement. It was not. Confusion targeting is a real pain in the ass to try and override. So... Hopefully it works for you. :guffaw:
 

Attachments

jakr8911

Veteran
Veteran
Joined
Feb 18, 2017
Messages
34
Reaction score
1
First Language
english
Primarily Uses
Other
Try this Plugin. It should make it so that the restriction "target anyone" will no longer make a battler target themselves. If they are the only living member of the party left, then they should pick a random target in the enemy party.

Code:
/*:
* @plugindesc This Plugin makes it so that Battlers cannot target themselves when
* affected by a state where the restriction is "target anyone."
* @author Zevia
*
* @help If the battler is the only member of the party, they will
* automatically target a unit in the opponents' party.
*/

(function(module) {
    'use strict';

    module.Zevia = module.Zevia || {};
    var IgnoreSelfTargetConfusion = module.Zevia.IgnoreSelfTargetConfusion = {};

    IgnoreSelfTargetConfusion.startAction = BattleManager.startAction;
    BattleManager.startAction = function() {
        $gameParty._subject = undefined;
        $gameParty._friendsUnit = undefined;
        $gameParty._targetUnit = undefined;
        $gameTroop._subject = undefined;
        $gameTroop._friendsUnit = undefined;
        $gameTroop._targetUnit = undefined;
        IgnoreSelfTargetConfusion.startAction.call(this);
    };

    IgnoreSelfTargetConfusion.randomTarget = Game_Unit.prototype.randomTarget;
    Game_Unit.prototype.randomTarget = function() {
        if (
            !this._subject ||
            !this._subject.isConfused() ||
            this._friendsUnit !== this._targetUnit
        ) { return IgnoreSelfTargetConfusion.randomTarget.call(this); }

        var tgrRand = (Math.random() * this.tgrSum()) - this._subject.tgr;
        var target = null;
        this.aliveMembers().filter(function(member) {
            if (this._subject._actorId) { return member._actorId !== this._subject._actorId; }
            else { return member.index() !== this._subject.index(); }
        }.bind(this)).forEach(function(member) {
            tgrRand -= member.tgr;
            if (tgrRand <= 0 && !target) { target = member; }
        });
        return target;
    };

    IgnoreSelfTargetConfusion.confusionTarget = Game_Action.prototype.confusionTarget;
    Game_Action.prototype.confusionTarget = function() {
        var subject = this.subject();
        var confusionLevel = subject.confusionLevel();
        var targetUnit = this.friendsUnit();
        targetUnit._friendsUnit = targetUnit.constructor;
        if (targetUnit.aliveMembers().length === 1) { targetUnit = this.opponentsUnit(); }

        if (confusionLevel === 1 || (confusionLevel === 2 && Math.randomInt(2) === 0)) { targetUnit = this.opponentsUnit(); }
        targetUnit._targetUnit = targetUnit.constructor;
        targetUnit._subject = subject;
        return targetUnit.randomTarget();
    };
})(window);
Fun side note: I thought this would be a fairly quick thing to implement. It was not. Confusion targeting is a real pain in the ass to try and override. So... Hopefully it works for you. :guffaw:
It work for now, thank you very much
 

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

Latest Threads

Latest Posts

Latest Profile Posts

"Ugh, so tired of these rivers and lakes." *squints and looks off into the distance* "Oh cool! Is that a waterfall?"
Why is it so hard to accept existential stoicism? To insist stoics must be deterministic is like insisting God couldnt create evolving animals. Drop the dogmas and concider the compatible mechanics
I just had a duel at Duel Links, and started right away with a fusion monster... felt like an actual yugioh main character :3
Now listen closely... Here's a little lesson in trickery, This is going down in history...
So the four of my friends are singing a song and I'm like... ohoho I don't know this song. Better act like I do!

Forum statistics

Threads
93,517
Messages
913,136
Members
123,047
Latest member
RedReaper204
Top