FabledFerret Posted December 8, 2020 Share Posted December 8, 2020 Hello, I'm new to modding and programming and I was following the custom character guide by Corgi. I had an idea for a custom perk where the character would get a sanity regen bonus when they are alone/no characters or creatures are nearby. I found the code for Willow's sanity boost with fire but I don't know how to convert that into what I want or if that would even be an efficient way of doing it. Any help would be appreciated! Link to comment Share on other sites More sharing options...
FabledFerret Posted December 8, 2020 Author Share Posted December 8, 2020 Not sure what I'm doing but after a couple of hours of digging I came up with this inst:DoPeriodicTask(1.0, function(inst) if inst.components.health == 0 or inst:HasTag("playerghost") then return end local x,y,z = inst.Transform:GetWorldPosition() local players = TheSim:FindEntities(x, y, z, 10, {"character", "player"}, {"INLIMBO", "playerghost"}, nil) local count = 0 for _ in pairs(player) do count = count + 1 end if count < 1 then inst:AddComponent("sanityaura") inst.components.sanityaura.aura = TUNING.SANITYAURA_SMALL end end) However, the character doesn't seem to be getting a sanity bonus when I test it in game. Any suggestions would be helpful Link to comment Share on other sites More sharing options...
DecDuck Posted December 9, 2020 Share Posted December 9, 2020 First, I'm not sure what TheSim:FindEntities(x, y, z, 10, {"character", "player"}, {"INLIMBO", "playerghost"}, nil) does, but it might be finding EVERYTHING in the world, and that may be a problem, but I know this is a problem: inst:AddComponent("sanityaura") inst.components.sanityaura.aura = TUNING.SANITYAURA_SMALL You need to use dapperness. This code would make any players standing near you get sanity, but dapperness is for yourself. I like to think of dapperness as your own personal sanity aura. P.S. look in Maxwell's code to see how to give a player dapperness. Link to comment Share on other sites More sharing options...
penguin0616 Posted December 9, 2020 Share Posted December 9, 2020 @decduck3 The first line finds all entities in a circle of 10 units with the center at x, y, z. The entities must have a character or player tag, and they cannot have an INLIMBO or playerghost tag. 1 Link to comment Share on other sites More sharing options...
DecDuck Posted December 9, 2020 Share Posted December 9, 2020 Oh sorry, didn't see. Link to comment Share on other sites More sharing options...
Yakuzashi Posted December 9, 2020 Share Posted December 9, 2020 (edited) @FabledFerret Alright everything goes into [your.character.name].lua Quote Somewhere above common_postinit and master_postinit local sanityvalue = 5 --- how much sanity you want per tick local tickinterval = 2 -- how often sanity tick occurs local function bonus(inst) if inst:HasTag("playerghost") then return end if inst.components.health:IsDead() then return end local x,y,z = inst.Transform:GetWorldPosition() local pt = inst:GetPosition() local range = 10 -- range of ability local tags = {"character"} --- don't move that local canthavetags = {"your.character's.tag"} --- change this lil tag local check = TheSim:FindEntities(pt.x,pt.y,pt.z,range,tags,canthavetags) for _,ent in ipairs(check) do if not ent.components.health:IsDead() then return end end inst.components.sanity:DoDelta(sanityvalue) end Quote Inside master_postinit inst:DoPeriodicTask(tickinterval, bonus, nil, inst) --- passive sanity gain Quote Inside common_postinit inst:AddTag("your.character's.tag") You can change "your.character's.tag" into something else if you want. You can also customize tickinterval and sanityvalueIn case you need explanation just let me know. Cheers! Edited December 9, 2020 by Yakuzashi messy mess Link to comment Share on other sites More sharing options...
FabledFerret Posted December 15, 2020 Author Share Posted December 15, 2020 (edited) On 12/9/2020 at 12:38 PM, Yakuzashi said: @FabledFerret Alright everything goes into [your.character.name].lua local sanityvalue = 5 --- how much sanity you want per tick local tickinterval = 2 -- how often sanity tick occurs local function bonus(inst) if inst:HasTag("playerghost") then return end if inst.components.health:IsDead() then return end local x,y,z = inst.Transform:GetWorldPosition() local pt = inst:GetPosition() local range = 10 -- range of ability local tags = {"character"} --- don't move that local canthavetags = {"your.character's.tag"} --- change this lil tag local check = TheSim:FindEntities(pt.x,pt.y,pt.z,range,tags,canthavetags) for _,ent in ipairs(check) do if not ent.components.health:IsDead() then return end end inst.components.sanity:DoDelta(sanityvalue) end You can change "your.character's.tag" into something else if you want. You can also customize tickinterval and sanityvalueIn case you need explanation just let me know. Cheers! @YakuzashiThank you so much for your reply, going to try it now! Edited December 15, 2020 by FabledFerret Link to comment Share on other sites More sharing options...
FabledFerret Posted December 16, 2020 Author Share Posted December 16, 2020 @Yakuzashi Thank you so much this worked. I had been going crazy going through all the forums trying to get something to work. Thank you again! 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