Jump to content

Recommended Posts

My goals for this item are sot:

1. I want to make an item as a basic component plus crafting materials for a weapon.

2. I want to make it so that when the weapon breaks, it reverts to the basic component, minus crafting materials.

Can anyone help me with how to code such a pair?

 

Edited by IoKusanagi

What will break the prefab ? Because, i'm not sure but i think that if you hammer a building, it will return part of the ingredient, based on a recipe, using the line :

    inst.components.lootdropper:DropLoot()

When it's a existing structure without recipe, like mermhouse, you will have somewhere a


    inst:AddComponent("lootdropper")
    inst.components.lootdropper:SetLoot(loot)

and a


local loot =
{
    "boards",
    "rocks",
    "fish",
}

 

(But for example, i made a mod adding a recipe for mermhouse and i'm pretty sure that hammering the house gave me the classic loot and half the ingredient of the recipe (it's why i think that "inst.components.lootdropper:DropLoot()" calls something that will determine that half the ingredients are returned when you destroy something with a recipe, because if you look at structure with ingredients, you don't usually have a "inst.components.lootdropper:SetLoot(loot)" line.

 

So, i think that if you don't want to return half the ingredients of the crafting recipe, but only one, you could do like the pumpkin lantern : when you destroy it, you obtain only the fireflies, but you are guaranteed to obtain it.

 

Meaning that you should have a line like this in your breaking prefab function :

        inst.components.lootdropper:SpawnLootPrefab("fireflies")

I hope it's clear, i'm sorry if not.

3 hours ago, Lumina said:

What will break the prefab ? Because, i'm not sure but i think that if you hammer a building, it will return part of the ingredient, based on a recipe, using the line :


    inst.components.lootdropper:DropLoot()

When it's a existing structure without recipe, like mermhouse, you will have somewhere a


    inst:AddComponent("lootdropper")
    inst.components.lootdropper:SetLoot(loot)

and a


local loot =
{
    "boards",
    "rocks",
    "fish",
}

 

(But for example, i made a mod adding a recipe for mermhouse and i'm pretty sure that hammering the house gave me the classic loot and half the ingredient of the recipe (it's why i think that "inst.components.lootdropper:DropLoot()" calls something that will determine that half the ingredients are returned when you destroy something with a recipe, because if you look at structure with ingredients, you don't usually have a "inst.components.lootdropper:SetLoot(loot)" line.

 

So, i think that if you don't want to return half the ingredients of the crafting recipe, but only one, you could do like the pumpkin lantern : when you destroy it, you obtain only the fireflies, but you are guaranteed to obtain it.

 

Meaning that you should have a line like this in your breaking prefab function :


        inst.components.lootdropper:SpawnLootPrefab("fireflies")

I hope it's clear, i'm sorry if not.

Ah sorry, I might have written unclearly, basically I wanted to make an item as a component for a weapon, and when the weapon breaks, it returns the component to your inventory.

Ok, so i guess you could try something like this.

Add the prefab you want to be able to drop :

local prefabs =
{
    "fireflies",
}

Add a function :


local function OnFinished(inst)
inst.components.lootdropper:SpawnLootPrefab("fireflies")
inst:Remove()
end

 

And having this line

inst.components.finiteuses:SetOnFinished(OnFinished)

Like this :

    inst:AddComponent("finiteuses")
    inst.components.finiteuses:SetMaxUses(TUNING.SPEAR_USES)
    inst.components.finiteuses:SetUses(TUNING.SPEAR_USES)
	inst.components.finiteuses:SetOnFinished(OnFinished)

 

 

Usually, a weapon already have a "inst.components.finiteuses:SetOnFinished(inst.Remove)", so replace this line.

Of course, don't forget to replace fireflies with your prefab name.

Also, add a line :

    inst:AddComponent("lootdropper")

Before the inspectable component, usually.

It should work, let me know.

On 11/6/2016 at 6:50 AM, Lumina said:

Ok, so i guess you could try something like this.

Add the prefab you want to be able to drop :


local prefabs =
{
    "fireflies",
}

Add a function :



local function OnFinished(inst)
inst.components.lootdropper:SpawnLootPrefab("fireflies")
inst:Remove()
end

 

And having this line


inst.components.finiteuses:SetOnFinished(OnFinished)

Like this :


    inst:AddComponent("finiteuses")
    inst.components.finiteuses:SetMaxUses(TUNING.SPEAR_USES)
    inst.components.finiteuses:SetUses(TUNING.SPEAR_USES)
	inst.components.finiteuses:SetOnFinished(OnFinished)

 

 

Usually, a weapon already have a "inst.components.finiteuses:SetOnFinished(inst.Remove)", so replace this line.

Of course, don't forget to replace fireflies with your prefab name.

Also, add a line :


    inst:AddComponent("lootdropper")

Before the inspectable component, usually.

It should work, let me know.

It works! Thank you very much for your help!

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