Jump to content

Recommended Posts

Hey Guys, i'm making a character, and when he eat a seed(just for test), he gain speed move, but i can't set a time for the buff, he gain infinite speed, and i want a temporary gain, i can't make the time in buff, i try to use the looping "for" and "while" but don't work in DST

 

In Cmd works fine the looping making a timer, but in DST don't, here's my code:

 

i try use like this in cmd using just .lua :
 

-- This make the count, making 20sec in the cmd, if u guys wanna test
 
for i = 20000, 0, -1 do
      print(i)
      if i > 0 then
        print("buff")
      end
       if i == 0 then
         print("normal")
      end
end
print("end")
 
after i try something like this using while, another time in cmd, and works fine, but fail in the DST
 
 
for i = 20000, 0, -1 do
 
while i > 0 do
print(i)
i = 1- i
 
if i == 0 then
print("parei")
end
end
 
end
print("end")
 
-----------------------------------
So, here's my code
 
    local function OnEat(inst,food)
    
      if food.components.edible
           and food.components.edible.foodtype == "SEEDS" then --edible food has these types too 
 
           for i = 20000, 0, -1  do
                while i > 0 do
                    inst.components.locomotor.runspeed = 15  
                    i = 1 - i
                    if i == 0 then
                        inst.components.locomotor.runspeed = 5  
                    end 
                end  
            end
        end
    end
 
......
 
-- This initializes for the host only
local master_postinit = function(inst)
-- choose which sounds this character will play
inst.soundsname = "wilson"
-- Stats
 
inst.components.health:SetMaxHealth(150)
inst.components.hunger:SetMax(100)
inst.components.sanity:SetMax(200)
    inst.components.builder.science_bonus = 1
    -- Velocidade em 10 quando tomar café
 
    inst:AddComponent("eater")
    inst.components.eater:SetOnEatFn(OnEat)
    
 
    end
 
If u guys can help me, i appreciate ^-^
Edited by incognitox
Link to comment
https://forums.kleientertainment.com/forums/topic/50647-modding-char-help/
Share on other sites

I assume your problem is that the loop doesn't run parallel to game ticks. You shouldn't use loops for that kind of stuff in Don't Starve.

 

I don't know if this behaves any special in DST, but in DS there are special methods scattered around various utility files. For example, you can use the following:

inst:DoTaskInTime(time,function,arguments_other_than_inst)

If you want the time to be long, you may need to set "onsave" and "onload" functions to keep the temporary effects saved. Shorter timespans are insignificant and not worth the effort.

I assume your problem is that the loop doesn't run parallel to game ticks. You shouldn't use loops for that kind of stuff in Don't Starve.

 

I don't know if this behaves any special in DST, but in DS there are special methods scattered around various utility files. For example, you can use the following:

inst:DoTaskInTime(time,function,arguments_other_than_inst)

If you want the time to be long, you may need to set "onsave" and "onload" functions to keep the temporary effects saved. Shorter timespans are insignificant and not worth the effort.

Thx  man, my function works now, i make that

 

local function OnEat(inst,food)
    if food.components.edible
           and food.components.edible.foodtype == "SEEDS" then --edible food has these types too 
           inst.components.locomotor.runspeed = 12
           inst:DoTaskInTime(30, function(inst) inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED end)
        end
    end

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