[XP]Player: Swap Dead Actor mod [SOLVED]

Started by l0rdph0enix, August 10, 2011, 05:04:31 pm

Previous topic - Next topic

l0rdph0enix

August 10, 2011, 05:04:31 pm Last Edit: September 07, 2011, 03:45:57 pm by l0rdph0enix
I'm using the Player: Swap Dead Actor script by Kain Nobel and I was curious as to how I could get it so when player 1 is alive again they are automatically shifted back into first position?

Spoiler: ShowHide

#===============================================================================
# ** Player : Swap Dead Actor
#    By : Kain Nobel
#    Date : 12/10/2008
#    Versio : 2.5
#===============================================================================

#-------------------------------------------------------------------------------
# * SDK Log
#-------------------------------------------------------------------------------
SDK.log('Player.SwapDeadActor', 'Kain Nobel  ©', 2.5, '12.10.2008')
#-------------------------------------------------------------------------------
# * SDK Enabled Test : BEGIN
#-------------------------------------------------------------------------------
if SDK.enabled?('Player.SwapDeadActor')

#===============================================================================
# ** Scene_Map
#===============================================================================

class Scene_Map < SDK::Scene_Base
  #-----------------------------------------------------------------------------
  # * Alias Listings
  #-----------------------------------------------------------------------------
  alias_method :swap_dead_leader_scene_map_update, :update
  #-----------------------------------------------------------------------------
  # * Update
  #-----------------------------------------------------------------------------
  def update
     swap_dead_leader_scene_map_update
     unless $game_party.actors.empty?
        if ($game_party.actors[0].hp).zero?
           unless $game_party.all_dead?
             $game_party.actors << $game_party.actors.shift
             $game_player.refresh
          else ; $game_temp.gameover = true
          end
       end        
    end
  end
end
 
#-------------------------------------------------------------------------------
# * SDK Enabled Test : END
#-------------------------------------------------------------------------------
end


l0rdph0enix


l0rdph0enix


l0rdph0enix


l0rdph0enix


KK20

#===============================================================================
# ** Player : Swap Dead Actor
#    By : Kain Nobel
#    Date : 12/10/2008
#    Versio : 2.5
#===============================================================================

#-------------------------------------------------------------------------------
# * SDK Log
#-------------------------------------------------------------------------------
SDK.log('Player.SwapDeadActor', 'Kain Nobel  ©', 2.5, '12.10.2008')
#-------------------------------------------------------------------------------
# * SDK Enabled Test : BEGIN
#-------------------------------------------------------------------------------
if SDK.enabled?('Player.SwapDeadActor')
#===============================================================================
# ** Game_Player
#===============================================================================

class Game_Player
  def refresh(leader=0)
    # If party members = 0
    if $game_party.actors.size == 0
      # Clear character file name and hue
      @character_name = ""
      @character_hue = 0
      # End method
      return
    end
    # Get lead actor
    if leader != 0
      actor = $game_actors[leader]
    else
      actor = $game_party.actors[0]
    end
    # Set character file name and hue
    @character_name = actor.character_name
    @character_hue = actor.character_hue
    # Initialize opacity level and blending method
    @opacity = 255
    @blend_type = 0
  end
end

 
#===============================================================================
# ** Scene_Map
#===============================================================================

class Scene_Map < SDK::Scene_Base
 
   #-----------------------------------------------------------------------------
   # * Alias Listings
   #-----------------------------------------------------------------------------
   alias_method :swap_dead_leader_scene_map_update, :update
   #-----------------------------------------------------------------------------
   # * Update
   #-----------------------------------------------------------------------------
   def update
      swap_dead_leader_scene_map_update
      unless $game_party.actors.empty?
        @leader = $game_party.actors[0]
         if (@leader.hp).zero?
            unless $game_party.all_dead?             
              for actor in $game_party.actors
                if actor.hp != 0
                  new_leader = actor
                  break
                end
              end
              if @temp_leader != new_leader
                @temp_leader = new_leader
              end
              $game_player.refresh(@temp_leader.id)
            else
              $game_temp.gameover = true
            end
         else
           $game_player.refresh(@leader.id)
         end   
      end   
   end
end
 
#-------------------------------------------------------------------------------
# * SDK Enabled Test : END
#-------------------------------------------------------------------------------
end
Tell me how good this works for you. I didn't test it a lot, but it does it's job.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

l0rdph0enix

Could you remove the SDK support from it. I'm trying to get my game away from that entirely. I just forgot to update my first post. Thanks for helping out though.

KK20

#===============================================================================
# ** Player : Swap Dead Actor
#    By : Kain Nobel
#    Date : 12/10/2008
#    Version : 2.5
#    SDK-Free Edit by KK20
#===============================================================================

#===============================================================================
# ** Game_Player
#===============================================================================

class Game_Player
  def refresh(leader=0)
    # If party members = 0
    if $game_party.actors.size == 0
      # Clear character file name and hue
      @character_name = ""
      @character_hue = 0
      # End method
      return
    end
    # Get lead actor
    if leader != 0
      actor = $game_actors[leader]
    else
      actor = $game_party.actors[0]
    end
    # Set character file name and hue
    @character_name = actor.character_name
    @character_hue = actor.character_hue
    # Initialize opacity level and blending method
    @opacity = 255
    @blend_type = 0
  end
end

 
#===============================================================================
# ** Scene_Map
#===============================================================================

class Scene_Map
 
   #-----------------------------------------------------------------------------
   # * Alias Listings
   #-----------------------------------------------------------------------------
   alias swap_dead_leader_scene_map_update update
   #-----------------------------------------------------------------------------
   # * Update
   #-----------------------------------------------------------------------------
   def update
      swap_dead_leader_scene_map_update
      unless $game_party.actors.empty?
        @leader = $game_party.actors[0]
         if (@leader.hp).zero?
            unless $game_party.all_dead?             
              for actor in $game_party.actors
                if actor.hp != 0
                  new_leader = actor
                  break
                end
              end
              if @temp_leader != new_leader
                @temp_leader = new_leader
              end
              $game_player.refresh(@temp_leader.id)
            else
              $game_temp.gameover = true
            end
         else
           $game_player.refresh(@leader.id)
         end   
      end   
   end
end
Wasn't much to delete actually...just realized that. Anyways, the character that's displayed on the field is whomever is closest to the front of the party. I removed the whole "shift the party up and throw the dead actors at the bottom of the party" function.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

l0rdph0enix

Quote from: JanraeMendoza on September 06, 2011, 05:15:14 pm
Quote from: l0rdph0enix on September 06, 2011, 04:40:02 pm
Could you remove the SDK support from it.


Well actually this does not need any scripting (in my own opinion) because this is actually possible in eventing and common events. The thing is, it needs A LOT of eventing, which I myself, am bored to create at times. This may also depend if you are using a Caterpillar script, which your events depends on it. My tip, create a new State change. =)

I'm using the Caterpillar system from ToA ;).

@KK20
Thanks for taking the SDK out, but when the main characters is 'knocked out' their position isn't shifted to where they aren't the leader anymore. But when they are 'recovered' they are back to being the leader again. Any ideas?

KK20

Now that you mention you are using a caterpillar script, I can probably see why it wouldn't work. My script edit assumes that you are using the default "one actor" on the field.
Quote...when the main characters is 'knocked out' their position isn't shifted to where they aren't the leader anymore.
Not sure exactly what you mean. The script assumes that whoever is closest to the front of the party and is still alive is the controllable actor. Like I said previously, it does not shift the order of the party. If you want that to happen, I'm going to have to edit the script again.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

ForeverZer0

Just stick this in the editor below the default classes.  It will work automatically.

Spoiler: ShowHide
class Game_Party
 
  alias zer0_dead_actor_swap_setup setup_starting_members
  def setup_starting_members
    zer0_dead_actor_swap_setup
    set_preferred_order
  end
 
  def set_preferred_order
    @preferred_order = @actors.collect {|actor| actor.id }
  end
 
  def refresh_order
    @actors.sort! {|a, b|
      if a.dead? && b.dead?
        return @preferred_order.index(a.id) <=> @preferred_order.index(b.id)
      else
        return a.dead? ? -1 : 1
      end
    }
  end
 
  alias zer0_dead_swap_add add_actor
  def add_actor(id)
    @actors = @preferred_order.collect {|id| $game_actors[id] }
    zer0_dead_swap_add(id)
    set_preferred_order
    refresh_order
  end
 
  alias zer0_dead_swap_remove remove_actor
  def remove_actor(id)
    @actors = @preferred_order.collect {|id| $game_actors[id] }
    zer0_dead_swap_remove(id)
    set_preferred_order
    refresh_order
  end
end

class Game_Actor
 
  alias zer0_dead_swap_remove_state remove_state
  def remove_state(state_id)
    zer0_dead_swap_remove_state(state_id)
    $game_party.refresh_order
  end
end
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

KK20

Not being rude or anything, but...I don't get what your script 'actually' does. Perhaps it's because there's an error in it or something. I just tried using an event where I remove Aluxes from the party and add Dorothy. What happened was that it kept removing the last actor in the party one-by-one until it was only Aluxes in the party. Then, I finally got Dorothy in the party (but all by herself).

Like I said, just throwing my...observation skills... :uhm:

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

ForeverZer0

Oops, you are right. I changed something at the the last second with the add/remove actor methods and never tested it. Here's the fix for that:

Spoiler: ShowHide
class Game_Party
 
  alias zer0_dead_actor_swap_setup setup_starting_members
  def setup_starting_members
    zer0_dead_actor_swap_setup
    set_preferred_order
  end
 
  def set_preferred_order
    @preferred_order = @actors.collect {|actor| actor.id }
  end
 
  def refresh_order
    @actors.sort! {|a, b|
      if a.dead? && b.dead?
        return @preferred_order.index(a.id) <=> @preferred_order.index(b.id)
      else
        return a.dead? ? -1 : 1
      end
    }
  end
 
  alias zer0_dead_swap_add add_actor
  def add_actor(id)
    zer0_dead_swap_add(id)
    @preferred_order.push(id) unless @preferred_order.include?(id)
    refresh_order
  end
 
  alias zer0_dead_swap_remove remove_actor
  def remove_actor(id)
    zer0_dead_swap_remove(id)
    @preferred_order -= [id]
    refresh_order
  end
end

class Game_Actor
 
  alias zer0_dead_swap_remove_state remove_state
  def remove_state(state_id)
    zer0_dead_swap_remove_state(state_id)
    $game_party.refresh_order
  end
end
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

KK20

Blah! I still don't get it!  :O.o:

Is def refresh_order suppose to change the actor's positions in the party? Because it's not and I think that's what he wanted. I am also assuming that he wants the actor that you control on the field to change as well (if $game_party.actor
  • is dead, make the next person in line be the controllable character). And after doing some lolstalking I found out he's using a Multi-Party/Party Switcher script. Suddenly I'm starting to think that the only way it is possible to solve this problem is if we had the demo.

    :wacko: I'll just...do something else until he replies back with what he wants. -lies down-

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

ForeverZer0

It does this:

Actor 1 dies, he goes to back of party (all dead actors are still sorted by the "preferred" order)
The second preferred actor is moved up to take his place. 
If dead actor returns to life, the party is reordered and Actor 1 returns to being the party leader. 
Its for use with the caterpillar script that he is using, and it works. I can supply you with a demo of it working if you still do not understand.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

KK20

It's probably because I don't have the caterpillar script he has; that's why I can't exactly test it.  :facepalm:

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

l0rdph0enix

WOOT! ForeverZer0 your script did the trick  :up: it works like a charm now. KK20 if you still would like me to post a demo of my game I can ( was going to anyway  ;) ) but thanks for your help with this as well. KK20 you will be added to my games credits, ForeverZer0 you're already there for multiple reasons  :^_^':. This topic is now solved thanks to everyones help.