Getting Meta from state affecting character or monster.

Status
Not open for further replies.

Khulse

Villager
Member
Joined
Jan 2, 2019
Messages
16
Reaction score
6
First Language
English
Primarily Uses
RMMV
So I've figured out how to get the meta information added by note tags from the excellent little tutorial in https://forums.rpgmakerweb.com/index.php?threads/write-a-plugin-that-reads-notetags-beginner.100228/

Unfortunately, there's a lot of things that it sounds like should be possible that aren't covered. Looking in the console, I've also figured out how to get the note tag meta from the states, and so forth. The problem I'm running into is that I'd like to retrieve the data from a state on the character using both scripts (like in a plugin or script entry in events) and damage formulas. Knowing how to get the meta from a character's equipment and class would also be useful.

Obviously, I'm an amateur when it comes to scripting. Please keep any explanations as simple as you can...

Warning: Wall o' Text...
To be a little more specific, I'm setting up things up with each monster having two different types. There are only ten types, but a LOT of monsters. It would be a great deal more efficient to set up the type traits for each monster using passive states from yanfly's passive states plugin than setting them up for each individual monster, and putting any variation specific to that monster in the monster's own traits. So, each type would be linked to a passive state, ect.
There's some additional information associated with each type- such as the types name and an associated number for pulling off the monster and putting in a variable for events and damage formulas and so forth. As an added layer of complication, some characters will also have these passive states, as they are 'monsters' in lore terms, and will even have their monster type listed in the character status screen (thanks to the example in the tutorial I mentioned above).

I've already figured out how to do all that using note entries in each individual monster or character (type1:name, type1id:x, type2:name, type2id:x are the note entries). It would make life a whole lot easier if I could stick those note entries in the states instead of each individual monster and then retrieve it using a method similar to what I've already figured out how to do. I'd have to copy each state and have one add the type1 notes and the other add type two notes, but that's no big deal.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
In order to get state meta from character using script:

Code:
$dataStates[$gameActors.actor(1)._states[0]].meta
or if you want from first party member:
Code:
$dataStates[$gameParty.members()[0]._states[0]].meta
Getting meta from actor's class:
Code:
$dataClasses[$gameActors.actor(1)._classId].meta
Getting meta from actor's equips (for this purpose I'll be saving it to designated variables ranging from 21 to 21 + the amount of equipped items just for variance):
Code:
for (var i in $gameActors.actor(1)._equips) {
var id = $gameActors.actor(1)._equips[i]._itemId;
if (!id) continue;
if ($gameActors.actor(1)._equips[i]._dataClass == "weapon") $gameVariables.setValue (21 + i, $dataWeapons[id].meta);
else $gameVariables.setValue(21 + i, $dataArmors[id].meta);
Then you can use this meta for whatever reason you might want to use it.

As for skill damage formula, you replace $gameActors.actor(1) with a for user and b for target. Just be prepared to make some sanity checks and don't check enemy for equipment, they don't have it :D
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,087
Reaction score
1,508
First Language
EN
Primarily Uses
RMMZ
There's a states function available to return the $dataStates entries, which may be a better plan than checking _states, particularly if you're using plugins like Yanfly's Passive States:
Code:
console.log($gameActors.actor(4).states());
Also, you may find the traitObjects function useful: it returns all relevant database (i.e. meta-bearing) objects for a battler, e.g. actor|enemy, equips, states, etc:
Code:
var isCheese = actor.traitObjects().some(function(o) { return o.meta.type1 === ' cheese'; });
 

Khulse

Villager
Member
Joined
Jan 2, 2019
Messages
16
Reaction score
6
First Language
English
Primarily Uses
RMMV
@Poryg Thank you very much!

That works perfectly for the damage formulas. Now how would I get it to 'draw' metadata to the menus in place of, say, the nickname?

When I try to set it up, I get 'actorId is undefined if I put actorId in place of the actor id number, cannot read _states of undefined for actor or this, and it doesn't show anything at all if I use a specific Id number (but it doesn't crash or throw an error, either).

If I try to set it up by adding $dataStates[$gameActors.actor(actorId)._states[0]].meta to Game_Actor.prototype.setup the way the tutorial I mentioned adds race I get a maximum call stack size exceeded error. I didn't really expect that to work, though.

My quick and dirty plugin to test it currently looks like this:

//=============================================================================
// TypeFromStateExpiriment.js
//=============================================================================
/*:
*/

(function() {

var drawTypeInStatusWindow = Window_Status.prototype.drawActorNickname

Window_Status.prototype.drawActorNickname = function (actor, x, y, width=270) {
this.resetTextColor();
this.drawText($dataStates[$gameActors.actor(1)._states[0]].meta.Type1, x, y, width);
};

})();

What can I put in place of 1 that will tell the game 'the actor who's status I'm looking at'?

@caethyril

I actualy tried the states function, which I found using the console. It didn't know what I was talking about when I tried to get it to pull up the metadata attached to those states, though. It just seems to list the states on the actor, and that's it.

I'll admit I don't understand the example use of traitObjects you supplied. What is some(function(o)?
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
You cannot use anything that is not defined. So if you use actorId and it is undefined, well, it will not yield anything useful.
What you can do is dedicate a variable to hold the actor ID and then use $gameVariables.value(1) to read the actor's ID.

So it would look like
Code:
$dataStates[$gameActors.actor($gameVariables.value(1))._states[0]].meta
Also, you need to remember that Javascript is case sensitive and type1 is not the same as Type1.
 

Khulse

Villager
Member
Joined
Jan 2, 2019
Messages
16
Reaction score
6
First Language
English
Primarily Uses
RMMV
So, I got it working the way I want, at least for the most part. There's a bit more I want to do with it, but the basics are working.

The fundamental issue I was encountering is that if any part of $dataStates[$gameActors.actor(id#)._states[0]].meta.Type1 is undefined when the game tries to call it the game will crash. It doesn't matter a bit if you've put in an || to a valid statement after it, it crashes when it tries to check. Same goes for an if statement that checks it.

Likewise, $dataStates[$gameActors.actor(id#)._states[0]].meta.Type1 does not seem to be able to use several of the different methods for pulling a particular instance of an actor's ID that I've seen used, such as actorId. I'll admit that was probably something I was failing to do. The odd thing is that I'd have actorId work in other ways in the same script, it just would NOT work in that particular line. I finally looked through the initial actor setup in the rpg_objects js and found actor._actorId - as I recall, _actorId didn't work. It has to be the whole thing. Once you put that in there, the game manages to figure out which actor you want to test in that instance.

In order to get it to work, I had to test $gameActors.actor(actor._actorId)._states[0]] by itself for validity.

On another note, $gameVariables.setValue(9, $dataStates[b._states[0]].meta.Type1Id) in a damage formula will set variable 9 to the value of Type1Id, and it doesn't crash the game if the target doesn't have the appropriate note tags on any of it's states, it just defaults to 0. Be warned, however, that it will mess up any of the damage formula that comes after it when invalid. ANY numbers that come after it in the damage formula turn into a 0.

This is the final result of my experimenting. Note that this is not a complete plugin by any means, just a test.

//=============================================================================
// TypeFromStateExpiriment.js
//=============================================================================
/*:
*/

(function() {

var drawTypeInStatusWindow = Window_Status.prototype.drawActorNickname;

Window_Status.prototype.drawActorNickname = function (actor, x, y, width=270) {
this.resetTextColor();
// test for validity, and default to nickname if it isn't. Can't test the whole statement, that crashes the game.
if ($gameActors.actor(actor._actorId)._states[0] === undefined) {
Type1 = actor.nickname();
} else {
// if ($gameActors.actor(actor._actorId)._states[0] IS valid, go ahead and run. If there's no type1, the nickname field will just be blank.
Type1 = $dataStates[$gameActors.actor(actor._actorId)._states[0]].meta.Type1 || actor.nickname(); // of course, a blank field isn't cool, so toss in an alternative.
}
this.drawText(Type1, x, y, width);
};

// and that's all folks. This was a lot harder than I expected it to be!

})();

Thank you Poryg, I could never have managed this without your help.

This thread may be closed now.
 
Last edited:

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,087
Reaction score
1,508
First Language
EN
Primarily Uses
RMMZ
I realise you've solved it, but to answer your questions:
I actualy tried the states function, which I found using the console. It didn't know what I was talking about when I tried to get it to pull up the metadata attached to those states, though. It just seems to list the states on the actor, and that's it.
Each of those states should (they do for me) have a meta property. You'd need to specify an index first, e.g. the meta of the first state on the party leader:
Code:
$gameParty.members()[0].states()[0].meta
I'll admit I don't understand the example use of traitObjects you supplied. What is some(function(o)?
Array.some is a function that returns true iff at least one entry of the array satisfies the callback function. So, my example should set isCheese to true if the battler stored in the actor variable has a <type1: cheese> notetag on it or any object "attached" to it (equips, states, etc), else isCheese = false. Here's the MDN article on it in case you're interested: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some
 
Status
Not open for further replies.

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

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,847
Messages
1,016,972
Members
137,561
Latest member
JaCrispy85
Top