Jump to content

Unequip damaged items.


Recommended Posts

@penguin0616
That edit does stop the game crashing!  The game runs, everything seems fine.  When I equip an amulet though the game crashes.  Apparently the 'unequip' code isn't being called, I think.  I appreciate all the help, but omg, this seems way, way more complicated than it should be..

When I ran this code, the unequip code was in the character's file.  It's 3am, but I tested it again by putting the unequip code in the modmain.  I think I got a similar result, but I'll try to post the server log for that test tomorrow.

[00:01:31]: [string "../mods/FurryEskimo/modmain.lua"]:114: attempt to call global 'AutoUnequip' (a nil value)
LUA ERROR stack traceback:
    ../mods/FurryEskimo/modmain.lua:114 in (local) fn (Lua) <113-115>
    scripts/entityscript.lua:1040 in (method) PushEvent (Lua) <1027-1054>
    scripts/components/fueled.lua:285 in (method) DoDelta (Lua) <268-286>
    scripts/components/fueled.lua:290 in (method) DoUpdate (Lua) <288-300>
    scripts/components/fueled.lua:251 in (method) OnWallUpdate (Lua) <247-252>
    scripts/update.lua:57 in () ? (Lua) <33-129>
    
[00:01:31]: Warning: Widget:SetFocusFromChild is happening on a widget outside of the screen/widget hierachy. This will cause focus moves to fail. Is     ScriptErrorWidget    not a screen?    
[00:01:31]: stack traceback:
    scripts/widgets/widget.lua:605 in (method) SetFocusFromChild (Lua) <602-627>
    scripts/widgets/widget.lua:624 in (method) SetFocusFromChild (Lua) <602-627>
    scripts/widgets/widget.lua:624 in (method) SetFocusFromChild (Lua) <602-627>
    scripts/widgets/widget.lua:656 in (method) SetFocus (Lua) <629-665>
    scripts/widgets/menu.lua:83 in (method) SetFocus (Lua) <74-85>
    scripts/widgets/scripterrorwidget.lua:109 in (method) OnUpdate (Lua) <102-119>
    scripts/update.lua:90 in () ? (Lua) <33-129>    
 

Link to comment
Share on other sites

@penguin0616@penguin0616
Ok, it's working!  Phew!  I added them both to the modmain.lua file this morning and they just, work.  I'm not sure what I did differently this morning compared to last night, but it's working.  I made one change, so that the unequip code checks the player's character and only my custom character will unequip.  Thanks so, so much for your help!

function AutoUnequip(inst, data)  --Test code.
    print("Preparing to unequip item.")
    local owner = inst.components.inventoryitem:GetGrandOwner()
    if owner and owner.components.inventory:IsItemEquipped(inst) and owner:HasTag("furryeskimo") then -- check if someone is holding it and they have it equipped
        print("There's an owner and item.")
        if data.percent <= 0.05 then -- check if its 5% or below
            print("Item is damaged, and being removed.")
            --owner.components.inventory:Unequip(EQUIPSLOTS.BODY) -- expressly unequips
            owner.components.inventory:GiveItem(inst) -- implicitly unequips
        end
    end
end

AddPrefabPostInit("blueamulet", function(inst)  --Test code.
    if not GLOBAL.TheWorld.ismastersim then return end
    inst:ListenForEvent("percentusedchange", function(inst, data)
        AutoUnequip(inst, data)
    end)
end)

Edited by FurryEskimo
Link to comment
Share on other sites

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
 Share

×
  • Create New...