Breeziy Posted November 29, 2019 Share Posted November 29, 2019 (edited) Hi, guys! I'm trying to make a character that attracts birds, similar to the feather hat. local function feather_equip(inst, owner) onequip(inst, owner) local attractor = owner.components.birdattractor if attractor then attractor.spawnmodifier:SetModifier(inst, TUNING.BIRD_SPAWN_MAXDELTA_FEATHERHAT, "maxbirds") attractor.spawnmodifier:SetModifier(inst, TUNING.BIRD_SPAWN_DELAYDELTA_FEATHERHAT.MIN, "mindelay") attractor.spawnmodifier:SetModifier(inst, TUNING.BIRD_SPAWN_DELAYDELTA_FEATHERHAT.MAX, "maxdelay") local birdspawner = TheWorld.components.birdspawner if birdspawner ~= nil then birdspawner:ToggleUpdate(true) end end end This is the feather hat code, but since it calls for a function that equips something (in this case the hat), I'm not sure how to modify it so it's just a component in the character's prefab. Additionally, is there anyway to make birds not fly away, but JUST birds? I know I can remove the scarytoprey tag, but that includes other tiny creatures. That's not as important a perk, though. Thanks so much in advance :). Edited November 30, 2019 by Breeziy Link to comment Share on other sites More sharing options...
Breeziy Posted November 29, 2019 Author Share Posted November 29, 2019 I'm thinking I'll have to AddComponent("birdattractor"), but I'm still not sure what sort of function or line to write the TUNING values into . Link to comment Share on other sites More sharing options...
Breeziy Posted November 30, 2019 Author Share Posted November 30, 2019 local SourceModifierList = require "util/sourcemodifierlist" local BirdAttractor = Class(function(self, inst) self.inst = inst -- This modifier is using multple keys, always call CalculateModifierFromKey() with "maxbirds", "mindelay" or "maxdelay" self.spawnmodifier = SourceModifierList(inst, 0, SourceModifierList.additive) end) function BirdAttractor:GetDebugString() local str = string.format("maxbirds:%d, mindelay:%d, maxdelay:%d", self.spawnmodifier:CalculateModifierFromKey("maxbirds"), self.spawnmodifier:CalculateModifierFromKey("mindelay"), self.spawnmodifier:CalculateModifierFromKey("maxdelay")) return str end return BirdAttractor This is the code for the birdattractor component too, if needed. Again, I figure I can go about adding the component but I'm not sure how to write up the modifiers. Link to comment Share on other sites More sharing options...
Breeziy Posted November 30, 2019 Author Share Posted November 30, 2019 Update: Close, but not quite. local birdspawner = TheWorld.components.birdspawner if not TheWorld.ismastersim then return inst end if birdspawner ~= nil then birdspawner:SetSpawnTimes({min=2, max=5}) birdspawner:SetMaxBirds(15) end I found this to put into the character's prefab under master_postinit, and it seems to get the job done but SetSpawnTimes and SetMaxBirds are both deprecated. The console/log says "use birdattractor.spawnmodifier" but I don't know HOW, as if I just replace birdspawner then it comes back with telling me birdattractor is not declared :x. I'm close, I just don't quite understand how to accurately write birdattractor.spawnmodifer up.. I tried to find it through the script files but there's no other instance of this particular line being used besides print "DEPRECATED: SetSpawnTimes() in birdspawner.lua, use birdattractor.spawnmodifier instead" Link to comment Share on other sites More sharing options...
Ultroman Posted December 8, 2019 Share Posted December 8, 2019 (edited) All players already have the birdattractor component. You're close, but since you're reusing the unique keys from the Feather Hat, you'll clash with it. Putting this at the bottom of your character's master_postinit() or fn() should do it: local attractor = inst.components.birdattractor if not attractor then inst:AddComponent("birdattractor") attractor = inst.components.birdattractor end if attractor then attractor.spawnmodifier:SetModifier(inst, TUNING.BIRD_SPAWN_MAXDELTA_FEATHERHAT, "MyCharacterNameMaxBirds") attractor.spawnmodifier:SetModifier(inst, TUNING.BIRD_SPAWN_DELAYDELTA_FEATHERHAT.MIN, "MyCharacterNameMinDelay") attractor.spawnmodifier:SetModifier(inst, TUNING.BIRD_SPAWN_DELAYDELTA_FEATHERHAT.MAX, "MyCharacterNameMaxDelay") local birdspawner = TheWorld.components.birdspawner if birdspawner ~= nil then birdspawner:ToggleUpdate(true) end end Just edited the code. Edited December 8, 2019 by Ultroman Link to comment Share on other sites More sharing options...
Breeziy Posted December 12, 2019 Author Share Posted December 12, 2019 My hero! I'll test the code a little later, but I super appreciate it :). I hate to use a workaround if it's deprecated, as it just feels better to be up to date with the coding lingo. Thank you again so much! Link to comment 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