RPGXP: Battle engine redux?

Alright, so lemme kick off by saying that I do have a limited knowledge of scripting.

However, something I notice more often than not is that I need to choose something that RPG Maker XP doesn't consider valid (ie. enemy and skill-user, or all allies AND enemies), and I'm looking for variables that are hard-to-fetch (ie. skill user's [HP/total] as %).

All I'm requesting is a system that allows for a bit more flexibility in whom/what to choose for variables. If it's injections into Game_BattleAction and a few other places, then I'm all for it, and I AM willing to collaborate with any potential takers. If it's just Common Events pointing to a custom-scripted event, then that's also very much viable as a "toolkit" for people to use on here too.
I don't know about allies and enemies, but for something like HP percent, you can use the event commands
Image
Is there anything else you'd need the script to do?
The script would need to enable something like being able to "swap" a user's HP with an enemy by % (your example helps a bit, thanks) for the most part. Other things, I can probably add on my own afterward, I just really can't tangle with the scripting engine that well when it comes to battles.

To run through the process:

Case 1:
> At <30% HP, enemy uses "Swap" skill.
>> Target's new HP = (Enemy's HP/Enemy's MaxHP)*Target's MaxHP
>> Enemy's new HP = (Target's HP/Target's MaxHP)*Enemy's MaxHP
> Battle resumes like normal afterward.

Case 2:
> Enemy uses "Homemade Explosive" skill.
>> if rand(20)>10: Targets opposite party, else: targets EVERYONE.

I have a feeling now that everything I'm asking for is natively supported somewhere. ><;

Edit: I'm trying to think of other cases where the script I suggested would actually come in handy, but I can't think of anything serious that's all that useful. >.<;
Oh for enemies too, right. How could I miss that? XD
To access the current battler's information, you can put this anywhere and then you can read their info with a script call.
  1. class Scene_Battle
  2.   attr_reader :active_battler
  3.   attr_reader :target_battlers
  4. end
Expand to see the code.

Then use $scene.active_battler or $scene.target_battlers in a script call in a common event. It will work in a battle event though, but it will use whatever enemy is currently attacking when the code fires, so be careful.
Also, use $scene.target_battlers[0] if there is only one target as it is an array of battlers.
To do your swap skill, it'd be something like this (this is purely theoretical, I haven't tested it)
Image

It's very difficult to fiddle with the targeting system that's implemented, and from quickly browsing over it, I can't seem to find an effective way to do so. Perhaps someone else here is more familiar with the battle system and can show me otherwise :P
In the mean time, I suggest creating two copies of the skill and one which triggers the other two. Run the calculations in the first common event and then force a skill use of one of the other two.
So, after following your suggestions...
Content Hidden Spoiler
Image
Image

...and fully implementing it for testing...
Content Hidden Spoiler
Image

...I get this:
Image

Testing with $scene.target_battlers[0] on the first line to see if that makes a difference...

...It says "Miss", but it actually procs! WE LIVE!

Here's the edited code for anyone else that was reading along, I personally slapped it as a Common Event, but as long as it's a script handled by RPG Maker XP's 'Script...' function, and called in battle, you should be fine.
  1. t=$scene.target_battlers[0]
  2. c=$scene.active_battler
  3.  
  4. thp = (c.hp.to_f/c.maxhp.to_f)
  5. chp = (t.hp.to_f/t.maxhp.to_f)
  6.  
  7. t.hp = (thp*t.maxhp.to_f).to_i
  8. c.hp = (chp*c.maxhp.to_f).to_i
Expand to see the code.


Summary of thread so far:
Content Hidden Spoiler
Inject this in Scene_Battle:
  1. class Scene_Battle
  2.   attr_reader :active_battler
  3.   attr_reader :target_battlers
  4. end
Expand to see the code.

Make the 'Swap' attack call this script:
  1. t=$scene.target_battlers[0]
  2. c=$scene.active_battler
  3.  
  4. thp = (c.hp.to_f/c.maxhp.to_f)
  5. chp = (t.hp.to_f/t.maxhp.to_f)
  6.  
  7. t.hp = (thp*t.maxhp.to_f).to_i
  8. c.hp = (chp*c.maxhp.to_f).to_i
Expand to see the code.

...and you're laughin'.

-------------------------------------------------------
Now, case #2: Targeting all enemies and all party members. (Currently working on that)

Edit: ...I've introduced an animation bug, but... ...I managed, though the results are a little buggy! xD
Content Hidden Spoiler
Injected into Scene_Battle 4:
Image
and
Image
There's a little extra stuff for you to figure out your way there. Anyways, onto the Common Event:
Image
Here's the copy/pasta code I have:
  1. $scene.set_target_battlers(8)
  2. $scene.make_skill_action_result
  3. $scene.update_phase4_step3
  4. $scene.update_phase4_step4
  5. $scene.update_phase4_step5
  6. $scene.update_phase4_step6
Expand to see the code.

Just set up the rest, and... ...success?

Known bug(s): The attack doesn't get the post-attack delay?


Edit: Spoiler'd the images so they're not all gaudy and gross right off of the bat. =P
Ah yes, sorry about the typo. Looks like you know how to sort things out yourself, I see 😀
Have you tried my "Collection"? It has a ton of enhancements to the XP Battle System, yet retains all of the features, such as being able to Event a Battle, Bosses, etc.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=78543