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.
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:
$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.
$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.
You say you need to keep that data at hand. Well, go assign it to any variable!
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!
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9
Maranatha!
The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.
My Original Stories (available in English and Spanish)
List of Compiled Binary Executables I have published...
HiddenChest & Roole
Give me a free copy of your completed game if you include at least 3 of my scripts!
Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Maranatha!
The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.
My Original Stories (available in English and Spanish)
List of Compiled Binary Executables I have published...
HiddenChest & Roole
Give me a free copy of your completed game if you include at least 3 of my scripts!
Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE