Jump to content

Recommended Posts

I'm quite confused with the following code. Only daywalker2 can drop the item.

for i, v in pairs({ "daywalker", "daywalker2", "sharkboi" }) do
    AddPrefabPostInit(v, function(inst)
        if inst.components.lootdropper == nil then
            inst:AddComponent("lootdropper")
        end
        inst.components.lootdropper:AddChanceLoot("ancient_soul", 1)
    end)
end

 

daywalker uses SetLootSetupFn to determine the exact loot to generate, called when the loot is about to drop. In the function daywalker uses, it calls SetLoot, which resets your chanceloot, so it gets lost. For a solution, I'd hook into the lootsetup function.

sharkboi doesn't call the function to drop loot. Like, anywhere. It doesn't drop anything on death normally. For a solution, hook into its stategraph somewhere to drop the loot or maybe more simply ListenForEvent "minhealth" which handles its death.

  • Like 1
8 hours ago, ClumsyPenny said:

daywalker uses SetLootSetupFn to determine the exact loot to generate, called when the loot is about to drop. In the function daywalker uses, it calls SetLoot, which resets your chanceloot, so it gets lost. For a solution, I'd hook into the lootsetup function.

sharkboi doesn't call the function to drop loot. Like, anywhere. It doesn't drop anything on death normally. For a solution, hook into its stategraph somewhere to drop the loot or maybe more simply ListenForEvent "minhealth" which handles its death.

Alright, I will implement it by listening for the minhealth event. It looks good, thank you very much.

local function OnMinHealth(inst, data)
    if data.afflicter and data.afflicter.prefab == "fhl" and not inst:HasTag("defeated") then
        inst.components.lootdropper:SpawnLootPrefab("ancient_soul")
        inst:AddTag("defeated")
    end
end

for i, v in pairs({ "daywalker", "daywalker2", "sharkboi" }) do
    AddPrefabPostInit(v, function(inst)
        if inst.components.lootdropper == nil then
            inst:AddComponent("lootdropper")
        end
        inst:ListenForEvent("minhealth", OnMinHealth)
    end)
end

 

  • GL Happy 1

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...