Jump to content

Recommended Posts

Hello,

So, i need a script that makes me drop an item when the hat breaks.
I tried to use this script:

local prefabs = { 
     "gmask",
}

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

and in the fn() function:

 inst:AddComponent("lootdropper")

But it doesn't work with the hat when it works with a weapon for example.

I am a noobie about writing a code from scratch, so any code advices / pieces would be helpful,

Thanks.

 

Edited by Meson
Link to comment
https://forums.kleientertainment.com/forums/topic/86708-hat-script-lootdrop/
Share on other sites

could try this:

local function onfinished(inst)
    inst:Remove()
end
 
local function onfinished_hat(inst)
    inst.components.lootdropper:SpawnLootPrefab("gmask") --drop the mask on the ground when finished
    inst:Remove()
end

local function onequip(inst, owner)-- reference on where the code goes
    inst.components.fueled:StartConsuming()

local function onunequip(inst, owner) --reference on where the code goes
inst.components.fueled:StopConsuming()

 

if not TheWorld.ismastersim then --reference on where the code goes
        return inst
    end

 inst:AddComponent("fueled")
        inst.components.fueled.fueltype = FUELTYPE.USAGE
        inst.components.fueled:InitializeFuelLevel(2) --how many seconds it'll last
        inst.components.fueled:SetDepletedFn(onfinished_hat)

inst:AddComponent("lootdropper")

I'm assuming the gas mask depletes by continuously wearing it so I didn't try it as armour or perishable item like food.

 

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