Jump to content

Recommended Posts

I am trying to make a character that gains sanity when around goats and I found a code, and it worked. But I want to increase the sanity gain, yet I can't really understand the codes so I don't know what to change. 

local function sanityfn(inst)
    local x, y, z = inst.Transform:GetWorldPosition()
    local delta = 0
    local ents = TheSim:FindEntities(x, y, z, 20, {"lightninggoat"})

    for k, v in pairs(ents) do
        if v ~= inst then
            local distsq = math.max(inst:GetDistanceSqToInst(v), 1)
            -- Handle Sanity
            if distsq < 50 then 
                delta = .2
            elseif distsq < 200 then
                delta = .1
            end
        end
    end
    return delta
end

 

What I mainly don't know are; delta, distsq and k, v meanings.. Thanks in advance ^^

5 hours ago, kump11r said:

What I mainly don't know are; delta, distsq and k, v meanings

'delta' : Rate of change of sanity, higher is more sanity per time slice.

'distsq' : Distance squared to the target entity found, clamped to be at least 1.0 or greater.

'k' / 'v' : In LUA, these are commonly used in a for-pairs iteration.  "for k, v in pairs(sometable) do end" being the boilerplate.  They represent k[ey] and v[alue] of the table.  I'd recommend reading up on LUA's API reference or some tutorials to get more familiar with LUA.

 

In your case you'd want to increase the delta values being assigned to increase the sanity gain rate.

  • Like 2
6 hours ago, CarlZalph said:

'delta' : Rate of change of sanity, higher is more sanity per time slice.

'distsq' : Distance squared to the target entity found, clamped to be at least 1.0 or greater.

'k' / 'v' : In LUA, these are commonly used in a for-pairs iteration.  "for k, v in pairs(sometable) do end" being the boilerplate.  They represent k[ey] and v[alue] of the table.  I'd recommend reading up on LUA's API reference or some tutorials to get more familiar with LUA.

 

In your case you'd want to increase the delta values being assigned to increase the sanity gain rate.

Thank you!!! This helped more than it should have!!!

Edited by kump11r

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...