muddykat Posted September 18, 2015 Share Posted September 18, 2015 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 More sharing options...
Maris Posted September 18, 2015 Share Posted September 18, 2015 (edited) 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 September 18, 2015 by Maris Link to comment Share on other sites More sharing options...
muddykat Posted September 19, 2015 Author Share Posted September 19, 2015 (edited) i get an error stating it doesn't know what TheNet is sorry its not checking what the player is wearing the item just adds a tag to the player who has it on called "nosundam" Edited September 19, 2015 by muddykat Link to comment Share on other sites More sharing options...
ZupaleX Posted September 19, 2015 Share Posted September 19, 2015 (edited) 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 September 19, 2015 by ZupaleX Link to comment Share on other sites More sharing options...
muddykat Posted September 20, 2015 Author Share Posted September 20, 2015 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 thiso here is the code for what im trying to do nowlocal 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 More sharing options...
ZupaleX Posted September 20, 2015 Share Posted September 20, 2015 (edited) 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 thiso 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) endend endendlocal function onbecomevampire(inst)if TheNet:GetIsServer() theninst:DoPeriodicTask(dosundamage(inst,TheWorld.state.isday),1) --your stuff with health etcend inst.components.locomotor.walkspeed = 4 inst.components.locomotor.runspeed = 6end 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 doif TheNet:GetIsServer() then inst:DoPeriodicTask(1, dosundamage, 0, TheWorld.state.isday)endor if TheNet:GetIsServer() then inst:DoPeriodicTask(1, function() dosundamage(inst,TheWorld.state.isday) end)endIt'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 doinst: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 September 20, 2015 by ZupaleX Link to comment Share on other sites More sharing options...
Maris Posted September 20, 2015 Share Posted September 20, 2015 if TheNet:GetIsServer() then inst:DoPeriodicTask(1, dosundamage, 0, TheWorld.state.isday)endor if TheNet:GetIsServer() then inst:DoPeriodicTask(1, function() dosundamage(inst,TheWorld.state.isday) end)endIt's equivalent Actually it's not equivavlent. Second example is better. Link to comment Share on other sites More sharing options...
Maris Posted September 20, 2015 Share Posted September 20, 2015 @muddykat, if you write in youcharacter.lua, useTheWorld.ismastersiminstead 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 More sharing options...
ZupaleX Posted September 21, 2015 Share Posted September 21, 2015 Actually it's not equivavlent. Second example is better. Would you care to develop? Link to comment Share on other sites More sharing options...
Maris Posted September 21, 2015 Share Posted September 21, 2015 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)endThis 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? 1 Link to comment Share on other sites More sharing options...
ZupaleX Posted September 21, 2015 Share Posted September 21, 2015 (edited) Seen like that indeed ^^ Edited September 21, 2015 by ZupaleX Link to comment 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