Jump to content

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.

Edited by SenL
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.

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.

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
×
  • Create New...