Edit to Escape Penalty script

I'm using this script I found by a person named zSprawl, an escape penalty script that removes a percentage of each actor's experience points upon fleeing. I have my game's escape rate configured to be 100%, and this penalty script is a nice way to prevent abuse of the flee option.

Script:

Spoiler
=begin#============================================================ Title: Escape_Penalty Author: Sprawl Date: August 15, 2013------------------------------------------------------------- ** Change log August 15, 2013 - Initial Release------------------------------------------------------------- ** Description This script adds an escape penalty equal to 0.5% of the totalXP per actor. ------------------------------------------------------------- ** Usage Cut and Paste in the Materials Section. If you have any other scripts that affect escape penalties, things may not work.------------------------------------------------------------- ** Licensing Feel free to use for free or commercial use, but give credit to "zSprawl".------------------------------------------------------------- ** Credits Sprawl -Wrote the Script. Merdouille44 -Replied to my post on the forums to get me motivated to fix this.==============================================================end$imported = {} if $imported.nil?$imported["Sprawl_Escape"] = truemodule BattleManager def self.process_abort replay_bgm_and_bgs SceneManager.return battle_end(1) $game_party.all_members.each do |actor| @exp_loss = -1 * actor.exp * 0.005; actor.gain_exp(@exp_loss) end @xp_loss_str = @exp_loss * -1 text = "You lose " + @xp_loss_str.to_i.to_s text = text + " experience points for fleeing." $game_message.add('\.' + text) wait_for_message return true endend
It works perfectly, except there is a small presentation issue I would like fixed. I would fix this myself, but I simply don't have the coding knowledge necessary.

The issue: when fleeing from battle, there is a message that displays how much EXP was lost. Except, it only displays the LAST actor's EXP. It's not an average, not the actor with the lowest EXP, but simply the actor who is last in the party formation.

With one actor in the party this isn't a big deal, but with multiple actors, it becomes a bit muddy how much EXP was lost for all. You only ever know the last actor's EXP. I would like a way for the script to display all actor's EXP lost, one-by-one. Not an average, because that's not how the script works, since each actor loses 0.5% EXP by default.

So, say I flee a battle with 4 party members. This is how I want it to display:

"[Actor #] lost ### experience points.

[Actor #] lost ### experience points.

[Actor #] lost ### experience points.

[Actor #] lost ### experience points."

Where [Actor #] is replaced by the name given to the corresponding actor in the database. There will ever only be a maximum of 4 actors in any given battle, but I have more than 4 actors in the database. I hope this won't be a problem.

So it configures how much EXP was lost with each actor separately and displays that EXP accordingly.

Hopefully this won't prove too difficult of an edit. If you need anymore info, just let me know. Thanks!
Here you go:

Spoiler
module BattleManager def self.process_abort wait_for_message replay_bgm_and_bgs SceneManager.return battle_end(1) $game_party.all_members.each do |actor| @exp_loss = -1 * actor.exp * 0.005; actor.gain_exp(@exp_loss) txt = sprintf("%s lost %d experience points!",actor.name,@exp_loss.abs) $game_message.add(txt) end wait_for_message return true endend
Just replace the module part of the script with the above one, and it should do what you want.
Wow, thanks so much! It works perfect!

Edit: Is there a way to have the message that displays the character's experience lost be separate from the flee text?

So that when you flee, one message box pops up saying the party fled, then a second message box appears with the experience lost text. With the way it is now, both messages appear in the same box and fill all 4 lines of the box, so that if there is more than 4 party members, the 4th member's experience lost text space has already been used up by the flee text and is moved to a new box separate from the other party members. Not a big deal, honestly, but I do like to keep things nice and organized.
Try to put a "wait_for_message" at the start of the method. That should work, but I did not test it.


I updated the change in my post above, if you are unsure where to put it.
It works!

Thanks so much!

Original thread: https://forums.rpgmakerweb.com/threads/edit-to-escape-penalty-script.48091/