RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Item Weight?

0 Members and 1 Guest are viewing this topic.

***
Rep:
Level 82
We learn by living...
$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.

*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
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".

***
Rep:
Level 82
We learn by living...
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...
Code: [Select]
      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...
« Last Edit: September 21, 2011, 11:55:51 PM by shintashi »

*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
Sorry again, I was using VX code. Let's try this:

Code: [Select]
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.



***
Rep:
Level 82
We learn by living...
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.

***
Rep:
Level 82
We learn by living...
so I got this set up, in Window_step count's refresh,

Code: [Select]
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.

*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
Wow I am really bad with XP.

Code: [Select]
  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.

***
Rep:
Level 82
We learn by living...
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:

Code: [Select]
#=============================================================   
#                ***   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.
« Last Edit: September 22, 2011, 05:25:10 AM by shintashi »