Delly182 Posted December 24, 2015 Share Posted December 24, 2015 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.") endend 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? Link to comment Share on other sites More sharing options...
Delly182 Posted December 24, 2015 Author Share Posted December 24, 2015 Additionally, line 111 is inst:PushEvent("unequip",inst) Link to comment Share on other sites More sharing options...
ZupaleX Posted December 24, 2015 Share Posted December 24, 2015 Here is the complete playerinspectable.lualocal 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 PlayerInspectableWhen 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 getEQUIPSLOT_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 More sharing options...
Delly182 Posted December 24, 2015 Author Share Posted December 24, 2015 The issue is resolved and I understand what I did wrong! Thanks for the detailed response! Link to comment Share on other sites More sharing options...
ZupaleX Posted December 24, 2015 Share Posted December 24, 2015 You're welcome. I prefer trying to explain what was the issue and work with what was already done, instead of just throwing a bunch of code without any explanation. It's more helpful on the long term. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now