RadiantRoma Posted March 29, 2017 Share Posted March 29, 2017 (edited) My character has mottephobia, AKA fear of butterflies and moths! I have it so they lose sanity when in a radius of a butterfly, but I wanted there to be a chance of them announcing when they get near a butterfly. I got everything right, except I probably don't have the math.random() done right, because when the chance < 0.50, they never say it. But when I change it to chance < 0.75, they say it every time. Here's the code. local chance = math.random() --near butterfly inst:DoPeriodicTask( 0.1, function(inst) local x, y, z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, 4.0, {"butterfly"}) if #ents > 0 then if inst.wisniowski_mottephobia == nil then if chance < 0.50 then inst.components.talker:Say(GetString(inst.prefab, "ANNOUNCE_BUTTERFLY")) inst.components.sanity.dapperness = (TUNING.DAPPERNESS_LARGE * -1) inst.wisniowski_mottephobia = true else inst.components.sanity.dapperness = (TUNING.DAPPERNESS_LARGE * -1) inst.wisniowski_mottephobia = true end end else if inst.wisniowski_mottephobia ~= nil then inst.components.sanity.dapperness = (TUNING.DAPPERNESS_SMALL * -1) inst.wisniowski_mottephobia = nil end end end ) Any help is appreciated! Edited March 29, 2017 by Cherryzion Link to comment Share on other sites More sharing options...
Serpens Posted March 29, 2017 Share Posted March 29, 2017 (edited) replace "chance < 0.50" with "math.random() < 0.50" in your code (and remove local chance...above) The way it is at the moment chance is set one time, so it will be always eg. 0.3, without changing. The result is always your text or never. Edited March 29, 2017 by Serpens Link to comment Share on other sites More sharing options...
RadiantRoma Posted March 29, 2017 Author Share Posted March 29, 2017 12 minutes ago, Serpens said: replace "chance < 0.50" with "math.random() < 0.50" in your code (and remove local chance...above) The way it is at the moment chance is set one time, so it will be always eg. 0.3, without changing. The result is always your text or never. Works! Thanks a ton! Link to comment Share on other sites More sharing options...
. . . Posted March 30, 2017 Share Posted March 30, 2017 Wouldn't calling this code every .1 seconds cause lag or something? Just wonderin' ... Link to comment Share on other sites More sharing options...
RadiantRoma Posted March 30, 2017 Author Share Posted March 30, 2017 10 hours ago, SuperDavid said: Wouldn't calling this code every .1 seconds cause lag or something? Just wonderin' ... From what I can tell, it doesn't. All it's doing anyway is adding a couple lines of code. But if you know another way that undeniably is impossible to cause lag, I could try it out! 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