Leothenewguy Posted November 5, 2016 Share Posted November 5, 2016 So I ave been trying to give one of my custom characters the ability to affect other players sanity. It's not my first time making a character, but I have never made one that influenced other players. His perk should in the end be: Other players gain a little bit of sanity at night from being close to him. At day time their sanity should slightly drain from being too close to him. inst.components.sanityaura.aura = -TUNING.SANITYAURA_SMALL I tried using this from the Evil Flower but it kept crashing my game. While going through the forums here I found this one: But the code they used for the health regeneration (also including sanity) didn't work for me as soon as I tried to add the day and night bit. If anyone has an idea how I could solve my issue I'd be really grateful! Every little bit help, maybe I could help you with some art things in return. Link to comment https://forums.kleientertainment.com/forums/topic/71435-custom-character-sanity-aura-perk-help/ Share on other sites More sharing options...
. . . Posted November 5, 2016 Share Posted November 5, 2016 What would the sanity aura be in dusk time? Link to comment https://forums.kleientertainment.com/forums/topic/71435-custom-character-sanity-aura-perk-help/#findComment-833905 Share on other sites More sharing options...
. . . Posted November 6, 2016 Share Posted November 6, 2016 (edited) I think this would work, tell me if it doesn't or it crashes! outside master_postinit of YOURCHARACTER.lua Spoiler local function custom_sanity_aura(inst, phase) local x, y, z = inst.Transform:GetWorldPosition() local players = FindPlayersInRange(x, y, z, (8), true) -- "8" = Distance between you & others. if phase == "day" then if inst:HasTag("playerghost") or inst.components.health:IsDead() then return end -- Don't do anything if dead. if inst.sanity_aura_night == true then -- If any other sanity auras are in effect cancel them. inst.sanity_aura_night = nil inst.sanity_aura_night:Cancel() elseif sanity_aura_dusk == true then inst.sanity_aura_dusk = nil inst.sanity_aura_dusk:Cancel() end inst.sanity_aura_morning = true inst.sanity_aura_morning = inst:DoPeriodicTask(1, function() if inst:HasTag("playerghost") or inst.components.health:IsDead() then return end -- Don't do anything if dead. for _, v in pairs(players) do if (v~=inst) and (v.components and v.components.sanity) and v.components.health and not v.components.health:IsDead() then v.components.sanity:DoDelta(-.5) end end end) elseif phase == "night" then if inst:HasTag("playerghost") then return end if inst.sanity_aura_morning == true then -- If any other sanity auras are in effect cancel them. inst.sanity_aura_morning = nil inst.sanity_aura_morning:Cancel() elseif sanity_aura_dusk == true then inst.sanity_aura_dusk = nil inst.sanity_aura_dusk:Cancel() end inst.sanity_aura_night = true inst.sanity_aura_night = inst:DoPeriodicTask(1, function() if inst:HasTag("playerghost") or inst.components.health:IsDead() then return end -- Don't do anything if dead. for _, v in pairs(players) do if (v~=inst) and (v.components and v.components.sanity) and v.components.health and not v.components.health:IsDead() then v.components.sanity:DoDelta(.5) end end end) elseif phase == "dusk" then if inst:HasTag("playerghost") then return end if inst.sanity_aura_morning == true then -- If any other sanity auras are in effect cancel them. inst.sanity_aura_morning = nil inst.sanity_aura_morning:Cancel() elseif sanity_aura_night == true then inst.sanity_aura_night = nil inst.sanity_aura_night:Cancel() end inst.sanity_aura_dusk = true inst.sanity_aura_dusk = inst:DoPeriodicTask(1, function() if inst:HasTag("playerghost") or inst.components.health:IsDead() then return end -- Don't do anything if dead. for _, v in pairs(players) do if (v~=inst) and (v.components and v.components.sanity) and v.components.health and not v.components.health:IsDead() then v.components.sanity:DoDelta(.1) end end end) end end inside master_postinit of YOURCHARACTER.lua inst:WatchWorldState("phase", custom_sanity_aura) Hopefully this works for you ! @Leothenewguy You'd also add this into YOURCHARACTER.lua is master_postinit Spoiler inst:DoTaskInTime(1, function() if TheWorld.state.isnight then -- Login while night. if inst:HasTag("playerghost") or inst.components.health:IsDead() then return end -- Don't do anything if ded. inst.sanity_aura_night = true inst.sanity_aura_night = inst:DoPeriodicTask(1, function() if inst:HasTag("playerghost") or inst.components.health:IsDead() then return end -- Don't do anything if dead. for _, v in pairs(players) do if (v~=inst) and (v.components and v.components.sanity) and v.components.health and not v.components.health:IsDead() then v.components.sanity:DoDelta(.5) end end end) elseif TheWorld.state.isdusk then -- Login while dusk. if inst:HasTag("playerghost") or inst.components.health:IsDead() then return end -- Don't do anything if ded. inst.sanity_aura_dusk = true inst.sanity_aura_dusk = inst:DoPeriodicTask(1, function() if inst:HasTag("playerghost") or inst.components.health:IsDead() then return end -- Don't do anything if dead. for _, v in pairs(players) do if (v~=inst) and (v.components and v.components.sanity) and v.components.health and not v.components.health:IsDead() then v.components.sanity:DoDelta(.1) end end end) elseif TheWorld.state.isday then -- Login while day. if inst:HasTag("playerghost") or inst.components.health:IsDead() then return end -- Don't do anything if ded. inst.sanity_aura_morning = true inst.sanity_aura_morning = inst:DoPeriodicTask(1, function() if inst:HasTag("playerghost") or inst.components.health:IsDead() then return end -- Don't do anything if dead. for _, v in pairs(players) do if (v~=inst) and (v.components and v.components.sanity) and v.components.health and not v.components.health:IsDead() then v.components.sanity:DoDelta(-.5) end end end) end end) Edited November 6, 2016 by SuperDavid Link to comment https://forums.kleientertainment.com/forums/topic/71435-custom-character-sanity-aura-perk-help/#findComment-833908 Share on other sites More sharing options...
Leothenewguy Posted November 6, 2016 Author Share Posted November 6, 2016 (edited) Hey @SuperDavid! Thank you so much for the help. The only issue is as soon as I add the third code the game will let me get to the point that I spawn and then I get an error that "player" is not defined. Without the third one it runs so I am certain that it has to do with that one. It was correct to add it underneath the master_postinit so it looks like this local master_postinit = function(inst) inst:DoTaskInTime(1, function() if TheWorld.state.isnight then -- Login while night. if inst:HasTag("playerghost") or inst.components.health:IsDead() then return end -- Don't do anything if ded. inst.sanity_aura_night = true inst.sanity_aura_night = inst:DoPeriodicTask(1, function() if inst:HasTag("playerghost") or inst.components.health:IsDead() then return end -- Don't do anything if dead. for _, v in pairs(players) do if (v~=inst) and (v.components and v.components.sanity) and v.components.health and not v.components.health:IsDead() then v.components.sanity:DoDelta(.5) end end end) elseif TheWorld.state.isdusk then -- Login while dusk. if inst:HasTag("playerghost") or inst.components.health:IsDead() then return end -- Don't do anything if ded. inst.sanity_aura_dusk = true inst.sanity_aura_dusk = inst:DoPeriodicTask(1, function() if inst:HasTag("playerghost") or inst.components.health:IsDead() then return end -- Don't do anything if dead. for _, v in pairs(players) do if (v~=inst) and (v.components and v.components.sanity) and v.components.health and not v.components.health:IsDead() then v.components.sanity:DoDelta(.1) end end end) elseif TheWorld.state.isday then -- Login while day. if inst:HasTag("playerghost") or inst.components.health:IsDead() then return end -- Don't do anything if ded. inst.sanity_aura_morning = true inst.sanity_aura_morning = inst:DoPeriodicTask(1, function() if inst:HasTag("playerghost") or inst.components.health:IsDead() then return end -- Don't do anything if dead. for _, v in pairs(players) do if (v~=inst) and (v.components and v.components.sanity) and v.components.health and not v.components.health:IsDead() then v.components.sanity:DoDelta(-.5) end end end) end end) and then continues on with the stats and so on. Do you maybe know how to fix it? Edited November 6, 2016 by Leothenewguy Link to comment https://forums.kleientertainment.com/forums/topic/71435-custom-character-sanity-aura-perk-help/#findComment-833923 Share on other sites More sharing options...
. . . Posted November 6, 2016 Share Posted November 6, 2016 Can you maybe post me your entire mod then I can do the stuff, I could fix it much faster then Link to comment https://forums.kleientertainment.com/forums/topic/71435-custom-character-sanity-aura-perk-help/#findComment-833927 Share on other sites More sharing options...
Leothenewguy Posted November 6, 2016 Author Share Posted November 6, 2016 Sure if you could tell me how to do that I am actively using this page for the first time Should I just copy the entire prefab code or can I somehow upload the Mod file? Link to comment https://forums.kleientertainment.com/forums/topic/71435-custom-character-sanity-aura-perk-help/#findComment-833930 Share on other sites More sharing options...
. . . Posted November 6, 2016 Share Posted November 6, 2016 Just now, Leothenewguy said: Sure if you could tell me how to do that I am actively using this page for the first time Should I just copy the entire prefab code or can I somehow upload the Mod file? Create a zip folder on your desktop then copy your entire mod folder into the zip then attach the file in a post here !!! Link to comment https://forums.kleientertainment.com/forums/topic/71435-custom-character-sanity-aura-perk-help/#findComment-833931 Share on other sites More sharing options...
Leothenewguy Posted November 6, 2016 Author Share Posted November 6, 2016 (edited) There you go sorry for the hold up my Pc decided to take ages to zip it. It 's still at the beginning so no own art yet Thanks again for bothering with me :3 Edit: Oh and I kept your codes in Jack.rar Edited November 6, 2016 by Leothenewguy Link to comment https://forums.kleientertainment.com/forums/topic/71435-custom-character-sanity-aura-perk-help/#findComment-833944 Share on other sites More sharing options...
. . . Posted November 6, 2016 Share Posted November 6, 2016 (edited) @Leothenewguy I think I added a positive sanity aura for night, negative for day & nothing for dusk. Sorry it took so long I was fixing crashes.. Edited November 6, 2016 by SuperDavid Link to comment https://forums.kleientertainment.com/forums/topic/71435-custom-character-sanity-aura-perk-help/#findComment-833993 Share on other sites More sharing options...
Leothenewguy Posted November 6, 2016 Author Share Posted November 6, 2016 Thank youuu so much! Don't worry about taking long I have been chewing on this for hours. I'm really grateful for your help. I can't believe that it finally works. If I can help you with anything just let me know Link to comment https://forums.kleientertainment.com/forums/topic/71435-custom-character-sanity-aura-perk-help/#findComment-834000 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