Doodle Monster Posted April 10, 2025 Share Posted April 10, 2025 Hi! So, I wanted to do something similar with the shadow tools with a fx animation and sanity drain. I did a little digging in dst’s prefabs but I could not find a component for on item use. Basically I want to spawn a FX effect on the object being chopped/mined and drain sanity when the item is used for each use. I have basic knowledge of Lua. with functions and variables, still trying to learn returns and such Any help would be really awesome! Link to comment https://forums.kleientertainment.com/forums/topic/165280-help-with-adding-fx-effect-and-sanity-loss-on-use-to-tools/ Share on other sites More sharing options...
Merkyrrie Posted April 11, 2025 Share Posted April 11, 2025 Tools don't have a dedicated on hit function in their component to make things easier like weapons do, but there is a push event when a character does a "work" action, which includes mining, chopping, and digging. You can call a listenforevent for this event in the onequip function of the tools. local function OnDoingWork(owner, data) -- From Wolfgang's prefab if data ~= nil and data.target ~= nil then local workable = data.target.components.workable if workable ~= nil then local work_action = workable:GetWorkAction() if work_action ~= nil then -- Spawn FX and lower sanity code would go here end end end end local function onequip(inst, owner) -- The usual onequip code here too owner:ListenForEvent("working", OnDoingWork) -- "owner" instead of "inst" because the player's instance is what the event is being pushed to end local function onunequip(inst, owner) -- The usual onunequip code here too owner:RemoveEventCallback("working", OnDoingWork) -- This stops listening for the event when the item is unequipped. end Link to comment https://forums.kleientertainment.com/forums/topic/165280-help-with-adding-fx-effect-and-sanity-loss-on-use-to-tools/#findComment-1811739 Share on other sites More sharing options...
Doodle Monster Posted April 11, 2025 Author Share Posted April 11, 2025 Thanks for the help! Do I need to specify the location I want the FX to spawn? I'm trying to make it spawn ontop of the object being choped/mined Link to comment https://forums.kleientertainment.com/forums/topic/165280-help-with-adding-fx-effect-and-sanity-loss-on-use-to-tools/#findComment-1811820 Share on other sites More sharing options...
Doodle Monster Posted April 11, 2025 Author Share Posted April 11, 2025 Okay, So I put everything together; not sure if I did the sanity drain correctly. As soon as I craft the Axe my game crashes and throws this error My function looks like this local function OnDoingWork(owner, data) -- From Wolfgang's prefab if data ~= nil and data.target ~= nil then local workable = data.target.components.workable if workable ~= nil then local work_action = workable:GetWorkAction() if work_action ~= nil then local fx_prefab = "shadow_despawn" and owner.components.sanity:DoDelta(-.5 * TUNING.BATBAT_DRAIN) if fx_prefab ~= nil then local fx = SpawnPrefab(fx_prefab) local x, y, z = target.Transform:GetWorldPosition() local radius = target:GetPhysicsRadius(.5) local angle = (inst.Transform:GetRotation() - 90) * DEGREES fx.Transform:SetPosition(x + math.sin(angle) * radius, 0, z + math.cos(angle) * radius) end -- Spawn FX and lower sanity code would go here end end end end Link to comment https://forums.kleientertainment.com/forums/topic/165280-help-with-adding-fx-effect-and-sanity-loss-on-use-to-tools/#findComment-1811822 Share on other sites More sharing options...
Doodle Monster Posted April 11, 2025 Author Share Posted April 11, 2025 (edited) My onequpit and onunequpit functions look like this local function OnEquip(inst, owner) -- This will override symbol "swap_body" of the equipping player with your custom build symbol. -- Here's what this function is overriding: -- owner.AnimState:OverrideSymbol(Player's_symbol, Your_build(*.zip_filename), Symbol_from_your_build(name_of_subfolder_with_art) owner.AnimState:OverrideSymbol("swap_object", "woven_axe", "swap_object") owner:ListenForEvent("working", OnDoingWork) -- "owner" instead of "inst" because the player's instance is what the event is being pushed to -- Players have 2 left arms - one of them is hidden when we are not holding an item and vice versa. -- Since we want to show an item on equip - hide ARM_normal and show ARM_carry. owner.AnimState:Show("ARM_carry") owner.AnimState:Hide("ARM_normal") end local function OnUnequip(inst, owner) owner.AnimState:Hide("ARM_carry") owner.AnimState:Show("ARM_normal") owner:RemoveEventCallback("working", OnDoingWork) -- This stops listening for the event when the item is unequipped. end Edited April 11, 2025 by Doodle Monster Link to comment https://forums.kleientertainment.com/forums/topic/165280-help-with-adding-fx-effect-and-sanity-loss-on-use-to-tools/#findComment-1811823 Share on other sites More sharing options...
Doodle Monster Posted April 11, 2025 Author Share Posted April 11, 2025 (edited) @Merkyrrie Sorry for the ping! Just wanted to make sure this gets to you Edited April 11, 2025 by Doodle Monster Link to comment https://forums.kleientertainment.com/forums/topic/165280-help-with-adding-fx-effect-and-sanity-loss-on-use-to-tools/#findComment-1811824 Share on other sites More sharing options...
Doodle Monster Posted April 11, 2025 Author Share Posted April 11, 2025 I'm not sure why it's saying the varible isn't defined, I'm assumeing I have to define it further up maybe with the wolfgang file Link to comment https://forums.kleientertainment.com/forums/topic/165280-help-with-adding-fx-effect-and-sanity-loss-on-use-to-tools/#findComment-1811826 Share on other sites More sharing options...
Doodle Monster Posted April 11, 2025 Author Share Posted April 11, 2025 I did find this further down in the wolfgang file; but it looks like I already have it in the onequpit and unequpit so I'm not sure what is going on inst:ListenForEvent("working", OnDoingWork) Link to comment https://forums.kleientertainment.com/forums/topic/165280-help-with-adding-fx-effect-and-sanity-loss-on-use-to-tools/#findComment-1811827 Share on other sites More sharing options...
Merkyrrie Posted April 12, 2025 Share Posted April 12, 2025 (edited) 17 hours ago, Doodle Monster said: Okay, So I put everything together; not sure if I did the sanity drain correctly. As soon as I craft the Axe my game crashes and throws this error My function looks like this local function OnDoingWork(owner, data) -- From Wolfgang's prefab if data ~= nil and data.target ~= nil then local workable = data.target.components.workable if workable ~= nil then local work_action = workable:GetWorkAction() if work_action ~= nil then local fx_prefab = "shadow_despawn" and owner.components.sanity:DoDelta(-.5 * TUNING.BATBAT_DRAIN) if fx_prefab ~= nil then local fx = SpawnPrefab(fx_prefab) local x, y, z = target.Transform:GetWorldPosition() local radius = target:GetPhysicsRadius(.5) local angle = (inst.Transform:GetRotation() - 90) * DEGREES fx.Transform:SetPosition(x + math.sin(angle) * radius, 0, z + math.cos(angle) * radius) end -- Spawn FX and lower sanity code would go here end end end end Is the OnDoingWork function above or below the onequip and onunequip functions? local functions should generally be above anything that is calling them Edited April 12, 2025 by Merkyrrie Link to comment https://forums.kleientertainment.com/forums/topic/165280-help-with-adding-fx-effect-and-sanity-loss-on-use-to-tools/#findComment-1811953 Share on other sites More sharing options...
Doodle Monster Posted April 12, 2025 Author Share Posted April 12, 2025 Got it! it makes sense; the onequip and unequip functions won't know what OndoingWork is unless the function is above them Link to comment https://forums.kleientertainment.com/forums/topic/165280-help-with-adding-fx-effect-and-sanity-loss-on-use-to-tools/#findComment-1811980 Share on other sites More sharing options...
Doodle Monster Posted April 12, 2025 Author Share Posted April 12, 2025 Okay, So I moved the function and tested it; and the sanity drain is working! Just not the FX Link to comment https://forums.kleientertainment.com/forums/topic/165280-help-with-adding-fx-effect-and-sanity-loss-on-use-to-tools/#findComment-1811982 Share on other sites More sharing options...
Doodle Monster Posted April 12, 2025 Author Share Posted April 12, 2025 @Merkyrrie I assume I have to specify the location of the FX somehow? I don't think the code for the attack will work Link to comment https://forums.kleientertainment.com/forums/topic/165280-help-with-adding-fx-effect-and-sanity-loss-on-use-to-tools/#findComment-1811991 Share on other sites More sharing options...
Merkyrrie Posted April 12, 2025 Share Posted April 12, 2025 4 hours ago, Doodle Monster said: @Merkyrrie I assume I have to specify the location of the FX somehow? I don't think the code for the attack will work The same code should work, just use 'data.target' in place of 'target' for example 'target.Transform:GetWorldPosition()' becoming data.target.Transform:GetWorldPosition() Data.target in this case is the instance of the rock/tree being worked. Link to comment https://forums.kleientertainment.com/forums/topic/165280-help-with-adding-fx-effect-and-sanity-loss-on-use-to-tools/#findComment-1812016 Share on other sites More sharing options...
Doodle Monster Posted April 13, 2025 Author Share Posted April 13, 2025 Awesome! I'll give it a test then get back to you. Link to comment https://forums.kleientertainment.com/forums/topic/165280-help-with-adding-fx-effect-and-sanity-loss-on-use-to-tools/#findComment-1812037 Share on other sites More sharing options...
Doodle Monster Posted April 13, 2025 Author Share Posted April 13, 2025 I pulled it up ingame and gave it a test! Sanity drain is definitely working but the FX isn't showing up after I added the 'data.target' I'm not sure If I need the math at the end that transforms the FX either here's my function and prefab file. local function OnDoingWork(owner, data) -- From Wolfgang's prefab if data ~= nil and data.target ~= nil then local workable = data.target.components.workable if workable ~= nil then local work_action = workable:GetWorkAction() if work_action ~= nil then local fx_prefab = "shadow_despawn" and owner.components.sanity:DoDelta(-.5 * TUNING.BATBAT_DRAIN) if fx_prefab ~= nil then local fx = SpawnPrefab(fx_prefab) local x, y, z = data.target.Transform:GetWorldPosition() local radius = data.target:GetPhysicsRadius(.5) local angle = (inst.Transform:GetRotation() - 90) * DEGREES fx.Transform:SetPosition(x + math.sin(angle) * radius, 0, z + math.cos(angle) * radius) end -- Spawn FX and lower sanity code would go here end end end end woven_axe.lua Link to comment https://forums.kleientertainment.com/forums/topic/165280-help-with-adding-fx-effect-and-sanity-loss-on-use-to-tools/#findComment-1812039 Share on other sites More sharing options...
Doodle Monster Posted April 13, 2025 Author Share Posted April 13, 2025 @Merkyrrie Link to comment https://forums.kleientertainment.com/forums/topic/165280-help-with-adding-fx-effect-and-sanity-loss-on-use-to-tools/#findComment-1812041 Share on other sites More sharing options...
Baguettes Posted April 13, 2025 Share Posted April 13, 2025 Put fx.Transform:SetPosition(x, y, z) under your local x, y, z, that may work. Link to comment https://forums.kleientertainment.com/forums/topic/165280-help-with-adding-fx-effect-and-sanity-loss-on-use-to-tools/#findComment-1812057 Share on other sites More sharing options...
Merkyrrie Posted April 13, 2025 Share Posted April 13, 2025 1 hour ago, Baguettes said: Put fx.Transform:SetPosition(x, y, z) under your local x, y, z, that may work. Yeah I'm not sure if the math is actually necessary in this instance or not, however, local fx_prefab = "shadow_despawn" and Remove the "and" here as its causing it to actually make fx_prefab nil here, as well as, local angle = (inst.Transform:GetRotation() - 90) * DEGREES "inst" here should be "owner" instead. Link to comment https://forums.kleientertainment.com/forums/topic/165280-help-with-adding-fx-effect-and-sanity-loss-on-use-to-tools/#findComment-1812060 Share on other sites More sharing options...
Baguettes Posted April 13, 2025 Share Posted April 13, 2025 1 hour ago, Merkyrrie said: Yeah I'm not sure if the math is actually necessary in this instance or not, however, All prefabs from SpawnPrefab defaults to 0, 0, 0 if you don't specify where it should go. Link to comment https://forums.kleientertainment.com/forums/topic/165280-help-with-adding-fx-effect-and-sanity-loss-on-use-to-tools/#findComment-1812066 Share on other sites More sharing options...
Merkyrrie Posted April 13, 2025 Share Posted April 13, 2025 7 minutes ago, Baguettes said: All prefabs from SpawnPrefab defaults to 0, 0, 0 if you don't specify where it should go. This is correct, the Transform:SetPosition is necessary. I just meant the math applied to the workable's x,y,z in this SetPosition might not be necessary 1 Link to comment https://forums.kleientertainment.com/forums/topic/165280-help-with-adding-fx-effect-and-sanity-loss-on-use-to-tools/#findComment-1812067 Share on other sites More sharing options...
Doodle Monster Posted April 13, 2025 Author Share Posted April 13, 2025 It works now! Thanks for the help; Now I just need to do the same thing with the pickaxe which I assume would be exactly the same. Link to comment https://forums.kleientertainment.com/forums/topic/165280-help-with-adding-fx-effect-and-sanity-loss-on-use-to-tools/#findComment-1812103 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now