HOW TO RETURN THE ATK VALUE OF WEAPON?

Discussion in 'RPG Maker MV' started by arashiya, Jul 5, 2019.

  1. arashiya

    arashiya Veteran Veteran

    Messages:
    75
    Likes Received:
    3
    First Language:
    english
    Primarily Uses:
    RMMV
    I want to show the atk value of the weapon which is equipped
    how can I do it?
     
    #1
  2. Zenpai

    Zenpai Warper Member

    Messages:
    4
    Likes Received:
    0
    First Language:
    English
    Primarily Uses:
    RMMV
    Using Control Variable in an event, you can grab the actors attack number. I don't know if this pulls the current total actor attack amount (including all boosts/buffs) or if it just pulls the core attack amount. try a few experiments where you print the value of the variable using \V[n] where n is the number of the variable you want to read using a text display, and print it without the weapon equipped, and again with the weapon equipped and see if the value changes. If it does change, then it pulls the current total attack amount.

    Unfortunately, I don't see a way to dynamically pull the data each time, unless you look for an addon that will do it for you. As im not well versed in the ins and outs of this program, it's possible someone knows a way to pull this off in vanilla.

    However, if that test above works, you'd just need to figure out a way to trigger some data storage when equipment changes, to measure the existing attack value, and then record the new attack value, subtract the difference and you have the attack value of the equipped weapon.
     
    #2
  3. MushroomCake28

    MushroomCake28 KAMO Studio Veteran

    Messages:
    1,714
    Likes Received:
    3,065
    Location:
    Montreal, Canada
    First Language:
    English
    Primarily Uses:
    RMMV
    Code:
    var actor    = $gameParty.members()[0]; // change this number to change member. 0 = member 1, 1 = member 2, etc.
    var totalAtk = 0;
    var weapons  = actor.weapons();
    
    for (var i = 0 ; i < weapons.length; i++) {
        totalAtk += weapons[i].params[2];
    }
    
    $gameVariables.setValue(20, totalAtk); // change the 20 to the variable ID
    This code will calculate the sum of the atk parameter of all weapons the first party member has equip:
    • To change which hero it checks, change the number on the first line. The number indicates the party member id (0 = member 1; 1 = member 2; 2 = member 3, etc.)
    • To change which variable it stores the value in, change the "20" to your variable ID on the last line.
    You can insert the code in a script call. What will happen is that it will store the value inside the indicated variable. Please note that I haven't run the code, so I do not guarantee that I made no error in the code.

    EDIT: Also, to answer the above post, the atk parameter of the actor is the combination of his base stats + equipment (weapon and armor) + buffs + anything else that other plugins might add (like abilities or something).
     
    #3
    Eliaquim likes this.
  4. Nilom

    Nilom Veteran Veteran

    Messages:
    178
    Likes Received:
    39
    First Language:
    German
    Primarily Uses:
    RMMV
    Dependend on where you want to show the weapon attack you can use this script or set a variable with the script tab inside the variable command:

    $gameActors.actor(1).equips()[0].params[2]

    Character ID (look at the number in the actors tab in your database)
    Equip ID (look at the number in the types -> equipment types part of your database. 0 is mainhand, 1 is offhand etc.)
    Param ID
    hp = 0
    mp = 1
    atk = 2
    def = 3
    mat = 4
    mdf = 5
    agi = 6
    luk = 7

    Edit:
    For Dual wield
    $gameActors.actor(1).equips()[0].params[2]+$gameActors.actor(1).equips()[1].params[2]
    This will simply sum weapon 1's atk with weapon 2's atk.
     
    Last edited: Jul 5, 2019
    #4
    Wavelength and Eliaquim like this.
  5. MushroomCake28

    MushroomCake28 KAMO Studio Veteran

    Messages:
    1,714
    Likes Received:
    3,065
    Location:
    Montreal, Canada
    First Language:
    English
    Primarily Uses:
    RMMV
    The above post works generally, but it will not work with dual-wield. If you want something that works with everything, regardless of with or without dual-wield, pick my method.
     
    #5
  6. Nilom

    Nilom Veteran Veteran

    Messages:
    178
    Likes Received:
    39
    First Language:
    German
    Primarily Uses:
    RMMV
    $gameActors.actor(1).equips()[0].params[2]+$gameActors.actor(1).equips()[1].params[2]
    What's the problem?

    But I agree. Mushrooms Variant might be more elegant as you do not need if checks.
    I use the script that I suggested mainly for the formula tab of skills to let the attack do x% mainhand or offhand damage.
     
    Last edited: Jul 5, 2019
    #6
  7. arashiya

    arashiya Veteran Veteran

    Messages:
    75
    Likes Received:
    3
    First Language:
    english
    Primarily Uses:
    RMMV
    thanks very much for all the replies and it greatly helps!
    now I also know how to show the other values (HP, def, etc...)
    thanks a lot
     
    #7
  8. Aesica

    Aesica undefined Veteran

    Messages:
    784
    Likes Received:
    744
    Location:
    SW5GMW 4xVHk
    First Language:
    English
    Primarily Uses:
    RMMV
    Note that this only works if the weapons are in the first and second slots (0 and 1) and you have to know if the user is a dual wielder or not because otherwise, you'll be counting shield atk (if any) or whatever is in the slot right after. It's highly encouraged that you use weaons() instead of equips() for that reason. To total up every equipped weapon's atk for single wielders, dual wielders, quad wielders, and whatever else:

    $gameActors.actor(1).weapons().reduce((a, c) => a + c.params[2], 0)

    (At least it should work, I didn't give it a proper test) :D

    <Shameless>Note that one of the plugins in my signature lets you access weapon stats directly and easily via the formula box: a.weaponAtk for example</Shameless>

    :D
     
    Last edited: Jul 6, 2019
    #8
    Nilom likes this.
  9. MushroomCake28

    MushroomCake28 KAMO Studio Veteran

    Messages:
    1,714
    Likes Received:
    3,065
    Location:
    Montreal, Canada
    First Language:
    English
    Primarily Uses:
    RMMV
    @Nilom Your method works, I'm not saying it's working. But like you said, you need conditionals.

    For OP, if you don't use third party plugins that add multiple weapons, or if you don't have any dual-wield, Nilom's method is shorter (single) and works perfectly. My method is longer, but will work in every scenario.
     
    #9
    Nilom likes this.

Share This Page