MV Javascripting to lose tp.

Hello!


I have a rts style combat system in which you are able to pick up items on the floor during combat at the cost of 1 tp point with events! It works great save for the fact that I could only find out how to take it off actor 1 as opposed to the actor doing the action 🙁.

So I had an idea, I make an invisible state that applys at the beginning of a turn and goes away at the end. An active player sort of deal. Maybe I can find a way using Javascript for an event to only subtract tp from players with that state? I am not the best at javascript and while I'm slowly learning it is a process. Thank you so much in advance
When using a state for that, you can do something like this inside your event:

JavaScript:
$gameParty.members().forEach((actor) => {
    if (actor.isStateAffected(XX)) {
        // reduce tp of actor
    }
});
Replace XX with the state ID you want to use.
This will loop over your characters and checks if an actor is affected by your state.
Thank you! I feel like I'm close but I am not quite hitting it.

Capture.PNG


Or perhaps I am entering it in wrong. The active player properly applies at turn start but the Tp remains unaffected.
That "reduce tp of actor" was just a placeholder comment, it doesn't actually do the TP loss. 😛

What you want is

Code:
actor.gainTp(-1)
Oops! Forgot about that. Clearly I am genius! Thank you! That said it now sort of works! It looks like it takes the 1 AP off those without the state.
Right now it'll loop through every actor and take 1 TP away from any that has the state.
I appreciate all the help! This type of eventing may be impossible with the battle plugin ( Letbs) I am running. I may need to go back to the drawing board and find another way to have that actor lose tp or remove the TP cost for picking up items in battle. Regardless I appreciate everything guys.

Capture.PNG
Make sure you remove the // that makes it a comment.
You are my hero! Thank you!
As a follow up is there a way to check if the TP of the actor with said state is >= 1 for a conditional branch. I have it for the just the actor and it works great, but if I am to implement this with any party member affected by such state it becomes more complicated.
Capture.PNG
One way would be to use a control variable to store the id of the affected actor when you give said actor the state

that way you could use the value of that variable to get the right actor for that if statement and you won't have to use the forEach loop afterwards, as you already know the actor with that state.

I don't know how you are currently applying that state, though
I have a passive state on each class that has a turn start effect that gives the active player state ( or state 193) which is a state that lasts for one turn and is reapplied automatically when its that players turn.
Capture.PNG


This helps the event know who is trying to pick up the item to deduct the TP from. (Which now happens thanks to you guys!)

I want to now make a conditional branch that disables the ability to pick up an item if the actor with the "Active Player" state has less then one TP. Something like this.

Capture2.PNG

I just need to java formula to kinda make that happen... Once this is solved, it will finally fully fix my overly painful to develop item system and then I can finally find true "Nirvana". or ya know...something like that.
I see.
try adding this inside the note tag

JavaScript:
$gameVariables.setValue(XX, a._actorId)

and for the If statement
JavaScript:
$gameActors.actor($gameVariables.value(XX)).tp >= 1

replace the "XX" with an unused control variable number, but make sure that the number isn't higher than your max control variables

If it works, you can remove the forEach loop you added earlier and just use
JavaScript:
$gameActors.actor($gameVariables.value(XX)).gainTp(-1)
Just to clarify. In my Active Player state, I will be adding this note. (selected 153 because that was an unused variable on file)
Capture.PNG

Then on my event I will add this...

Capture2.PNG
wait...
yeah, 's looking good. but be sure to put the code in the note inside your <Custome Turn Start Effect> tag you showed me earlier
Alright perfect. Would I also need to set an end turn effect to remove the variable?
Kiriseo, I do not know how that worked, but it works perfectly. Thank you so much! I am going to name my first imaginary kid after you!
Alright perfect. Would I also need to set an end turn effect to remove the variable?

everytime the start turn effect is used, it will set the variable to a new value, so it shouldn't be necessary.

Kiriseo, I do not know how that worked, but it works perfectly. Thank you so much! I am going to name my first imaginary kid after you!

your welcome 😂

Original thread: https://forums.rpgmakerweb.com/threads/javascripting-to-lose-tp.126507/