Jump to content

[Solved] How to set something to increase ovetime?


Recommended Posts

local function RegenFn(inst)
if inst:HasTag("playerghost") then return end
if inst.transformed then

inst:AddTag("canmove")
inst:RemoveTag("nomove")
inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED)
inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED)
inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 0.75)
inst.components.combat.damagemultiplier = 1
inst.components.sanity.dapperness = TUNING.DAPPERNESS_TINY *0.01

else

inst:AddTag("nomove")
inst:RemoveTag("canmove")
inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 0.00)
inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 0.00)
inst.components.temperature.inherentinsulation = 120
inst.components.temperature.inherentsummerinsulation = 60
inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 0.25)

inst:DoPeriodicTask(15, ????????????

inst.components.sanity.dapperness = TUNING.DAPPERNESS_HUGE * Z
end

 

I want to have number Z increases by 1 ever 15 seconds but so far can't figure it out.

Edited by Anstarveo
Link to comment
Share on other sites

if you found a solution already, do not delte your post, just post the solution, so others can learn from it ;)

And yes, it should be "DoPeriodicTask"
If you don't know how to use the function, simply do a search for it in all the game files. There you will have tons of examples ;)
And you will also see where it is defined, in entityscript.lua:
EntityScript:DoPeriodicTask(time, fn, initialdelay, ...)

Here you can see how to use notepad++ to serach all lua scripts at once:

 

Link to comment
Share on other sites

I couldn't find my answer in the game files, because the answer is too simple. I found it out the hard way   >_<

Here is my solution, inside (your mod name).lua put this:

       inst:DoPeriodicTask(1, sanRe, 15)

inside:

       local master_postinit = function(inst)

and put this:

 

local zzz = -1

local function sanRe(inst)

    if inst:HasTag("nomove") then
        zzz = zzz + 1
        inst.components.sanity.dapperness = TUNING.DAPPERNESS_TINY * (zzz/2)
    else
        inst.components.sanity.dapperness = 0
        zzz = -1
    end
end

 

into (your mod name).lua

 

The "nomove" is my custom tag. Purpose of the script: the longer I stay in "nomove" state, the faster my sanity will regen, take 15s to start.

Edited by Anstarveo
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...