Jump to content

Help with adding sound to function


Quincy

Recommended Posts

Hi all,

 

Currently trying to learn how the whole modding dealio works, and am struggling to understand how to add a sound into a function. I have a sound attached to the recipe (i.e. the crafting phase) which works fine, but I would like a separate sound to play at the end of the crafting action (the OnCreate), depending on whether the user succeeded or failed in the craft. Similar to how you get a wood breaking sound if you fail to pick up a crate with carpentry, but I struggled to find that to reference.

 

The current function is below - basically rolls to see if the user succeeds or fails in the craft, and rolls some flavour text options for each.

 

Could anyone help with advising on:

  • How to add a custom sound that plays solely for the player based on success (GemChance>=5), or failure?
  • Where to place these custom sounds in the mod file to permit the function to locate/use them?

 

 
function Recipe.OnCreate.GemSuccess(items, result, player)
    local GemChance = ZombRand(1,11);
    local GemWords = ZombRand(1,7);
    
    if GemChance>=5 and GemWords>=1 and GemWords<=2 then
        player:getInventory():AddItem("Base.AWKGemstone");
        player:Say(getText("IGUI_GemSucceed1"));
    elseif GemChance>=5 and GemWords>=3 and GemWords<=4 then
        player:getInventory():AddItem("Base.AWKGemstone");
        player:Say(getText("IGUI_GemSucceed2"));
    elseif GemChance>=5 and GemWords>=5 then
        player:getInventory():AddItem("Base.AWKGemstone");
        player:Say(getText("IGUI_GemSucceed3"));
    elseif
        GemWords<=3 then
        player:Say(getText("IGUI_GemFail1"));
    elseif
        GemWords>=4 and GemWords<=5 then
        player:Say(getText("IGUI_GemFail2"));
    elseif
        GemWords==6 then
        player:Say(getText("IGUI_GemFail3"));
    end
end

 

Cheers,

 

Quincy

Edited by Quincy
Link to comment
Share on other sites

Cheers Hugo,

 

Ended up stumbling my way into - getSoundManager():PlaySound("GemGet", false, 0.5); - which is working.

 

Can confirm dropping the audio files into media/sound/ works a treat.

 

Appreciate the heads up on the Discord, have signed up there :)

Link to comment
Share on other sites

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