Store actor position in a variable (and more!)

Ahoy hoy,

So my primary query is how to get an actor's position in the battle party and store it in a variable. There's a lovely limitation on both Force Action and Deal Battle Damage that it can only be applied based on position, rather than specific party members. I've tried using this but I'm pretty sure it's wrong:

var99 = $game_party.actors.index(3) (with the intent of getting the position of Actor 3)

I'm trying to accomplish two things:

An enemy skill that deals exactly enough damage to each party member that they are left with 1HP remaining. I accomplished this via a general Script Call (set HP to 1), but naturally that doesn't play hurt reactions, nor does the battle status update after that. It just doesn't look as good as an actual damage command. I'd much rather be doing a HP calculation and applying damage that way. Change HP also doesn't deal damage.

A player skill that uses a set of consecutive actions-- a skill that force actions several more skills after itself provided the skills are learned. Only one actor is able to use these particular skills, so on the skill's use I need to know what position she's in to force her to use the actions.

I'd also love to know if there is a means to force refresh the battle screen, namely battle status, actors and enemies (I'm using animated battlers and have had issues with troops not appearing after an 'Enemy Transform' is run, until they use a command. I've brute forced it by making them use a 'null skill' immediately after transformation, but its not infallible.) It may not be possible with anim. battlers though, and that's fine.
I don't have XP available, but in all the later makers that I know of there was never a need for a script to do this, it was a default game data option in the control variable command.
was that not the case in RMXP?
Ahoy hoy,

So my primary query is how to get an actor's position in the battle party and store it in a variable. There's a lovely limitation on both Force Action and Deal Battle Damage that it can only be applied based on position, rather than specific party members. I've tried using this but I'm pretty sure it's wrong:

var99 = $game_party.actors.index(3) (with the intent of getting the position of Actor 3)

I'm trying to accomplish two things:

An enemy skill that deals exactly enough damage to each party member that they are left with 1HP remaining. I accomplished this via a general Script Call (set HP to 1), but naturally that doesn't play hurt reactions, nor does the battle status update after that. It just doesn't look as good as an actual damage command. I'd much rather be doing a HP calculation and applying damage that way. Change HP also doesn't deal damage.

A player skill that uses a set of consecutive actions-- a skill that force actions several more skills after itself provided the skills are learned. Only one actor is able to use these particular skills, so on the skill's use I need to know what position she's in to force her to use the actions.

I'd also love to know if there is a means to force refresh the battle screen, namely battle status, actors and enemies (I'm using animated battlers and have had issues with troops not appearing after an 'Enemy Transform' is run, until they use a command. I've brute forced it by making them use a 'null skill' immediately after transformation, but its not infallible.) It may not be possible with anim. battlers though, and that's fine.
$game_actors[3].index

Refreshing the battle windows is a bit more complex, since Scene_Battle doesn't expose any of its instance variables. You'd have to add a script that declares the windows as attr_writer or attr_accessors and call their refresh methods or manually write a method you can call in the scene that refreshes the windows.
I don't have XP available, but in all the later makers that I know of there was never a need for a script to do this, it was a default game data option in the control variable command.
was that not the case in RMXP?
Nope, not in XP, its not part of its variable functions. I'd prefer not to be using it but its an update to an old project rather than a fresh one.
$game_actors[3].index

Refreshing the battle windows is a bit more complex, since Scene_Battle doesn't expose any of its instance variables. You'd have to add a script that declares the windows as attr_writer or attr_accessors and call their refresh methods or manually write a method you can call in the scene that refreshes the windows.
Hm, not having any luck. I am probably using the wrong method of assigning the data to the variable though, because XP doesn't have Script option for control variables, and google has been unhelpful on how to do this incredibly basic thing :rtear:

var99 = $game_actors[3].index didn't work, nor does $game_variables[99] = $game_actors[3].index
The latter should work. Is it not changing the value of the variable?
I'm getting argument errors with it. I just also tried changing the [3] to [2], as I thought maybe it was because its trying to get the actor in position [3] when the game only has a 3-person party, but I got the same error.

I have one script that involves party switching, but I tried putting it under Main and I still got the error.

Just discovered RMXP also lacks quick script commenting-out, amazing
It seems to be breaking the line, that is, you will need to declare the variable first:
Ruby:
@act_inx=$game_actors[3].index
$game_variables[99]=@act_inx
^
The @ isn't necessary. Alternatively
Code:
$game_variables[99] =
$game_actors[3].index
Though you want to make sure the actor is in the party first. Otherwise, it would be setting the variable to nil, but XP has a preventative measure to return 0 in those cases:
Ruby:
  #--------------------------------------------------------------------------
  # * Get Variable
  #     variable_id : variable ID
  #--------------------------------------------------------------------------
  def [](variable_id)
    if variable_id <= 5000 and @data[variable_id] != nil
      return @data[variable_id]
    else
      return 0
    end
  end

Here's a 1HP remaining script I whipped up. It basically prevents skills from being able to kill the target, like False Swipe from Pokemon, hence the name.
Ruby:
# List of Skill IDs
FalseSwipeDB = [81]

class Game_Battler
 
  def remove_dead_states
    for i in 1...$data_states.size
      if $data_states[i].zero_hp
        remove_state(i)
      end
    end
  end
   
  alias skill_effect_false_swipe_skill_later skill_effect
  def skill_effect(user, skill)
    last_hp = self.hp
    result = skill_effect_false_swipe_skill_later(user, skill)

    if result || self.damage.is_a?(Numeric)
      if FalseSwipeDB.include?(skill.id) && self.hp <= 0
        self.remove_dead_states
        self.hp = 1
        self.damage = last_hp - 1
      end
    end
    result
  end
end
You just configure the array at the top with whatever skill IDs that should always leave 1HP remaining, then configure your skill so that it will always deal max damage. One way to do this would be to create another Knockout/0HP state (I just copy-paste the existing one), have your skill apply it, and ensure every actor class and enemy has an 'A' rating under its State Efficiency. This way, you're applying instant death to the target, but the script will prevent that and will do near lethal damage.
The index variable returning zero is fine, thankfully...

In regards to the script, part of the reason I wanted it to be event code was for the skill to deal exactly enough damage to drop the party to 1HP. I couldn't get your snippet to work correctly, though its almost 100% a settings issues. I do very much appreciate it.

Regarding battle status refreshing, though...

What in RMXP causes the battle status to refresh? Will it have been changed due to using RTAB/DerVVulfman's battle status, or will they be operating under the same methods? I don't really have the coding knowledge to write a custom attr_writer class, so I'm wondering if there's something I can do mid-process that would update it as well.

Applying a instant death state seems to refresh it, which is my method of brute forcing with the 1HP skill currently, but I have other skills that use CEs and it takes far too long for an update to go through. Ideally I'd like to avoid using an 'instant death' as I feel like it could cause problems having the whole party hit zero for a moment, plus it resets their ATB gauge.
Could be possible that the RTAB script isn't compatible with my script. Can you share it? It would also make answering your battle status question better.
Sorry for the delay. Pastebin wouldn't accept it and neither would the site, so here's a dropbox link for it https://www.dropbox.com/s/gp94317h9idb6j2/RTAB.txt?dl=0
and the fix for multi-target, but I don't think that will be involved:
There's definitely more to the script than just that, surely. This has no issues with my script, nor does it cover anything regarding battle states.
There's two links in the post - first one is the one covering RTAB, second one is a scope fix.
Oh, my bad, weird it only created a preview link for one of them.

I ended up having to download the script demo to test.
Ruby:
FalseSwipeDB = [81]

class Game_Battler
  alias skill_effect_false_swipe_skill_later skill_effect
  def skill_effect(user, skill)
    last_hp = self.hp
    result = skill_effect_false_swipe_skill_later(user, skill)

    if result && FalseSwipeDB.include?(skill.id)
      if (self.damage[user].is_a?(Numeric) && self.hp - self.damage[user] <= 0) ||
      self.state_p[user].any? { |n| $data_states[n].zero_hp }
        self.state_p[user].delete_if { |n| $data_states[n].zero_hp }
        self.damage[user] = last_hp - 1
      end
    end
    result
  end
end
Setup is still the same as I described before.

Will look into the battle status thing later.
I'm not sure I understand your battle status issue. I don't exactly have enough information to go off of here to reproduce whatever it is you're seeing. Step-by-step reproduction or a demo would be nice.

Original thread: https://forums.rpgmakerweb.com/threads/store-actor-position-in-a-variable-and-more.147039/