I made this for a final fantasy tactics project . But it may be useful for others , especially if you have a large party . It is a scripter tool .
It can be used in a menu like this :
# sort party by level :
$game_party.sort_level
# sort party by Atk :
$game_party.sort_atk
... other sorts are available .
But the menu is not included in the script , sorry .
The sort for 40 members is very fast , but i know my sort algorithm is not the best one .
put an instruction "@status_window.refresh" after the sort .
#==============================================================================
# ** Game_Party
#------------------------------------------------------------------------------
# This class handles the party. It includes information on amount of gold
# and items. The instance of this class is referenced by $game_party.
#==============================================================================
class Game_Party < Game_Unit
# YOU CAN CHANGE THIS !!!
#actor_id => value
# the value can be whatever you want . it is a custom sort .
Actor_Value = {
1 => -4,
2 => 3,
4 => -6,
5 => 3,
6 => -8,
7 => 5
}
# the default value for actors not in the Actor_Value
Actor_default_value = 0
# end of "# YOU CAN CHANGE THIS !!!"
def avalue(actor_id)
# Valuetab = Actor_Value[@actor_id]
return Actor_default_value if Actor_Value[@actor_id] == nil
return Actor_Value[@actor_id]
end
#--------------------------------------------------------------------------
# * Sort actors by the table value
#--------------------------------------------------------------------------
def sort_value
result = []
for i in 0..@actors.size - 1
mini = nil
for j in 0..@actors.size - 1
mini = j if mini == nil and not result.include?(@actors[j])
if mini != nil then
if avalue(@actors[mini]) <= avalue(@actors[j]) and not result.include?(@actors[j]) then
mini = j
end
end
end
result.push(@actors[mini])
end
@actors = result
$game_player.refresh
end
#--------------------------------------------------------------------------
# * Sort actors by the table value
#--------------------------------------------------------------------------
def sort_value_asc
result = []
for i in 0..@actors.size - 1
mini = nil
for j in 0..@actors.size - 1
mini = j if mini == nil and not result.include?(@actors[j])
if mini != nil then
if avalue(@actors[mini]) >= avalue(@actors[j]) and not result.include?(@actors[j]) then
mini = j
end
end
end
result.push(@actors[mini])
end
@actors = result
$game_player.refresh
end
#--------------------------------------------------------------------------
# * Sort actors by alpha
#--------------------------------------------------------------------------
def sort_alpha
result = []
for i in 0..@actors.size - 1
mini = nil
for j in 0..@actors.size - 1
mini = j if mini == nil and not result.include?(@actors[j])
if mini != nil then
if $game_actors[@actors[mini]].name <= $game_actors[@actors[j]].name and not result.include?(@actors[j]) then
mini = j
end
end
end
result.push(@actors[mini])
end
@actors = result
$game_player.refresh
end
#--------------------------------------------------------------------------
# * Sort actors by level
#--------------------------------------------------------------------------
def sort_level
result = []
for i in 0..@actors.size - 1
mini = nil
for j in 0..@actors.size - 1
mini = j if mini == nil and not result.include?(@actors[j])
if mini != nil then
if $game_actors[@actors[mini]].level <= $game_actors[@actors[j]].level and not result.include?(@actors[j]) then
mini = j
end
end
end
result.push(@actors[mini])
end
@actors = result
$game_player.refresh
end
#--------------------------------------------------------------------------
# * Sort actors by ATK
#--------------------------------------------------------------------------
def sort_atk
result = []
for i in 0..@actors.size - 1
mini = nil
for j in 0..@actors.size - 1
mini = j if mini == nil and not result.include?(@actors[j])
if mini != nil then
if $game_actors[@actors[mini]].atk <= $game_actors[@actors[j]].atk and not result.include?(@actors[j]) then
mini = j
end
end
end
result.push(@actors[mini])
end
@actors = result
$game_player.refresh
end
#--------------------------------------------------------------------------
# * Sort actors by hp
#--------------------------------------------------------------------------
def sort_hp
result = []
for i in 0..@actors.size - 1
mini = nil
for j in 0..@actors.size - 1
mini = j if mini == nil and not result.include?(@actors[j])
if mini != nil then
if $game_actors[@actors[mini]].hp <= $game_actors[@actors[j]].hp and not result.include?(@actors[j]) then
mini = j
end
end
end
result.push(@actors[mini])
end
@actors = result
$game_player.refresh
end
#--------------------------------------------------------------------------
# * Sort actors by mp
#--------------------------------------------------------------------------
def sort_mp
result = []
for i in 0..@actors.size - 1
mini = nil
for j in 0..@actors.size - 1
mini = j if mini == nil and not result.include?(@actors[j])
if mini != nil then
if $game_actors[@actors[mini]].mp <= $game_actors[@actors[j]].mp and not result.include?(@actors[j]) then
mini = j
end
end
end
result.push(@actors[mini])
end
@actors = result
$game_player.refresh
end
#--------------------------------------------------------------------------
# * Sort actors by spi
#--------------------------------------------------------------------------
def sort_spi
result = []
for i in 0..@actors.size - 1
mini = nil
for j in 0..@actors.size - 1
mini = j if mini == nil and not result.include?(@actors[j])
if mini != nil then
if $game_actors[@actors[mini]].spi <= $game_actors[@actors[j]].spi and not result.include?(@actors[j]) then
mini = j
end
end
end
result.push(@actors[mini])
end
@actors = result
$game_player.refresh
end
#--------------------------------------------------------------------------
# * Sort actors by spi
#--------------------------------------------------------------------------
def swap(actor1,actor2)
result = []
for i in 0..@actors.size - 1
result.push(@actors[actor2]) if i == actor1
result.push(@actors[actor1]) if i == actor2
result.push(@actors[i]) if i != actor2 and i != actor1
end
@actors = result
$game_player.refresh
end
end
I hope this can help someone !
This post has been edited by dricc: Nov 20 2009, 06:17 AM