Jump to content

Recommended Posts

I'm trying to create a character that has a starting item that's not at 100% durability. If I add the item to the start_inv list, it always gets put in at 100%, and I can't seem to find a way around this. I tried creating one with SpawnPrefab in the general startup code (local fn = function(inst)) so I could set the percent on the fueled component, but this runs every time the character is loaded, not just created, so reloading a save gives them the item again.

Any ideas?

@Alkalissa I think the most stable way of doing it would probably be to make a copy of the original item and making one with less durability specifically for your character. Alternately, you could dig into how inventory:GuaranteeItems works.

 

For reference:

inventory.lua

function Inventory:GuaranteeItems(items)    self.inst:DoTaskInTime(0,function()                for k,v in pairs(items) do            local item = v                        local equipped = false            for k,v in pairs (self.equipslots) do                if v and v.prefab == item then                    equipped = true                end            end            if equipped or self:Has(item, 1) then                for k,v in pairs(Ents) do                    if v.prefab == item and v.components.inventoryitem:GetGrandOwner() ~= GetPlayer() then                        v:Remove()                    end                end            else                for k,v in pairs(Ents) do                    if v.prefab == item then                        item = nil                        break                    end                end                if item then                    self:GiveItem(SpawnPrefab(item))                end            end        end    end)end 

Edited by Blueberrys

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...