[Javascript]How to get Actor Weapon's elemental damage ID?

Randor01

Veteran
Veteran
Joined
Dec 24, 2018
Messages
88
Reaction score
15
First Language
Italian
Primarily Uses
RMMV
Hello!
I'm making for my project a weakness/resistance system that doesn't use rates, but fixed values. For example, an enemy with resistance to Fire i'll make it that he removes 5 damage points from the total damage received from Fire attacks.
To do this, though, i need to be able to check the elemental damage inflicted by the weapon equipped by an actor. I tried looking for the right function to get the weapon's element ID, but i can't find it. Could you help me with this? Thanks in advance!
 

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,729
Reaction score
4,685
First Language
English
Primarily Uses
RMMZ
First of all, an actor can have more than one weapon, so I'll assume you're looking for the the elemental id of the first weapon. Second, I'll assume there's only one element per weapon, as my code will stop looking after the first traits that defines the weapon attack element (not to be confused with element rate in the first page of the traits). Here's the code which will return the element id, and if there's none it will return 0:
Code:
var weapon = $gameActors.actor(1).weapons()[0];
var element = 0;
for (var i = 0; i < weapon.traits.length; i++) {
    if (weapon.traits[i].code == 31) {
        element = weapon.traits[i].dataId;
        break;
    }
}
return element;

I've moved this thread to Learning Javascript. Please be sure to post your threads in the correct forum next time. Thank you.

 

Randor01

Veteran
Veteran
Joined
Dec 24, 2018
Messages
88
Reaction score
15
First Language
Italian
Primarily Uses
RMMV
First of all, an actor can have more than one weapon, so I'll assume you're looking for the the elemental id of the first weapon. Second, I'll assume there's only one element per weapon, as my code will stop looking after the first traits that defines the weapon attack element (not to be confused with element rate in the first page of the traits). Here's the code which will return the element id, and if there's none it will return 0:
Code:
var weapon = $gameActors.actor(1).weapons()[0];
var element = 0;
for (var i = 0; i < weapon.traits.length; i++) {
    if (weapon.traits[i].code == 31) {
        element = weapon.traits[i].dataId;
        break;
    }
}
return element;
[MOVE]Learning Javascript[/MOVE]
I see, so the Element is stored in the traits.
Thank you so much!


EDIT: I've decided to work the code around to make it possible to get more than one element from a weapon. Here it is:


Code:
var a = $gameActors.actor(1);
var weaponElement = [];

if(a.weapons()[0] == null)
{
   weaponElement.push(1);
}
else
{
   for (var i = 0; i < a.weapons()[0].traits.length; i++)
   {
      if (a.weapons()[0].traits[i].code == 31)
      {
         weaponElement.push(a.weapons()[0].traits[i].dataId);
      }
   }
}
With the first If condition you avoid an error message when the actor has no weapon equipped
 
Last edited:

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

Latest Threads

Latest Posts

Latest Profile Posts

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.
time for a new avatar :)

Forum statistics

Threads
106,017
Messages
1,018,356
Members
137,802
Latest member
rencarbali
Top