Jump to content

Custom Perk Modding Help


Recommended Posts

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!

546456456.png

Link to comment
Share on other sites

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

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

@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 by Yakuzashi
messy mess
Link to comment
Share on other sites

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 by FabledFerret
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...