Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> Sort your party
dricc
post Nov 20 2009, 06:16 AM
Post #1


Level 8
Group Icon

Group: Revolutionary
Posts: 117
Type: None
RM Skill: Undisclosed




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 .

[Show/Hide] Script code
#==============================================================================
# ** 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
Go to the top of the page
 
+Quote Post
   
als
post Nov 20 2009, 07:03 PM
Post #2


Level 1
Group Icon

Group: Member
Posts: 8
Type: Artist
RM Skill: Beginner




just as what i need for my game !!
thanks a lot dricc !! i'll credit you in my game...
i'll try this code now
Go to the top of the page
 
+Quote Post
   
dricc
post Nov 23 2009, 06:34 AM
Post #3


Level 8
Group Icon

Group: Revolutionary
Posts: 117
Type: None
RM Skill: Undisclosed




I forgot something : you know that the player displayed on screen is always the first one in the party ?
In the case of a tactic game , that's not what we want . We want to always have the same character on screen .
Use this script for that :

#==============================================================================
# ** Game_Player
#------------------------------------------------------------------------------
# after the sort , the displayed actors remains the same
# MAIN_ACTOR is the ID of this actor , change it !!!
#==============================================================================

class Game_Player < Game_Character

MAIN_ACTOR = 1

#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
if $game_party.members.size == 0
@character_name = ""
@character_index = 0
else
actor = $game_actors[MAIN_ACTOR] # Get front actor
@character_name = actor.character_name
@character_index = actor.character_index
end
end
end
Go to the top of the page
 
+Quote Post
   
Runefreak
post Nov 26 2009, 09:14 AM
Post #4


Comic Saaaaaaaans!
Group Icon

Group: Revolutionary
Posts: 140
Type: Developer
RM Skill: Advanced




Thanks, I've been looking for a script like this.


__________________________
</div>
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 18th May 2013 - 11:06 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker