Jump to content

Deequip suddenly broken for no perceivable reason


Recommended Posts

I'm working on a mod character and had functionality that would deequip armor from my character if it is not a type that can be worn upon equipping said armor. The method I was using was fully functional until today. I am using a table of item prefab names to tell what armor was not allowed and have a line for listening for equip events that calls to the deequip method.

This is the method:

local function armorNotAllowed (inst, data)
    local item = data.item
    if table.contains(no_wear, item.prefab ) then
        inst:PushEvent("unequip",inst)
        inst.components.inventory:DropItem(item)
        inst.components.talker:Say("I'd rather die than wear that thing.")
    end
end

 

There error in question occurs upon trying to equip a rejected armor type and is in the attached image.
 

Does anyone know why this is occurring or how I can fix it?

post-746023-0-43375200-1450935661_thumb.

Link to comment
Share on other sites

Here is the complete playerinspectable.lua

local EQUIPSLOT_IDS = {}local slot = 0for k, v in pairs(EQUIPSLOTS) do    slot = slot + 1    EQUIPSLOT_IDS[v] = slotendslot = nillocal function OnEquip(inst, data)    inst.Network:SetPlayerEquip(EQUIPSLOT_IDS[data.eslot], data.item:GetSkinName() or data.item.prefab)endlocal function OnUnequip(inst, data)    inst.Network:SetPlayerEquip(EQUIPSLOT_IDS[data.eslot], "")endlocal PlayerInspectable = Class(function(self, inst)    self.inst = inst    inst:ListenForEvent("equip", OnEquip)    inst:ListenForEvent("unequip", OnUnequip)end)return PlayerInspectable

When this component is attached to an entity, this entity will listen for the event "unequip".

 

In your armorNotAllowed function, you push this event, and give as data "inst".

Lne 14 of playerinspectable.lua is then executed and is trying to get

EQUIPSLOT_IDS[data.eslot]

but data is "inst" in your function and has no member called "eslot". Thus the error "number expected, got nil".

 

Remove this line, it's useless. When dropping the item, the unequip event will automatically be pushed with the proper data.

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...