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:
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.
? 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 endendclass 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] endendclass 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] endend
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!
本贴来自国际rpgmaker官方论坛作者:kyonides处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:
https://forums.rpgmakerweb.com/threads/ksortgroup-xp.124862/