TheGentlemanLoser

"And when we fall, we will fall together..."
Veteran
Joined
Dec 30, 2020
Messages
337
Reaction score
446
First Language
English
Primarily Uses
RMMV
The variable in this case being an actor's jp from YEP_JobPoints. I want to know how to get an actor's current jp from the plugin as a variable so I can then display that variable with OrangeHud/OrangeHudLine (somewhere near where MOGActorHud is displayed on screen, hopefully getting it to look more or less like one semi-coherent HUD).

The second part is straight forward (I mean until the MOG stuff gets involved) and the first part seems like it *should* be pretty straight forward too but I mean take that with a grain of salt because I know like freaking nothing. Anyway, the question is, how do I extract an actor's jp from YEP_JobPoints and store it in an RPG Maker variable?
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,917
Reaction score
3,151
First Language
English
Primarily Uses
RMMZ
$gameVariables.setValue(id of variable, $gameActors.actor(id of actor).jp(id of class you want to get JP for))

You can also use $gameParty.members()[index] if you want to do it for a particular party slot rather than a specific actor.
 

Restart

Veteran
Veteran
Joined
Mar 15, 2019
Messages
848
Reaction score
712
First Language
English
Primarily Uses
RMMV
The plugin has some plugin commands listed. the set jp one is probably involved in an actor's jp value
Code:
  *   setJp actorId jp
 *   setJp actorId jp classId
 *   Replace 'actorId' with the ID of the actor you wish to change the JP of.
 *   Replace 'jp' with the amount of JP you wish to alter. If you are using
 *   'classId', replace it with the ID of the actor's class you wish to alter.
 *   This command will set the actor's JP to a particular value.
do a control+f for 'setjp'

Code:
Game_Actor.prototype.setJp = function(value, classId) {
    value = parseInt(value);
    if (value === NaN) value = 0;
    classId = classId || this.currentClass().id;
		if (!this._jp) this._jp = {};
    if (!this._jp[classId]) this._jp[classId] = 0;
    this._jp[classId] = Math.max(0, value);
    if (Yanfly.Param.JpMax > 0) {
      this._jp[classId] = Math.min(Yanfly.Param.JpMax, value);
    }
};

This is the function that sets jp for an actor.

It looks like the jp is set right at the end, with the line
Code:
      this._jp[classId] = Math.min(Yanfly.Param.JpMax, value);
also, jp is class specific. Fortunately we can see that classId can be set to the current class with this.currentClass().id;

so within a Game_Actor expression, this function will return their JP with the current class:
Code:
this._jp[this.currentClass().id]

if you want a more general case, you need to reference the actor object somehow, and replace 'this' with the reference.

How do we reference the actor object? Well, looking at the script call list
Code:
$gameActors.actor(actorId).gainMp(n)	

Also allow using party member index: $gameParty.members()[index].gainMp(n)

So our final would look like
Code:
$gameParty.members()[index]._jp[$gameParty.members()[index].currentClass().id]
where 'index' is what slot the party member has.
 

TheGentlemanLoser

"And when we fall, we will fall together..."
Veteran
Joined
Dec 30, 2020
Messages
337
Reaction score
446
First Language
English
Primarily Uses
RMMV
Thanks guys! Trying to wrap my big smooth brain around this stuff! I'll let you know how it goes.
 

TheGentlemanLoser

"And when we fall, we will fall together..."
Veteran
Joined
Dec 30, 2020
Messages
337
Reaction score
446
First Language
English
Primarily Uses
RMMV
$gameVariables.setValue(id of variable, $gameActors.actor(id of actor).jp(id of class you want to get JP for))

You can also use $gameParty.members()[index] if you want to do it for a particular party slot rather than a specific actor.

So, in the latter case, $gameVariables.setValue(id of variable, $gameParty.members()[1].jp)?

So essentially, the YEP Job Points plugin added a ".jp" "suffix" variable to all $game.Actors/$gameParty.members entities? And I'm assuming the (id of class you want to get JP for) argument is optional since I'm not using YEP Class Change System or anything of that sort.

Lemme see if I can't get this to work then come back and edit this post.
 
Last edited:

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,917
Reaction score
3,151
First Language
English
Primarily Uses
RMMZ
So, in the latter case, $gameVariables.setValue(id of variable, $gameParty.members()[1]).jp?

So essentially, the YEP Job Points plugin added a ".jp" "suffix" variable to all $game.Actors/$gameParty.members entities? And I'm assuming the (id of class you want to get JP for) argument is optional since I'm not using YEP Class Change System or anything of that sort.

Lemme see if I can't get this to work then come back and edit this post.
Yes, though your end bracket needs to be after the .jp and not the [1].

And yeah, it does indeed add a jp property to all actors. The class ID is not optional; even if you're not using Class Change System, the JP is still stored individually for each class, so if the actor ever changes classes their JP count will be different.
 

TheGentlemanLoser

"And when we fall, we will fall together..."
Veteran
Joined
Dec 30, 2020
Messages
337
Reaction score
446
First Language
English
Primarily Uses
RMMV
Thank you, I was in fact fishing for the correct terminology.

so this is the simple common event I set up for the script call which isn't working
hmm.png
trouble shooting first thing yes switch 3 is on I'm dumb but I'm not that much of that particular *kind* of dumb at least not today let's see one other thing I can think of...

edit: AHA! Yes, I guessed correctly, $gameParty.members() needed a [0] not a [1] bcuz the first index is 0 for some reason, except when it isn't (IIRC RPGM has not been terribly consistent about this).

2021_6_10_17_42_51_866_4558.png
Thanks y'all!
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,917
Reaction score
3,151
First Language
English
Primarily Uses
RMMZ
What you interpret as inconsistency is actually some clever coding practices that simply can't be applied universally.

When you do this, you're accessing an array index directly. Arrays in Javascript are 0-indexed; the first element is always 0, just because of the way arrays work.

However, you'll note that database item IDs always start at 1. It'd be a bit of a hassle to expect developers to always know that they need to subtract 1 from any index they use so that the correct database entry is returned, so every array involving database objects uses "null" as its 0-index entry and starts its actual entries at 1, so that each array matches up with its respective database.

That's why the call for an actor is, say $gameActors.actor(1) to get the 1st actor in the database, but it's $gameParty.members()[0] for the same actor if actor 1 is the party leader (in the first, you're supplying an actor ID to a function, and in the second you're directly accessing an array of actors). You could theoretically do $gameActors.actor(0) but it would give you null because that's the value in the 0 index of the actors list.
 

TheGentlemanLoser

"And when we fall, we will fall together..."
Veteran
Joined
Dec 30, 2020
Messages
337
Reaction score
446
First Language
English
Primarily Uses
RMMV
cool!

right, so as far as the class argument (PC is one of six actors and belongs to one of 3 classes that will not change after game start/character creation) what is the workaround for that? I could work around the actor ID thing w/ basic conditional branches if you hadn't pointed out that $gameParty.members could be used instead (there are six playable 'races' using six actors set up in the DB) so I guess I could use nested conditional branches like so...

hmm2.pngbut it feels like there must be a less kludgy & cumbersome way of doing that
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,917
Reaction score
3,151
First Language
English
Primarily Uses
RMMZ
Restart already gave you the answer for this one: look at what he said about the currentClass() function.
 

TheGentlemanLoser

"And when we fall, we will fall together..."
Veteran
Joined
Dec 30, 2020
Messages
337
Reaction score
446
First Language
English
Primarily Uses
RMMV
Excellent!
Code:
$gameVariables.setValue(20, $gameParty.members()[0]._jp[$gameParty.members()[0].currentClass().id])

seems to work like a charm.

In hindsight is there some reason

Code:
$gameVariables.setValue(20, $gameParty.leader().jp())

would not have worked?
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,917
Reaction score
3,151
First Language
English
Primarily Uses
RMMZ
No reason whatsoever. $gameParty.leader() returns the same object as $gameParty.members()[0] does. I think the only reason we gave you the index method was that you didn't specify you only wanted the leader for your effect.
 

Latest Threads

Latest Posts

Latest Profile Posts

I'm seeing my god daughter's school play next week. Being the mild agoraphobe I am this makes me nervous. Thus I had a dream that it was actually a plot by my best friend to take me clubbing at an establishment where it is customary to throw a harpoon at staff members to reward good service.
Praise be to the game make!
I need help on what I should add to this fighter game.
Should I add:
Rain
Sleet
Snow
Leaves
Wind
If you can come up with anything else let me know.
Final day of the kickstarter campaign and my team and I decide to cap it off by doing ... musical numbers online.

These are clearly definitely My People.
6 hours and 35 minutes until it is December first here :3

Forum statistics

Threads
117,087
Messages
1,104,450
Members
153,079
Latest member
Lnaunboq
Top