$gameParty.luk() don´t work

Hello guys, I´m trying to put $gameParty.luk() on a formula to take luck as parameter.

But I coudn´t make this work. I tried $gameParty.agility() and it worked perfectly.

I need help on this, maybe is something that I have missed.

Thank you in advance!!
Thales
It can't work because the party has no luck, only actors have luck. And to determine the luck of a specific actor, it's better to use control variable - game data than script.

Agility is an exception that only works because the battleengine needs to calculate the agility of the entire party for the success of the escape option - but I can't even tell you if that agility is calculated as the sum or the average or in a different way.
That's because $gameParty.agility() is specifically defined, and gets the average agi of all party members (or enemies, if you call it on the troop) and is used in the default escape chances, among other places. The default game never needs to check their collecting luck, so there's not function to get the whole party's luck built in.

.agility() looks like this:
Code:
Game_Unit.prototype.agility = function() {
    var members = this.members();
    if (members.length === 0) {
        return 1;
    }
    var sum = members.reduce(function(r, member) {
        return r + member.agi;
    }, 0);
    return sum / members.length;
};

So, a hypothetical party luck check, if you wanted to add it to the code yourself, would look like this:
Code:
Game_Unit.prototype.luck= function() {
    var members = this.members();
    if (members.length === 0) {
        return 1;
    }
    var sum = members.reduce(function(r, member) {
        return r + member.luk;
    }, 0);
    return sum / members.length;
};

And then you could just call $gameParty.luck() and get their average luck value.
Thank you guys for helping me.

That's because $gameParty.agility() is specifically defined, and gets the average agi of all party members (or enemies, if you call it on the troop) and is used in the default escape chances, among other places. The default game never needs to check their collecting luck, so there's not function to get the whole party's luck built in.

.agility() looks like this:
Code:
Game_Unit.prototype.agility = function() {
    var members = this.members();
    if (members.length === 0) {
        return 1;
    }
    var sum = members.reduce(function(r, member) {
        return r + member.agi;
    }, 0);
    return sum / members.length;
};

So, a hypothetical party luck check, if you wanted to add it to the code yourself, would look like this:
Code:
Game_Unit.prototype.luk = function() {
    var members = this.members();
    if (members.length === 0) {
        return 1;
    }
    var sum = members.reduce(function(r, member) {
        return r + member.luk;
    }, 0);
    return sum / members.length;
};

And then you could just call $gameParty.luk() and get their average luck value.



@Doktor_Q it worked perfectly!! Thank you so much!

Please, I would like to ask what formula do I have to put to get a single actor luk. Or a single actor agility.
Because $gameParty.luk() does get the sum of average. I have tried gameParty.luk(0) or (1) but didn´t work.
You're doing this in the formula window for a skill, right? They already give you access to the user and target directly- "a.atk - b.def" is accessing the attack of the user and the defense of the target. You don't need to change anything to have access to all of the base stats for those battlers.
Like @Doktor_Q said, in the damage formula box this would just be "a.luk". If you're looking to use this outwith battle though the script is:

Code:
$gameActors.actor(x).luk

Where x is the actors ID. If you're looking for script calls in the future check these pages out:

RMMV Script Calls
https://kinoar.github.io/rmmv-doc-web/
Hello! Thank you guys for replying!!

I can´t use "a.luk" because I´m using this on Items. And there I just can do it with formulas.

But $gameActors.actor(x).luk works perfectly!!!
Thank you @Silva for the code!!!
Hello! Thank you guys for replying!!

I can´t use "a.luk" because I´m using this on Items. And there I just can do it with formulas.

But $gameActors.actor(x).luk works perfectly!!!
Thank you @Silva for the code!!!

Items support "a.luk" just the same as skills. In fact, an item can do just about anything a skill can do- the only real difference is the requirements to use. They use the same code to process their effects.
With items, you would use b.luk as you use an item ON an actor, so the actor is the target. Items don't have a user, if you're using them from the menu. There's only a user if you're in battle.
Ok! Got it! Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/gameparty-luk-don-t-work.105172/