Main Menu
  • Welcome to The RPG Maker Resource Kit.

Item Weight?

Started by shintashi, September 13, 2011, 07:42:29 PM

0 Members and 1 Guest are viewing this topic.

shintashi

Quote from: cozziekuns on September 21, 2011, 04:35:46 AM
$game_party.items.keys.

I was writing it blind; apologies.

I get "undefined method for items" error. What are keys anyway? They only appear in maps.

cozziekuns

Items is a hash. Every hash is referenced by a key and it's value. You can see more from the help file. The reason keys gave an error was because you probably wrote "keys.", not "keys".

shintashi

#27
Quote from: cozziekuns on September 21, 2011, 09:44:34 PM
Items is a hash. Every hash is referenced by a key and it's value. You can see more from the help file. The reason keys gave an error was because you probably wrote "keys.", not "keys".

here's what I've got - I stuck it in Gold Window as a quick display...

      total_weight = 0
for item_id in $game_party.items.keys
  num = $game_party.item_number(item_id)
  weight = $data_items[item_id].weight
  total_weight += (weight * num)
end
return total_weight
    self.contents.draw_text(124-cx, 120-cx-24, cx, 32, total_weight.to_s, 2)


I should point out it didn't work...

cozziekuns

Sorry again, I was using VX code. Let's try this:


class Game_Party
 
  def items
    result = []
    for i in @items.keys.sort
      result.push([i, 0]) if @items[i] > 0
    end
    for i in @weapons.keys.sort
      result.push([i, 1]) if @weapons[i] > 0
    end
    for i in @armors.keys.sort
      result.push([i, 2]) if @armors[i] > 0
    end
    return result
  end
 
  def total_weight
    total_weight = 0
    items = $game_party.items
    for item in items
      item_id = item[0]
      type = item[1]
      num = $game_party.item_number(item_id)
      case type
      when 0
        weight = $data_items[item_id].weight
      when 1
        weight = $data_weapons[item_id].weight
      when 2
        weight = $data_armors[item_id].weight
      end
      total_weight += (weight * num)
    end
    return total_weight
  end

 
end

To find the total weight, use $game_party.total_weight.



shintashi

appears to work like a charm ^^

I'll see what I can do to integrate these figures into something like movement. If I have any success, I'll post on it. The goal is if your party or actor is carrying too much junk, they can't move or physically attack, respectively.

shintashi

so I got this set up, in Window_step count's refresh,


def refresh
    self.contents.clear
    self.contents.font.color = system_color
    self.contents.draw_text(4, 0, 120, 32, "Encumbrance") #was "Step Count"
    self.contents.font.color = normal_color
    #self.contents.draw_text(4, 32, 120, 32, $game_party.steps.to_s, 2)


    for i in 0...$game_party.actors.size
      if $game_party.actors[i] != nil
        @max_carry += $game_party.actors[i].enc
      else
        @max_carry += 0
      return @max_carry
      end
    end
   
    self.contents.draw_text(4, 32, 120, 32, $game_party.total_weight.to_s + "/" + @max_carry.to_s, 2)
  end
end


but I noticed it's not apparently logging the weight of weapons and armor, even if I take them off and they go back into my inventory. I'm not sure what this means yet, but the other items, like potions, add up and display normally.

cozziekuns

Wow I am really bad with XP.


  def total_weight
    total_weight = 0
    items = $game_party.items
    for item in items
      item_id = item[0]
      type = item[1]
      case type
      when 0
        num = $game_party.item_number(item_id)
        weight = $data_items[item_id].weight
      when 1
        num = $game_party.weapon_number(item_id)
        weight = $data_weapons[item_id].weight
      when 2
        num = $game_party.armor_number(item_id)
        weight = $data_armors[item_id].weight
      end
      total_weight += (weight * num)
    end
    return total_weight
  end


Replace your existing total_weight with this.

shintashi

#32
VX is still cool, I just don't have it.

The fix worked though. I can see people "putting on their stuff" to lower their total party encumbrance. While at first that doesn't seem to work, in reality, we do this kind of thing all the time - you put stuff on your person to free up hand space. This gives me mad crazy ideas for encumbrance modifying doodads - backpacks, horses, etc.

What I like about this code is the idea that it can rapidly be stuck into almost any XP game.

edit:

I modified the Encumbrance code accordingly:


#=============================================================   
#                ***   Encumbrance ***
self.contents.font.color = system_color
    self.contents.draw_text(320, 112, 120, 32, "Carry")
self.contents.font.color = normal_color

a = @actor.weapon_id
a1 = $data_weapons[a] == nil ? 0 : $data_weapons[a].weight

b = @actor.armor1_id
b1 = $data_armors[b] == nil ? 0 : $data_armors[b].weight

c = @actor.armor2_id
c1 = $data_armors[c] == nil ? 0 : $data_armors[c].weight

d = @actor.armor3_id
d1 = $data_armors[d] == nil ? 0 : $data_armors[d].weight

e = @actor.armor4_id
e1 = $data_armors[e] == nil ? 0 : $data_armors[e].weight

carry = 0 + a1 + b1 + c1 + d1 + e1
self.contents.draw_text(320 + 80, 112, 84, 32, carry.to_s + "/" + @actor.enc.to_s, 2)
   
#==============================================================


it's crude, but it should add up the total weight of what you are carrying.