Jump to content

Problems with periodic task's


Recommended Posts

i'm a somewhat experienced Dont starve mod creator unfortunately the same cannot be said about don't starve together, i'm experiencing a problem with converting my mod Bellatrix the realistic vampire into don't starve together. I have managed to get it work but without any of the well "vampiry" stuff, so no burning in sunlight.

 

i got the items to work same with the characters ghost and other bits and bobs to work except the sunlight thing, and that's were the periodic task comes into play.

 

So my sunburn works really simply i have a periodic function that checks the clock and find if its day or not check if its raining and if i have any items equipped with the tag "nosundam" and if the requirements are checked i just do a health delta, but in don't starve together it seems that how i did the event it only seems to occur on the client side of things. Knowing this i'm afraid i'm going to have to make a component or something along those lines, but i'm not sure how i would implement something like that though.

 

so that's what the problem i'm facing is there anyway to get around this or will i have to make a component or something else like that. i'm 95% positive that what i want to do is possible in some way shape or form because the character wx87 takes damage in the rain

 

(i have gone through wx87's code and still to no avail)

Link to comment
Share on other sites

What is "i have any items equipped" in DST? There are many players on the DST server.

 

in modmain.lua:

if TheNet:GetIsServer() then    AddPrefabPostInit("youcharacter",function(inst)        inst:DoPeriodicTask( .......... ) --your stuff with health etc    end)end

Edited by Maris
Link to comment
Share on other sites

Could you post your code so we can see a bit better how it's done? It would be easier to have a base for discussion than talking about generalities on the DoPeriodicTask, which can be used in a loooot of ways.

 

And I don't get why the hell you would put a AddPrefabPostInit to your character in the modmain, while it is, well, YOUR character so just do this kind of stuff in your character.lua...

Edited by ZupaleX
Link to comment
Share on other sites

in both cases in which i put the code in the mod main or the characters.lua but i get the same error that i have never had before 

 

291: attempt to preform arithmetic on local 'dt' (a nil value)

 

from this i already know its trying to access a variable that doesn't exist or is a well nil value

 

i have no clue how i would fix this


o here is the code for what im trying to do now

local function dosundamage(inst, isday)	if not TheWorld.state.israining then		if not inst:HasTag("nosundam") then			if isday then		inst.components.health:DoFireDamage(.05, false, true)			end        end	endendlocal function onbecomevampire(inst)if TheNet:GetIsServer() then    inst:DoPeriodicTask(dosundamage(inst,TheWorld.state.isday),1) --your stuff with health etcend	inst.components.locomotor.walkspeed = 4	inst.components.locomotor.runspeed = 6end
Link to comment
Share on other sites

 

 

in both cases in which i put the code in the mod main or the characters.lua but i get the same error that i have never had before 

 

291: attempt to preform arithmetic on local 'dt' (a nil value)

 

from this i already know its trying to access a variable that doesn't exist or is a well nil value

 

i have no clue how i would fix this


o here is the code for what im trying to do now

 

local function dosundamage(inst, isday)
    if not TheWorld.state.israining then
        if not inst:HasTag("nosundam") then
            if isday then
        inst.components.health:DoFireDamage(.05, false, true)
            end
end
    end
end

local function onbecomevampire(inst)

if TheNet:GetIsServer() then
inst:DoPeriodicTask(dosundamage(inst,TheWorld.state.isday),1) --your stuff with health etc
end

    inst.components.locomotor.walkspeed = 4
    inst.components.locomotor.runspeed = 6
end

 

 

DoPeriodicTask takes as a first argument the period, and as a second the function. Secondly you cannot call your function like that. You have to do

if TheNet:GetIsServer() then    inst:DoPeriodicTask(1, dosundamage, 0, TheWorld.state.isday)end

or 

if TheNet:GetIsServer() then     inst:DoPeriodicTask(1, function() dosundamage(inst,TheWorld.state.isday) end)end

It's equivalent

 

PS : third optional argument for the DoPeriodiTask is a "delta t" to execute the function. Like if you want to execute the function periodically, but delay it additionnally. This is useful when you want to have a bit of randomness. You then do

inst:DoPeriodicTask(period, function, math.random())

Finally, from 4th to nth arguments, are the potential additional arguments that are past to your function executed periodically (in your case TheWorld.state.blah)

Edited by ZupaleX
Link to comment
Share on other sites

 

 
 
if TheNet:GetIsServer() then    inst:DoPeriodicTask(1, dosundamage, 0, TheWorld.state.isday)end

or 

if TheNet:GetIsServer() then     inst:DoPeriodicTask(1, function() dosundamage(inst,TheWorld.state.isday) end)end

It's equivalent

 

Actually it's not equivavlent. Second example is better.

Link to comment
Share on other sites

@muddykat, if you write in youcharacter.lua, use

TheWorld.ismastersim

​instead of 

TheNet:GetIsServer()

​It's better for perfomance.

TheNet:GetIsServer() works fine even if world is not created, but it takes more cpu load.

​All prefabs are created after creation of the world, so it's better to use TheWorld.ismastersim in AddPrefabPostInit function and in prefab's lua file.

Link to comment
Share on other sites

Would you care to develop?

Well, it is obvious.

Let's look at this example:

if TheNet:GetIsServer() then    inst:DoPeriodicTask(1, dosundamage, 0, TheWorld.state.isday)end

​This code will take VALUE of TheWorld.state.isday variable and will never check it again.

 

And in second example the code will check this variable every time. So second code is much better than first. Right?

  • Potato Cup 1
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...