Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
  • 0
Sign in to follow this  
Bigace360

Equipment Scene Help

Question

I writing my own CMS, but I'm having trouble with the Scene_Equip. What I'm trying to do is add a menu at the top that says:

- Equip - Remove - Remove All - Optimize -

 

However I do not know how to write that yet, wanted to know if any scripters knew. I'm guessing these have to be on a seperate window and all but I don't know what to write.

Edited by bigace

Share this post


Link to post
Share on other sites

10 answers to this question

Recommended Posts

  • 0

This article and other like it should help; looking at other scripts is the best way to learn.

 

Other than that, that's all I can do for ya'. = /

 

 

*waits for kell to show up*

Share this post


Link to post
Share on other sites
  • 0

I've already look at others script, and know one has the selection thing i'm talking about. But I'll check to the link to see what your talking about.

Edit: Ya that link didn't tell me anything I already knew.

Edited by bigace

Share this post


Link to post
Share on other sites
  • 0

I've already look at others script, and know one has the selection thing i'm talking about. But I'll check to the link to see what your talking about.

Edit: Ya that link didn't tell me anything I already knew.

 

What are you having difficulty implementing? The menu itself? or the fact that it is horizontal?

Share this post


Link to post
Share on other sites
  • 0

Oh its the fact that I don't know how to write the functions like remove and Optimize.post-9377-0-68581300-1318205140_thumb.png

 

this is the mock up see what I'm doing. I've got everything else finish, I just need to know if anyone knew how to the menu part at the top you can see in the image.

Edited by bigace

Share this post


Link to post
Share on other sites
  • 0

Well, to remove items the method call is:

actor.equip(0, type)

Just set type to the equipment slot number you want to remove. If the id is 0, the weapon/armor will be removed (well, technically it will equip nothing...which is the same as removing, no?)

So, just make it the same way you would for equipping, just don't let the player choose anything to equip, just equip with id = 0 and type = equipment window index

 

to remove all you could just do something like:

for i in 0...5
 actor.equip(0, i)
end

just set actor to $game_party.actors[index] (index being the currently selected actor's position in the party)

 

For optimization there are a lot of options (well for each of these, there are probably a lot of different solutions) but what I would do, is get all the available items the actor can equip, sort them based on which is better, then equip the best one. (I dunno if this would be the BEST method...but it would work)

so something like:

# Get all equippable items
equipment = [[], [], [], [], []]
# Get weapons
for id in $game_party.weapons.keys
 if actor.equippable?($data_weapons[id])
   equipment[0].push(id)
 end
end
# Get equipment
for id in $game_party.armors.keys
 armor = $data_armors[id]
 if actor.equippable?(armor)
   equipment[armor.kind].push(id)
 end
end
# Sort equipment
# Weapons
equipment[0].sort do |a, b|
 b.atk <=> a.atk # sort by greatest atk to least atk
end
# Armor
for i in 1...5 # Sort each equipment
 equipment[i].sort do |a, b|
   b.pdef <=> a.pdef # sort by greatest pdef to least pdef
 end
end
# Equip best equipment
for i in 0...5
 actor.equip(equipment[i][0], i)
end

 

Hopefully this helps a bit.

To explain the Array#sort method, array.sort will sort by comparing each value with the <=> operator. a <=> b will return -1 if a < b, 0 if a == b or +1 if a > b (moving a left if -1 or <; or moving a right if +1 or >)

with array.sort { |a, b| block } it invokes the block on values a/b. So, array.sort is the same as array.sort { |a,b| a <=> b }

You can also do things like this:

equipment[0].sort do |a, b|
 if b.atk > a.atk
   +1
 elsif b.atk == a.atk && b.pdef > a.pdef
   +1
 elsif b.atk == a.atk && b.pdef == a.pdef && b.mdef > a.mdef
   +1
 elsif b.atk == a.atk && b.pdef == a.pdef && b.mdef == a.mdef
   0
 else
   -1
 end
end

 

That would sort each weapon by atk, if equal then pdef, if equal then mdef. (descending - greatest to least)

Share this post


Link to post
Share on other sites
  • 0

Thank you for the help again kellessdee, I'll get to work with the Scene_Equip once I finish the Status and main menu. This is going to look nice when I'm done :biggrin_002:

Share this post


Link to post
Share on other sites
  • 0

Okay second thing, I'm having problems with the Window_command:

 

 

#==============================================================================
# ** Window_Command
#------------------------------------------------------------------------------
#  This window deals with general command choices.
#==============================================================================

class Window_Command_Equip < Window_Selectable
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 def initialize
   super(0, 0, 640, 64)
   self.contents = Bitmap.new(width - 32, height - 32)
   self.back_opacity = 255
   commands = ["Equip", "Remove", "Remove All ", "Optimize"]
   @item_max = 4
   @column_max = 4
   self.active = true
   self.visible = true
   self.z = 999
   self.index = 0
 end
 #--------------------------------------------------------------------------
 # * Refresh
 #--------------------------------------------------------------------------
 def refresh
   self.contents.clear
   for i in 0...@item_max
     draw_item(i, normal_color)
   end
 end
 #--------------------------------------------------------------------------
 # * Draw Item
 #     index : item number
 #     color : text character color
 #--------------------------------------------------------------------------
 def draw_item(index, color)
   self.contents.font.color = color
   rect = Rect.new(160 + index * 160 + 4, 0, 128 - 10, 32)
   self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
   self.contents.draw_text(rect, @commands[index], 1)
 end
 #--------------------------------------------------------------------------
 # * Cursor Rectangle Update
 #--------------------------------------------------------------------------
 def update_cursor_rect
   self.cursor_rect.set(160 + index * 160, 0, 128, 32)
 end
end

 

 

When I put it into the scene, the window appears but its way off to the right and I don't know how to move the list (not the window its self but ints contents). Also I can't get the words to appear?

Here's a image of the scene:

post-9377-0-19774500-1318521965_thumb.png

You can see that on first selected is way in the middle instead of near the left edge.

Share this post


Link to post
Share on other sites
  • 0

I'm having problems with the remove-all function ( just combined the remove with the equip function as it was easier).

 

As for removal-all, I put:

  def remove(slot)
   if slot >= 0
     for i in 0...5  
       actor = $game_party.actors[i]
       @actor.equip(0, i)
     end
   end  
 end

 

under Scene_equip. when I went to go click remove-all, it instead optimize the weapon spot but doesn't remove any of the equip.

Edited by bigace

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...