Jump to content

How do I make a character lose sanity and become groggy around fires?

Recommended Posts

(first of all sorry for my english its not my main language) I'm using this for gain or lose sanity near critters and player you can try


local function fire_aura(inst)
  	local x, y, z = inst.Transform:GetWorldPostion()
  	local delta = 0
  	local ents = TheSim:FindEntities(x, y, z, 20, {"tag1", "tag2", "tag3",...}) --like player or campfire
  	local bonus_sanity = nil
  	local distsq = nil
  		local totalDelta = nil
  	for k, v ,n pairs(ents) do
    		if v ~= inst then
      			if v.prefab == "tag1" then
        			bonus_sanity = =TUNING.SANITYAURA_X --X = SMALL OR MEDIUM OR LARGE. If you want to lose sanity then put (-) like -TUNING.SANITYAURA_X
        			distsq = math.max(inst:GetDistanceSqToInst(v), 1)
        			delta = delta + bonus_sanity / distsq
    	totalDelta = totalDelta + delta
  	if #ents > 0 then
    	totalDelta = totalDelta / #ents
    	totalDelta = 0
  return totalDelta

master code

inst.components.sanity.custom_rate_fn = fire_aura
inst:DoPeriodicTask(1, fire_aura)

i'm not the one who made that code someone gave it to me and i don't remember who was he/she but let me know if there is any problem i can try to fix it. (and im sorry if the owner does not want me to publish it just pm me and i'll delete it asap)

Link to comment
Share on other sites

As for the grogginess, this is actually surprisingly simple. All you have to do at add a groggy tag to the player like this: player:AddTag("groggy"). Of course you should replace "player" with however you reference the player in your context. I tried to figure out a more conventional way to make the player walk slower, but you can literally just use c_speedmult(.6). c_speedmult() is the console command that takes a multiplier and alters the walking speed. (btw the groggy walking speed is usually between .4 to .6 as seen in tuning.lua. You can choose whatever.) When you go out of range of a fire, just remove the tag and then do c_speedmult(1) to make the walking speed normal.

When it comes to actually detecting the fire (and, in turn, if it's lit), that might be more difficult. It would be ideal if you did not use a forever loop using TheSim:FindEntities since that would destroy performance (as well as being a bad coding practice), so you might want to check out the plain aura component or the playerprox component or check out some other mods that involve ranges. You might be able to create a new type of aura, but I don't know, I haven't tried it. I hope this points you in the right direction, ask me anything if you're confused by what I said...

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

  • Create New...