Trying to make an array that holds equipment.

Status
Not open for further replies.

kerbonklin

Hiatus King
Veteran
Joined
Jan 6, 2013
Messages
1,726
Reaction score
275
First Language
English
Primarily Uses
RMMV
Okay so a long while ago, Shaz helped me make an array that holds learned skills skills and forgets all of them, and then another array that learns them back. (Script call event via Game_Interpreter using Game_Actor methods)

a = $game_actors[2]v = []a.skills.each do |skill| v.push(skill.id) a.forget_skill(skill.id)end$game_variables[80] = v
Code:
a = $game_actors[2]v = $game_variables[80]v.each do |skill_id|  a.learn_skill(skill_id)end
Now i'm trying to do the same thing but for equipment instead, to remove all equipments and push them into an array (like in code 1), then re-equip them back later on (like in code 2). This is what I have so far:

a = $game_actors[2]v = []a.equips.each do |equips| v.push($data_weapons[@item_id]) v.push($data_armors[@item_id]) a.change_equip(slot_id, nil)end$game_variables[181] = vHowever i'm getting "unable to convert nil to integer" which I think comes from change_equip but nil represents Remove...

Anyone wanna help?

Edit: It's Ace. I'll try that right now Chompil. Actually bad news, Ace can't hold that many characters in the script call box. I'll see if I can find something to support using extra input, I remember seeing something like that around here.
 
Last edited by a moderator:

Chompil

Villager
Member
Joined
Oct 15, 2013
Messages
9
Reaction score
2
First Language
Hebrew
Primarily Uses
I've noticed you've never set the variables slot_id or @item_id.

this may cause the nil error you mentioned. also, you shouldn't save both an armor and a weapon for each equipment, it's either or.

try something like:

Code:
list = []actor = $game_actors[2]equips = actor.equipsfor i in 0...equips.size  equip = actor.equips[i]  item_id = equip.item_id  if equip.is_a?(RPG::Weapon)    list.push($data_weapons[item_id])  else    list.push($data_armors[item_id])  end  actor.change_equip(i, nil)end$game_variables[181] = list
when you want to get the equipment back, do something like:
Code:
list = $game_variables[181] actor = $game_actors[2]for i in 0...list.size actor.change_equip(i, list[i])end
now, I don't know which program you're using, so you may need to change some things. let me know if you get errors from this code.
 
Last edited by a moderator:

kerbonklin

Hiatus King
Veteran
Joined
Jan 6, 2013
Messages
1,726
Reaction score
275
First Language
English
Primarily Uses
RMMV
Okay so since the script box is too small, I made this as def command_400 within class Game_Interpreter and just called that instead. Sadly it gives undefined method "item_id" for RPG:Weapon
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Weapons and armors don't have item_ids. Just use id without stating what it is.


What you're doing there, is starting with an equippable item (the weapon or the armor), retrieving the ID, and then converting that ID to an equippable item (a weapon or an armor). So you're doing two conversions to end up with exactly what you started with. That takes up 6 lines of script, when it could be just 1.


Equipment is going to be more complicated than skills, because you have to cater for weapons AND armor, slots (single/dual wield), and the possibility that equipment can't be unequipped or a slot might be empty. The original script I gave you for skills also allowed for the fact that you could remove all the skills, then learn some new ones, and when you added back the old skills, they would not replace the ones you'd learned in the meantime.


Skills also aren't items that you carry around in inventory. If you unequip the weapons and armors, do you want them removed from inventory as well, or should they stay there? And what if you keep them in inventory, but the player goes and sells them before you're ready to add them back? If the player has equipped something else in that slot in the meantime, will it be replaced with what they had earlier?


See how much more complex it's going to be this time around?


Maybe you need to explain why you want to do this - what you're going to do to the actor (or what the player will be allowed to do with him) between removing the equipment and giving it back. The solution is not going to be as easy as it was for skills.
 
Last edited by a moderator:

kerbonklin

Hiatus King
Veteran
Joined
Jan 6, 2013
Messages
1,726
Reaction score
275
First Language
English
Primarily Uses
RMMV
Thanks for the input Shaz. The array to add them back will literally happen a split second after the array to remove them. It's a part of my custom stat system / class system where upon class-changing I remove all skills AND un-equip everything, record all the parameters into variables, , do the class change,then adjust the params (record the new params in more variables, add the old variable'd params onto the new ones, then minus them by the new ones), THEN I add all the skills and equipments back. The result is the actor keeping the same base stats after class changing. It was provided and demo'd within my demo for The Princess Lucia back when the Release Something Weekend happened. (so if you wanna go look at it to see for yourself in action, however it's encrypted)

However before until now, I just used a scripted Clear Equipment and then Optimize, which means every class change will optimize equips and I don't want that, I needed to do a real fix for that eventually, like with the skill array.

So yeah there will be no worry about the player doing anything with the un-equipped items. I guess they can go to the party inventory for that split second.
 
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
I would do something like this, then:

Code:
a = $game_actors[2]v = a.equipsa.clear_equipments$game_variables[81] = v
Code:
a = $game_actors[2]v = $game_variables[81]5.times do |index|  a.change_equip(a.equip_slots[index], v[index])end
 
Last edited by a moderator:

kerbonklin

Hiatus King
Veteran
Joined
Jan 6, 2013
Messages
1,726
Reaction score
275
First Language
English
Primarily Uses
RMMV
Okay so, a.clear_equipments doesn't work so I just used $game_actors[2].clear_equipments as a separate call afterwards. The array definitely writes stuff into the console window. (Probably cause of my other scripts) However when I try to run the stuff to re-equip, it crashes with this error:



I think it's because the "[index[)" is cut off being on a new line within the script box.

EDIT! I slightly re-arranged it to fix the new line problem and now it almost works. The equipments get recorded and sent back into my inventory (but going to Equip Scene causes a crash but that can be ignored) and then they get re-equipped upon calling the second array. (Used defense stat confirm)

a = $game_actors[2]v = $game_variables[81]6.times do |index| a.change_equip(a.equip_slots[index], v[index])endEdit2: It works perfectly now. Shaz, I love you lol.
 
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
Ah, didn't realise you were using additional scripts. Try adding if !v[index].nil? at the end of that line.


So a.change_equip(a.equip_slots[index], v[index]) if !v[index].nil?
 

kerbonklin

Hiatus King
Veteran
Joined
Jan 6, 2013
Messages
1,726
Reaction score
275
First Language
English
Primarily Uses
RMMV
Tried it, still gives the error.



Code:
    @data.sort_by! do |item|
Here's the full script, basically meant to manually sort items/equips/skills lists.
Code:
# ------------------------------------------------------------------------------# Manual Item Sorting v1.0# FenixFyreX# RPG Maker VXAce# ------------------------------------------------------------------------------# This script allows manual sorting of items, weapons, armors, and skills.# It is completely Plug-and-Play.# All you do is select each item once to move items around. Selecting the same# item twice selects the item like normal.# ------------------------------------------------------------------------------# DO NOT EDIT BELOW UNLESS YOU KNOW WHAT YOU ARE DOING# ------------------------------------------------------------------------------ class Game_System  attr_reader :item_order, :weapon_order, :armor_order, :skill_order  alias initialize_item_skill_order_fyx initialize  def initialize(*argv, &argb)    initialize_item_skill_order_fyx(*argv, &argb)    setup_orders  end   def setup_orders    @item_order = $data_items.map {|item| item ? item.id : 0 }    @weapon_order = $data_weapons.map {|wep| wep ? wep.id : 0 }    @armor_order = $data_armors.map {|arm| arm ? arm.id : 0 }    @skill_order = []    $data_actors.each do |actor|      if actor        @skill_order[actor.id] = $data_skills.map {|skill| skill ? skill.id : 0 }      end    end  end   def swap_item_order(id, id2)    idx1 = @item_order.index(id)    idx2 = @item_order.index(id2)       @item_order[idx1], @item_order[idx2] = @item_order[idx2], @item_order[idx1]  end   def swap_weapon_order(id, id2)    idx1 = @weapon_order.index(id)    idx2 = @weapon_order.index(id2)       @weapon_order[idx1], @weapon_order[idx2] = @weapon_order[idx2], @weapon_order[idx1]  end   def swap_armor_order(id, id2)    idx1 = @armor_order.index(id)    idx2 = @armor_order.index(id2)       @armor_order[idx1], @armor_order[idx2] = @armor_order[idx2], @armor_order[idx1]  end   def swap_skill_order(aid, id, id2)    idx1 = @skill_order[aid].index(id)    idx2 = @skill_order[aid].index(id2)       @skill_order[aid][idx1], @skill_order[aid][idx2] =    @skill_order[aid][idx2], @skill_order[aid][idx1]  endend class Window_Selectable   def draw_item_cursor_fade(index)    contents.fill_rect(item_rect(index), Color.new(0,0,0,100))  endend class Window_ItemList   def process_ok    if (@bypass_switch_ids && (item.id == @bypass_index))      @bypass_switch_ids = @bypass_index = nil      super    elsif (@bypass_switch_ids && (item.id != @bypass_index))      process_switch_order    elsif !@bypass_switch_ids      if item        Sound.play_ok        @bypass_switch_ids = true        @bypass_index = item ? item.id : 0        refresh      else        @bypass_switch_ids = @bypass_index = nil        super      end    end  end   alias process_cancel_bypass_swap process_cancel  def process_cancel(*argv, &argb)    @bypass_switch_ids = @bypass_index = nil    refresh    process_cancel_bypass_swap(*argv, &argb)  end   def process_switch_order    Sound.play_ok    swap_order(@bypass_index, item.id)    @bypass_index = @bypass_switch_ids = nil    refresh  end   def system_order_container    case @category    when :none      []    when :item, :key_item      $game_system.item_order    when :weapon      $game_system.weapon_order    when :armor      $game_system.armor_order    end  end   def swap_order(id1, id2)    case @category    when :item, :key_item      $game_system.swap_item_order(id1, id2)    when :weapon      $game_system.swap_weapon_order(id1, id2)    when :armor      $game_system.swap_armor_order(id1, id2)    end  end   alias sort_item_list_fyx make_item_list  def make_item_list(*argv, &argb)    sort_item_list_fyx(*argv, &argb)    @data.sort_by! do |item|      item ? system_order_container.index(item.id) : 0    end    @data  end   alias draw_item_fyx_swap_fade draw_item  def draw_item(index, *argv, &argb)    if @bypass_switch_ids      idx = @data.index(@data.find {|i| i.id == @bypass_index})      draw_item_cursor_fade(idx) if idx == index    end    draw_item_fyx_swap_fade(index, *argv, &argb)  endend class Window_SkillList  def process_ok    if (@bypass_switch_ids && (item.id == @bypass_index))      super    elsif (@bypass_switch_ids && (item.id != @bypass_index))      process_switch_order    elsif !@bypass_switch_ids      Sound.play_ok      @bypass_switch_ids = true      @bypass_index = item.id      refresh    end  end   alias process_cancel_bypass_swap process_cancel  def process_cancel(*argv, &argb)    @bypass_switch_ids = @bypass_index = nil    refresh    process_cancel_bypass_swap(*argv, &argb)  end   def process_switch_order    Sound.play_ok    $game_system.swap_skill_order(@actor.id, @bypass_index, item.id)    @bypass_index = -1000    @bypass_switch_ids = false    refresh  end   alias sort_item_list_fyx make_item_list  def make_item_list(*argv, &argb)    sort_item_list_fyx(*argv, &argb)    @data.sort_by! do |item|      $game_system.skill_order[@actor.id].index(item.id)    end    @data  end   alias draw_item_fyx_swap_fade draw_item  def draw_item(index, *argv, &argb)    if @bypass_switch_ids      idx = @data.index(@data.find {|i| i.id == @bypass_index})      draw_item_cursor_fade(idx) if idx == index    end    draw_item_fyx_swap_fade(index, *argv, &argb)  endend# ------------------------------------------------------------------------------# END OF SCRIPT# ------------------------------------------------------------------------------ 
 
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
At what point does this happen? How are you getting the error?


Are you sure it's not something else causing it ... disable those two script snippets and see if it still happens? If that's an item/skill sort (and item MEANS item, not weapon and armor) then it shouldn't be affected.


Why do you have 6.times instead of 5.times? Do you have another script that gives you more than 5 slots?
 

kerbonklin

Hiatus King
Veteran
Joined
Jan 6, 2013
Messages
1,726
Reaction score
275
First Language
English
Primarily Uses
RMMV
At what point does this happen? How are you getting the error?

Are you sure it's not something else causing it ... disable those two script snippets and see if it still happens? If that's an item/skill sort (and item MEANS item, not weapon and armor) then it shouldn't be affected.

Why do you have 6.times instead of 5.times? Do you have another script that gives you more than 5 slots?
The error happens when you remove (de-equip) an item after doing the array stuff.

Yeah that's the cause. The script allows sorting of ANY list (Item/Weapon/Armor/KeyItem/Skill) (aka Window_ItemList and Window_SkillList) Luckily though I can remove all the Item-List related stuff and just keep the Skill sort functions, cause that's what I really care about. (therefore no error) However there's a bug with skills not de-selecting after sorting so I PM'd the author about it.

Yeah I changed it to 6 because of having altered slots with Yanfly Equip Engine. Actually I just noticed that it doesn't do the 6th re-equip with the array. Hmmm...
 
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
I would disable that script temporarily and see what happens with the regular equip window after you run the equipment removal/replacement. If that works okay, then it's the sorting script that's at fault and not what I've given you above.
 

kerbonklin

Hiatus King
Veteran
Joined
Jan 6, 2013
Messages
1,726
Reaction score
275
First Language
English
Primarily Uses
RMMV
Yeah it's 100% the sorting script that's the problem. Your arrays are perfectly fine. (except for this 6.times I just previously mentioned a minute ago, not effecting the 6th slot which is an additional Accessory slot)

My altered equip slots are [0,1,2,3,4,4]

Weapon/Shield/Head/Body/Accessory/Accessory
 
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
Alright, so this is resolved then? If you need help fixing the script, that should go into a new thread, since it's really not related to this request.
 

kerbonklin

Hiatus King
Veteran
Joined
Jan 6, 2013
Messages
1,726
Reaction score
275
First Language
English
Primarily Uses
RMMV
Yeah go ahead and lock this, i'll make a new thread in due time for the 6.times thing. (Of course i'll see if I can find a solution first)
 
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
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

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
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'??

Forum statistics

Threads
105,860
Messages
1,017,038
Members
137,568
Latest member
invidious
Top