kump11r Posted December 13, 2021 Share Posted December 13, 2021 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 ^^ Link to comment https://forums.kleientertainment.com/forums/topic/136117-can-someone-explain-these-for-me/ Share on other sites More sharing options...
CarlZalph Posted December 14, 2021 Share Posted December 14, 2021 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. 2 Link to comment https://forums.kleientertainment.com/forums/topic/136117-can-someone-explain-these-for-me/#findComment-1522846 Share on other sites More sharing options...
kump11r Posted December 14, 2021 Author Share Posted December 14, 2021 (edited) 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 December 14, 2021 by kump11r Link to comment https://forums.kleientertainment.com/forums/topic/136117-can-someone-explain-these-for-me/#findComment-1522892 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