Augustusc Posted February 9, 2016 Share Posted February 9, 2016 Hello! i have this problem with this code. I had to frankenstein this, so i expected problems. the code is -- Spawn poop when sanity is low local function OnSanityDelta(inst, data) if data.newpercent == .20 then inst.components.talker:Say("AHH! I just saw something just jumped at me!") SpawnPrefab("poop").Transform:SetPosition(inst.Transform:GetWorldPosition()) end end Before you say it. yes, it is a silly piece of code. anyway, the problem. this code only seems to work when i set my sanity to .20 percent with the console command "c_setsanity(0.20)". if i set my sanity to .21 and let it naturally fall down, then the code doesn't run. if i change the code to this -- Spawn poop when sanity is low local function OnSanityDelta(inst, data) if data.newpercent <= .20 then inst.components.talker:Say("AHH! I just saw something just jumped at me!") SpawnPrefab("poop").Transform:SetPosition(inst.Transform:GetWorldPosition()) end end Then at .20, he starts dropping poop each tick. in the end, all i want is at .20 sanity my character says that and drops a single poop. Thanks in advance Link to comment Share on other sites More sharing options...
zUsername Posted February 9, 2016 Share Posted February 9, 2016 I took this code from Player Poop mod, so hope this code will help you/ inst.lastpooptime = nil -- put this to master_postinit local function TimeSinceLastPoop() if inst.lastpooptime ~= nil then --checks if lastpooptime is not nil, which means you have pooped sometime before return GetTime() - inst.lastpooptime end end local function OnSanityDelta(inst, data) if data.newpercent <= .20 then if inst.lastpooptime == nil or TimeSinceLastPoop() > TUNING.SEG_TIME*4 then inst.lastpooptime = GetTime() inst.components.talker:Say("AHH! I just saw something just jumped at me!") SpawnPrefab("poop").Transform:SetPosition(inst.Transform:GetWorldPosition()) end end end Link to comment Share on other sites More sharing options...
Augustusc Posted February 9, 2016 Author Share Posted February 9, 2016 so i looked into the mod you said you found the code from. it is a singleplayer mod for DS. is there a way i can make it so only a single mod character does this? Link to comment Share on other sites More sharing options...
zUsername Posted February 9, 2016 Share Posted February 9, 2016 It's will work on DST. Give a try. Link to comment Share on other sites More sharing options...
Augustusc Posted February 9, 2016 Author Share Posted February 9, 2016 It caused a crash. i put it in the character.lua file, should i have put it in modmain.lua? Link to comment Share on other sites More sharing options...
zUsername Posted February 9, 2016 Share Posted February 9, 2016 Can you give me a log file and character.lua file ? Link to comment Share on other sites More sharing options...
Augustusc Posted February 9, 2016 Author Share Posted February 9, 2016 There you go! I hope i sent them right. jeremiah.lua log.txt Link to comment Share on other sites More sharing options...
zUsername Posted February 9, 2016 Share Posted February 9, 2016 local function TimeSinceLastPoop(inst) if inst.lastpooptime ~= nil then --checks if lastpooptime is not nil, which means you have pooped sometime before return GetTime() - inst.lastpooptime end return 0 end -- Spawn poop when sanity is low (basicly crap your pants) local function OnSanityDelta(inst, data) if data.newpercent <= .20 then if inst.lastpooptime == nil or TimeSinceLastPoop(inst) > TUNING.SEG_TIME*4 then inst.lastpooptime = GetTime() inst.components.talker:Say("AHH! I just saw something just jumped at me!") SpawnPrefab("poop").Transform:SetPosition(inst.Transform:GetWorldPosition()) end end end local master_postinit = function(inst) inst.lastpooptime = nil inst:ListenForEvent("sanitydelta", OnSanityDelta) end Tested. Link to comment Share on other sites More sharing options...
Augustusc Posted February 9, 2016 Author Share Posted February 9, 2016 (edited) It works! Thanks for coming through with me again! you're a hero! EDIT: one question. how long does the game take before it allows another poop to happen? and what would i do to make it shorter or longer Edited February 9, 2016 by Augustusc because a question came up Link to comment Share on other sites More sharing options...
zUsername Posted February 10, 2016 Share Posted February 10, 2016 4 hours ago, Augustusc said: It works! Thanks for coming through with me again! you're a hero! EDIT: one question. how long does the game take before it allows another poop to happen? and what would i do to make it shorter or longer You can print(TimeLastSincePoop(inst)) when TimeLastSincePoop(inst) = 120 Its will poop 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