Page 1 of 1

Item repair based on part's condition?

Posted: 16 Feb 2017, 14:58
by Axebeardbeardaxe
I'm looking at mod for Call of Misery that lets you disassemble weapons into spare parts. I understand how the "if item is a weapon, then give a spare part" code works, but what I can't figure out is how to get the condition of the weapon in question. How can I get the condition of the weapon and have the game give X amount of spare parts based on it?

Ideally, weapons would give 0-4 spare parts based on their condition.
I looked at the ui_itm_repair scripts in CoC and CoM and they are 95% the same, so I was hoping you'd be able to help me out here. Here's the relevant block of code: (I cut out the huge list of weapons between "wpn_bm16_full" and "wpn_ppsh41")

Code: Select all

index = self.list_box_parts:GetSelectedIndex()
      if (index ~= -1) then
         item = self.list_box_parts:GetItemByIndex(index)
         local se_parts = item and item.item_id and alife():object(item.item_id)
         if (se_parts) then
            local sec = se_parts:section_name()
            bonus = system_ini():r_float_ex(sec,"repair_part_bonus") or self.part_bonus
            -- swiss knife
            if(db.actor)and(sec=="swiss")then
               alife():create("swiss", db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id())
            end
            -- crowbar
            if(db.actor)and(sec=="crowbar")then
               alife():create("crowbar", db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id())
            end
            -- hammer
            if(db.actor)and(sec=="hammer_inv")then
               alife():create("hammer_inv", db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id())
            end
            if(se_parts)and(se_parts:section_name()=="wpn_pm") or se_parts:section_name()=="wpn_bm16" or       se_parts:section_name()=="wpn_bm16_full"  ...
             se_parts:section_name()=="wpn_ppsh41" then
                  alife():create("spareparts", db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id())
             end

Re: Item repair based on part's condition?

Posted: 17 Feb 2017, 02:19
by Alundaio
That is because 90% of CoM and Misery scripts are my code, with edits to them.

Code: Select all

local cond = 1
local part = item and item.item_id and level.object_by_id(item.item_id)
if (part) then
   cond = part:condition() -- Will be a number between 0 and 1
end


probably want to put that after if (se_parts) then