Howdy,
I'm trying to figure out the simplest way for a script to figure out whether an attacker (specifically: a skill user during battle) is an Actor or an Enemy, then do X to either all in-battle Actors or Enemies. The structure would look something like:
if CURRENT_SKILL_USER == AN ACTOR$game_party.members.each { |actor|if !actor.dead?actor.mp +=1end}ELSE[ADD 1 MP TO ALL ALIVE, ACTIVE ENEMIES]ENDThe current add-1-MP-to-actors code works fine. I'm not sure (1) how to distinguish between Actors and Enemies using the skill and (2) how to tell the script to find all current alive enemies and give them MP.
Thanks much! :)
Script to identify whether attacker is actor or enemy?
● ARCHIVED · READ-ONLY
-
-
You could just make two versions of the skill, one to be used by actors and one to be used only by enemies. Attach a common event and conditional branch for if they're alive or not, and to execute the MP gain effect. Yay?
-
Thanks for the reply!
Actors and Enemies share 100+ skills, so that'd be pretty time-consuming to copy over -- let alone maintain! It'd be much easier to have the skill identify whether the user is an Actor or Enemy.
Also, still not sure how to express "target all the currently living enemies on the battlefield." ;) -
No.
Game_Battler has a method called friends_unit that will give you either $game_party (if your battler is a party member) or $game_troop (if your battler is an enemy).
On the opposite side, there's also an opponents_unit method.
So just do
Code:orfriends_unit.each {|friend| friend.mp += 1}
Code:Whether you have to prefix friends_unit and opponent_unit with an actor or enemy object will depend on where you're putting your snippet of code (you should have at least given us the class you're putting it in, so we know the scope).opponents_unit.each {|opponent| opponent.mp += 1} -
Genius level. Thanks very much! I'll give it a spin and let you know how it goes. :)
-
Shaz: could you explain what you mean further?
Right now, the code you gave me is sitting in a Common Event that I'm triggering as part of the skill use (so: instead of adding a state). It doesn't seem to be working either there or as part of the skill's damage output box separated by a semicolon. -
you could add the code in your damage formula instead. with some checking
a.is_a?(Game_Actor)
you might want to see article by formar on how to use damage formula. -
a.is_a?(Game_Actor) and a.actor? would return exactly the same thing.
That's why I said you should have told us where you're putting it. What you posted in the first post is a script, so I assumed you were writing a script. If you'd said common event or damage formula, it would have been a lot easier.
So, you just want to give all living members of the opposite side +1 MP?
In the damage formula, put this:
Code:And where I typed <original damage formula>, don't type that - put in the actual damage formula (I know - might sound obvious, but you'd be surprised how many would type EXACTLY that).a.opponents_unit.each {|enemy| enemy.mp += 1 if enemy.alive?}; <original damage formula> -
Thanks again! This is all coming clearer. But I feel super nubbly: I didn't clarify that the goal is to give the user's own side +1 MP. So presumably instead of opponents it's friends and enemy it's actor?
-
Then, as I said, replace opponents_unit with friends_unit depending on what you want to do.
Code:And if you want to give it to everyone EXCEPT the person who's using the skill or item, do this:a.friends_unit.each {|friend| friend.mp += 1 if friend.alive?}; <original damage formula>
Code:It doesn't matter whether you call them enemy or friend in the block. You could just call them battler.a.friends_unit.each {|friend| friend.mp += 1 if friend.alive? && friend != a}; <original damage formula> -
The following is kicking the 0 damage/no TP gain bug:
a.friends_unit.each {|friend| friend.tp += 1 if friend.alive?}; a.atk * 2 - b.defSomething broken with the code, or? -
what 0 damage / no TP gain bug?
What is the actor's ATK? What is the enemy's DEF? -
I've noticed that when something's wrong in the damage formula, the game will sometimes kick 0 damage results regardless of stats (and refuse to process whatever else is going on in the damage formula window).
ATK and DEF are both 3, variance is 25, so damage should be happening. -
a.atk * 2 - b.def
3 * 2 - 3
6 - 3 = 3
With a variance of 25, you could get a 0 damage result.
I wonder if the variance calculation would force it to still be non-zero if it starts at non-zero and it subtracts to be less than zero.
Try removing the bit about the tp (everything up to and including the ; ) and just leave the formula, and see if it still happens. Of course you might need to play a few times if it's a bit random.
You didn't say (or I've read it and forgotten) if you're using any custom battle scripts? -
I thought Variance was interpreted as a percentage +/- -- so shouldn't 25 variance on a damage output of 3 be (3 +/- 0.75)?
I tried the whole damage formula after hiking ATK to 100; it still kicks a damage of 0, no TP change.
I tried it with just the damage portion; it worked fine.
It tried it with just the TP portion; it didn't work.
I'm running gubid's tbs. -
Can you give a screenshot of your skill/item, and also copy/paste the formula here, just so we can make sure there's no typos or anything?
-
Sure. Here's the screenshot. Here's the code:
Code:a.friends_unit.each {|friend| friend.tp += 1 if friend.alive?}; a.atk * 2 - b.def -
I'm not at home so I can't test it, but I really don't see anything wrong with that. Can you try adding a space before the closing } and see if it makes a difference? Also change friend to f just in case there's a length limit on the damage formula.
a.friends_unit.each {|f| f.tp += 1 if f.alive? }; a.atk * 2 - b.def
Does anyone recall if there's a limit on the damage formula length, and how much? -
Add this to your scripts and try your skill again.
Code:class RPG::UsableItem::Damage def eval(a, b, v) [Kernel.eval(@formula), 0].max * sign endend -
should be friends_unit.members.each or friends.unit.alive_members.each
Code:a.friends_unit.alive_members.each {|friend| friend.tp += 1}; a.atk * 2 - b.def