Jump to content

Listening for event "armorbroke"


SenL

Recommended Posts

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

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

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

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.

×
  • Create New...