Jump to content

how to make a item play sound randomly and im having troble getting birdattractor working in my mod im not sure


Recommended Posts

hello just wondering is there a way to make a item randomly play a sound file? (im trying to google how to add custom sounds but im only finding how to do it for modded charters not items) 

 

and in 1 of the items in my mod it dosent seem to be doing what its ment to and im at the point of giving up trying to fix it on my own

what it is ment to do is attract birds just like wearing a feather hat ...only when its on the ground not in your inventory

https://github.com/monkeybee11/monkey-mod/blob/master/recipe mod/scripts/prefabs/birdy.lua

that is a link to the lua script on my github

im wondering if its bc the birdattracter component is in DST not my mod if thats the case is there a way to make it use the file from DST?  

or is that not the problem at all?

Edited by monkeybee
Link to comment
Share on other sites

TheWorld doesn't have a birdattractor component, it's attached to the players instead.

Similarly the birdspawner component is written with the idea that only players will make birds spawn, which makes your job here somewhat difficult.

Some approaches that would work:

  1. Hook into birdspawner and get it to recognize other things (this looks pretty difficult just glancing at the component)
  2. Have birdy detect nearby players (e.g. with playerprox), and modify their birdattractor
  3. Override birdattractor.spawnmodifier.CalculateModifierFromKey to look for nearby birdys, and return a higher value if so
Link to comment
Share on other sites

ok problem solved now ive just removed the bird attractor compleatly and replaced it with 
 

local function toground(inst) -- this makes birds spawn as offten as wearing a feather hat when on the ground
	local birdspawner = TheWorld.components.birdspawner
    if not TheWorld.ismastersim then
            return inst
    end
    if birdspawner ~= nil then
            birdspawner:SetSpawnTimes({min=2, max=10})
            birdspawner:SetMaxBirds(7)
    end
end

local function topocket(inst) -- this makes the spawn rate return to normal when birdy is picked up
	local birdspawner = TheWorld.components.birdspawner
    if not TheWorld.ismastersim then
            return inst
    end
    if birdspawner ~= nil then
            birdspawner:SetSpawnTimes({min=5, max=15})
            birdspawner:SetMaxBirds(4)
    end
end

so now when its on the ground birdy is going to spawn birds

only down side is now im getting 

[00:00:40]: DEPRECATED: SetSpawnTimes() in birdspawner.lua, use birdattractor.spawnmodifier instead    
[00:00:40]: DEPRECATED: SetMaxBirds() in birdspawner.lua, use birdattractor.spawnmodifier instead    

 

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
 Share

×
  • Create New...