KSortGroup XP

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
285
Reaction score
70
First Language
English
Primarily Uses
RMXP
KSortGroup XP

by Kyonides Arkantes


Introduction

Just as I've been doing lately, I've posted another scriptlet to let you get stuff done the easy way.
At least that's what I think...

What it does it to let you fetch the heroes or the enemies based on how strong or weak they are.

o_O How did I define what's strong or weak there?

Well, I used some script calls that handle a specific stat per call.

Following a single script call model you get any stat like this:

Code:
$game_party.members_by(:low_hp)
$game_troop.members_by(:high_int)
The former list will return a list of heroes sorted by HP in increasing order while the latter will offer you all troopers sorted by INT in decreasing order. Returns an empty list if no living member was found.

Code:
$game_party.member_by(:low_hp)
$game_troop.member_by(:high_int)
These calls let you do the same for their first member only, if that member is ALIVE.
Otherwise it returns nil for all members are already dead.

o_O? You say you need to keep that data at hand. Well, go assign it to any variable! XP

Code:
my_variable = $game_party.member_by(:low_hp)
By the way, you've got 16 different options as I've explained in the Comments section of my script.


The Script

Code:
# * KSortGroup XP
#   Scripter : Kyonides Arkanthes

# This is a scriptlet that should let you fetch a sorted list of actors based on
# a specific stat like HP or PDEF, etc.

# Warning!
#   It won't work on the Title and File Loading scenes obviously. :P
#   Here mana stands for SP in RMXP but MP in other versions.
#   It will automatically pick living heroes or troopers during battles.
#   It will return all heroes sorted by stat while on the map.
#   It might return an empty array with no Hero or Trooper.
#   Or it might return no Hero or Trooper but nil aka nothing.

# * Script Call Section *

# To get all members of your party or enemies
#   $game_party.actors   ## Already included in RM
#   $game_troop.enemies  ## Already included in RM

# To get all DEAD members of your party or enemies
#   $game_party.dead_members
#   $game_troop.dead_members

# To sort Heroes or Troopers by some basic stat using the script calls mentioned
# below, use any of the following  Code  options:
#   :low_hp    :high_hp    :low_mana  :high_mana
#   :low_str   :high_str   :low_int   :high_int
#   :low_agi   :high_agi   :low_dex   :high_dex
#   :low_pdef  :high_pdef  :low_mdef  :high_mdef

# To get all LIVING members of your party or enemies

#   $game_party.members_by(Code)
#   $game_troop.members_by(Code)

# To get the FIRST member on that list
# Option 1
#   Add [0] to the end of your favorite script call. No spaces included!
# Option 2
#   Add .first to the end of your favorite script call. No spaces included!
# Option 3 - The calls do the job for you.
#   $game_party.member_by(Code)
#   $game_troop.member_by(Code)

module KSort
  def self.group(type, list)
    case type
    when :low_hp
      list.sort{|a, b| a.hp < b.hp }
    when :high_hp
      list.sort{|a, b| a.hp > b.hp }
    when :low_mana
      list.sort{|a, b| a.sp < b.sp }
    when :high_mana
      list.sort{|a, b| a.sp > b.sp }
    when :low_str
      list.sort{|a, b| a.str < b.str }
    when :high_str
      list.sort{|a, b| a.str > b.str }
    when :low_int
      list.sort{|a, b| a.int < b.int }
    when :high_int
      list.sort{|a, b| a.int > b.int }
    when :low_agi
      list.sort{|a, b| a.agi < b.agi }
    when :high_agi
      list.sort{|a, b| a.agi > b.agi }
    when :low_dex
      list.sort{|a, b| a.dex < b.dex }
    when :high_dex
      list.sort{|a, b| a.dex > b.dex }
    when :low_pdef
      list.sort{|a, b| a.pdef < b.pdef }
    when :high_pdef
      list.sort{|a, b| a.pdef > b.pdef }
    when :low_mdef
      list.sort{|a, b| a.mdef < b.mdef }
    when :high_mdef
      list.sort{|a, b| a.mdef > b.mdef }
    end
  end
end

class Game_Party
  def dead_members
    @actors.select{|a| a.hp == 0 and !a.hidden }
  end

  def living_members
    @actors.select{|a| a.hp > 0 and !a.hidden }
  end

  def members_by(type)
    list = $game_temp.in_battle ? living_members : @actors
    KSort.group(type, list)
  end

  def member_by(type)
    members_by(type)[0]
  end
end

class Game_Troop
  def dead_members
    @enemies.select{|a| a.hp == 0 and !a.hidden }
  end

  def living_members
    @enemies.select{|a| a.hp > 0 and !a.hidden }
  end

  def members_by(type)
    KSort.group(type, living_members)
  end

  def member_by(type)
    members_by(type)[0]
  end
end
Terms & Conditions

Free for use in any kind of game.
Include my nickname in your game credits.
Mention this forum in your game credits as well.
Give me a free copy of your completed game if you include at least 2 of my scripts! :p
 
Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Hello I buyed RPG Maker VX Ace a long ago and I want to use it again but in the meantime I changed my pc but I lost the paper with my product key on so I can't use RPG maker again... someone can help me please ? or there is no hopes ?:'( ( I have a bad english I'm sorry )
I was away this days here in the forum but it was for a good cause!
The trailer of the demo of Luke Inn is on youtube and I am so happy!
I need to see the bugs of the game but I am happy that I have new content to show!

The last part of the modern interior will be ready soon. This will be a B-tile. With interior items for the kitchen, bathroom, toilet and storage room.
This frantic shooting ARPG plugin for MZ looks really great. Here is the link to a post from the official Japanese RPG Maker forum.
We start in 5 minutes!

Forum statistics

Threads
102,940
Messages
996,116
Members
134,392
Latest member
Niko44
Top