SenL Posted June 10, 2022 Share Posted June 10, 2022 I'm having problem with listening to this event. If I do this, it doesn't capture. inst:ListenForEvent("armorbroke", function(inst) armorbrokefn(inst) end) If I do this, it does but the inst.prefab is wilson (not the item with armor component) inst:ListenForEvent("armorbroke", function(inst) armorbrokefn(inst) end, GetPlayer()) How do you do it? Thanks. Link to comment Share on other sites More sharing options...
Leonidas IV Posted June 11, 2022 Share Posted June 11, 2022 20 hours ago, SenL said: I'm having problem with listening to this event. If I do this, it doesn't capture. inst:ListenForEvent("armorbroke", function(inst) armorbrokefn(inst) end) If I do this, it does but the inst.prefab is wilson (not the item with armor component) inst:ListenForEvent("armorbroke", function(inst) armorbrokefn(inst) end, GetPlayer()) How do you do it? Thanks. Function that pushes the event: local function PercentChanged(inst, data) if inst.components.armor and data.percent and data.percent <= 0 and inst.components.inventoryitem and inst.components.inventoryitem.owner then inst.components.inventoryitem.owner:PushEvent("armorbroke", {armor = inst}) end end Who pushes the event is the owner, ie the player. So: inst:ListenForEvent("armorbroke", function(player, data) armorbrokefn(player, data) end, GetPlayer()) Where data is a table: {armor = inst} To access the armor entity you will use data.armor See the definition of the PushEvent and ListenToEvent functions in the entityscript.lua file (where almost all the functions that all prefabs have by default are located. Link to comment Share on other sites More sharing options...
SenL Posted June 11, 2022 Author Share Posted June 11, 2022 This works. Thanks. However, when I try to print out the armor maxcondition it crashes (attempt to index, nil) print(data.armor.maxcondition) This one also crashes: print(data.components.armor.maxcondition) Strange because armor component always has maxcondition. Link to comment Share on other sites More sharing options...
Leonidas IV Posted June 12, 2022 Share Posted June 12, 2022 21 hours ago, SenL said: it crashes After pushing this event the armor is removed (no longer exists), so possibly you need to store it in a variable inside your function first, and then just in case check if the variable exists. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.