Jump to content

Recommended Posts

Hello! I want roses to drop rose petals instead of usual petals. (I already made rose petals as an item and it works as intended).

I tried several options, but they either work only for newly spawned roses or don't work at all.

 

The code I currently have:

AddComponentPostInit(function(inst)
    local function PickUpRosePetals(inst)
        if not inst.components.pickable then
			return
		end
        if inst.components.pickable then
            inst.components.pickable:SetUp("rose_petals", 1) --change the item it gives when picked
            inst:RemoveEventCallback("picked", PickUpRosePetals) --stops listening to event
        end
    end

	-- rose was picked
	if inst.prefab == "flower_rose" then
		--ListenForEvent
		inst:ListenForEvent("picked", PickUpRosePetals)
	end
end)

What can I do to make this work? Any help is appreciated.

 

Component postinit requires the first argument to be a component name, second being the function. Either way, you're better off using AddPrefabPostInit if it's only for the rose.

AddPrefabPostInit("flower_rose", function(inst)
    -- Uncomment this ONLY IF your mod is tagged "all_clients_require_mod". Leave as is if it's "server_only_mod"
    -- if not GLOBAL.TheWorld.ismastersim then
    --     return
    -- end

    if inst.components.pickable then
        inst.components.pickable:ChangeProduct("rose_petals")
    end
end)

ChangeProduct simply just changes the product and doesn't do anything else, as such it'll leave the petals given number too.

Edited by Baguettes
forgot GLOBAL.TheWorld is a wee bit more complicated than that, so I'd rather not give that advice since I don't remember fully.
1 hour ago, Baguettes said:

Component postinit requires the first argument to be a component name, second being the function. Either way, you're better off using AddPrefabPostInit if it's only for the rose.

AddPrefabPostInit("flower_rose", function(inst)
    -- Uncomment this ONLY IF your mod is tagged "all_clients_require_mod". Leave as is if it's "server_only_mod"
    -- if not GLOBAL.TheWorld.ismastersim then
    --     return
    -- end

    if inst.components.pickable then
        inst.components.pickable:ChangeProduct("rose_petals")
    end
end)

ChangeProduct simply just changes the product and doesn't do anything else, as such it'll leave the petals given number too.

Thank you for the reply, but this code has the same problem - it works only for the newly spawned roses. So if i re-enter the world nothing works anymore...

7 hours ago, ualreadyknowme said:

Thank you for the reply, but this code has the same problem - it works only for the newly spawned roses. So if i re-enter the world nothing works anymore...

Huh. I swear PrefabPostInit works for everything, even existing ones after reloading. Odd... does your mod happen to have anything else concerning roses? Just curious.

2 hours ago, Baguettes said:

Huh. I swear PrefabPostInit works for everything, even existing ones after reloading. Odd... does your mod happen to have anything else concerning roses? Just curious.

This is supposed to be the only part of the code that alters roses. 

I'm making a character, but currently it's just esctemplate with graphics. And rose petals item I've added is basically a copy and paste of in-game petals prefab. I plan to make character's skills based around roses, but i'm stuck :(

My modmain.lua - Extended Sample Character base code + addPrefabPostInit that you suggested.

Rose_petals prefab has nothing in it that involves roses but I attached it just in case. Could any of these be the problem? What can I do?

rose_petals.lua

9 hours ago, Baguettes said:

Maybe send modmain too if you're comfortable.

Sure! 

here is modmain.lua 

I also attached a zip file, this is a separate mod (no character, nothing else but changing the rose drop to log, so no modded items are involved). And it still only works on new roses...

This way I tried to check myself if anything in my initial code affects it, seems like no.

modmain.lua Rose_Petals_Separate_Mod.zip

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