Actor in Party Reliant on Item in Inventory

Status
Not open for further replies.

nickfitzgerald3

Villager
Member
Joined
May 5, 2014
Messages
24
Reaction score
3
First Language
english
Primarily Uses
I need help eventing or scripting this. I need a way to make a actor appear in party only if a designated item is in your inventory, so when you sell it or lose it, the actor is removed from party, help is much appreciated :)

what would actually also help, if this is easier to script is a way to restrict the sale of an item if you only have a quantity of 1

Whatever is easier to do :)
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
If you buy the item, do you want the actor to join your party automatically? How many ways can you obtain or lose the item?


If you're only adding/removing it via events, then you can do the add/remove actor in the same event. If you can buy or sell the item, you need to script it.


You can always make it so you can't sell it (don't have my engine in front of me - not sure if you do that by making it a Key Item, or just setting the price to 0).
 

Evgenij

Veteran
Veteran
Joined
Aug 28, 2013
Messages
349
Reaction score
100
First Language
German
Primarily Uses
N/A
This is a small script I have written:

If you add an item to your inventory the actor corresponding to the item will also be added, and if you remove this item, the actor will also be removed, when you dont have this item anymore.

Code:
module EE  module ActorAsItem    #---------------------------------------------------------------------------    ACTORS = [ # Dont edit this line    #---------------------------------------------------------------------------           #---------------------------------------------------------------------          # [item_type, item_id, actor_id],          #   item_type: :item, :weapon, or :armor          #---------------------------------------------------------------------          [:weapon, 1, 5],          [:item, 1, 3],              #---------------------------------------------------------------------------    ] # Dont edit this line    #---------------------------------------------------------------------------    def self.items      return ACTORS.select{ |arr| arr.first == :item}          end         def self.weapons      return ACTORS.select{ |arr| arr.first == :weapon}         end        def self.armors      return ACTORS.select{ |arr| arr.first == :armor}         end        def self.get_items(item_class)      return items   if item_class == RPG::Item      return weapons if item_class == RPG::Weapon      return armors  if item_class == RPG::Armor      return []    end        def self.get_actor_id(item_class, item_id)      get_items(item_class).each do |arr|        return arr[2] if arr[1] == item_id      end      return nil    end  endendclass Game_Party  alias :e222_gp_gi_ias         :gain_item  def gain_item(item, amount, include_equip = false)    e222_gp_gi_ias(item, amount, include_equip)    container = item_container(item.class)    return unless container    actor_id = EE::ActorAsItem.get_actor_id(item.class, item.id)    return unless actor_id    if item_number(item) > 0      $game_party.add_actor(actor_id)    else      $game_party.remove_actor(actor_id) if $game_party.all_members.size > 1    end  end    def actors    return @actors  endendclass Game_Map  alias :e222_gm_update_ias     :update  def update(update_main = false)    e222_gm_update_ias(update_main)    check_party_equip  end    def check_party_equip    $game_party.all_members.each do |actor|      actor.equips.each do |item|        next unless item        actor_id = EE::ActorAsItem.get_actor_id(item.class, item.id)        next unless actor_id        $game_party.add_actor(actor_id) unless $game_party.actors.include?(actor_id)      end    end  endend
 

nickfitzgerald3

Villager
Member
Joined
May 5, 2014
Messages
24
Reaction score
3
First Language
english
Primarily Uses
This is a small script I have written:

If you add an item to your inventory the actor corresponding to the item will also be added, and if you remove this item, the actor will also be removed, when you dont have this item anymore.

module EE module ActorAsItem #--------------------------------------------------------------------------- ACTORS = [ # Dont edit this line #--------------------------------------------------------------------------- #--------------------------------------------------------------------- # [item_type, item_id, actor_id], # item_type: :item, :weapon, or :armor #--------------------------------------------------------------------- [:weapon, 1, 5], [:item, 1, 3], #--------------------------------------------------------------------------- ] # Dont edit this line #--------------------------------------------------------------------------- def self.items return ACTORS.select{ |arr| arr.first == :item} end def self.weapons return ACTORS.select{ |arr| arr.first == :weapon} end def self.armors return ACTORS.select{ |arr| arr.first == :armor} end def self.get_items(item_class) return items if item_class == RPG::Item return weapons if item_class == RPG::Weapon return armors if item_class == RPG::Armor return [] end def self.get_actor_id(item_class, item_id) get_items(item_class).each do |arr| return arr[2] if arr[1] == item_id end return nil end endendclass Game_Party alias :e222_gp_gi_ias :gain_item def gain_item(item, amount, include_equip = false) e222_gp_gi_ias(item, amount, include_equip) container = item_container(item.class) return unless container actor_id = EE::ActorAsItem.get_actor_id(item.class, item.id) return unless actor_id if item_number(item) > 0 $game_party.add_actor(actor_id) else $game_party.remove_actor(actor_id) if $game_party.all_members.size > 1 end end def actors return @actors endendclass Game_Map alias :e222_gm_update_ias :update def update(update_main = false) e222_gm_update_ias(update_main) check_party_equip end def check_party_equip $game_party.all_members.each do |actor| actor.equips.each do |item| next unless item actor_id = EE::ActorAsItem.get_actor_id(item.class, item.id) next unless actor_id $game_party.add_actor(actor_id) unless $game_party.actors.include?(actor_id) end end endend
That works beautifully! Thanks so much, I really think this script should get posted in the finished script page, because theres nothing like it out there, again thanks you! 
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.
 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c

Forum statistics

Threads
105,857
Messages
1,017,015
Members
137,563
Latest member
MinyakaAeon
Top