In my game I'm using a system where each actor has multiple of each equipment slot (e.g. four "Weapon" slots per actor).
With this system an actor can wield a sword, a spear, a gun, and an axe. But what if the actor is wielding four of the same sword?
My question is; how can I count how many of each item the actor has equipped?
How can I tell if the actor has four "Weapon ID 2"s equipped?
You'll need a script for this, and it will partially depend on which script you're using to create the additional equip slots.
Please give a link to the site of the equip manager you used.
I've moved this thread to Script Support. Please be sure to post your threads in the correct forum next time. Thank you.
You could probably loop through each equip and check its ID.
Something like:
count = 0
for actor in $game_party.members
for i in 0..3 # This checks your four "Type 0" slots. If you wanted to check your four "Type 1" slots, replace 0..3 with 4..7
if actor.equips.id == 2 # Checks for Equip #2
count += 1
end
end
end
$game_variables[26] = count # This is optional and stores the count in a Variable to make it easier to use
This will count the number of equipped items from one type:
# For weapons:
$game_actors[id].weapons.select {|wp| wp.id == w_id }.size
# For armors:
$game_actors[id].armors.select {|ar| ar.id == a_id }.size
Replace the id with a valid actor ID, and the w_id and a_id refers to a valid weapon/armor ID respectively.
But if you simply need to check if the actor has a specific weapon/armor already equipped, you can use this as well:
# For weapons:
$game_actors[id].weapons.include?($data_weapons[id])
# For armors:
$game_actors[id].armors.include?($data_armors[id])
If you want to restrict the player from equipping two of the same kind of weapons in the equip menu, you will need to adjust the enable? or include? methods in the Window_EquipItem class (only one of them is enough). You can refer to the selected actor in those methods as @actor and the selected item will be item.
You might also need to check if the item is a weapon or armor first, which you can do so with this:
item.is_a?(RPG::Weapon) # For weapon check.
item.is_a?(RPG::Armor) # For armor check.
Now you just need to add these together, right? 😛
Thank you Wavelength and Sixth for your help!
Between both your methods, I'm sure I'll be able to accomplish what I hope to.
My problem has been resolved.