SenL Posted June 10, 2022 Share Posted June 10, 2022 (edited) 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. Edited June 10, 2022 by SenL Link to comment https://forums.kleientertainment.com/forums/topic/140801-listening-for-event-armorbroke/ 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 https://forums.kleientertainment.com/forums/topic/140801-listening-for-event-armorbroke/#findComment-1576428 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 https://forums.kleientertainment.com/forums/topic/140801-listening-for-event-armorbroke/#findComment-1576446 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. 1 Link to comment https://forums.kleientertainment.com/forums/topic/140801-listening-for-event-armorbroke/#findComment-1576604 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