TagumonYatsuray Posted March 10, 2019 Share Posted March 10, 2019 I'm working on a character that's resistant to the cold but vulnerable to heat. For the perk, it gives an "aura of dapperness" (Helps other player's sanity) when it's Winter, that has a small glow to it... Additionally, if it's raining or snowing during any season, they get a sanity and health regeneration... I'm also unsure how to make them more resistant to freezing or losing health in the cold... I can't seem to make these work and was hoping for help from this forum. local master_postinit = function(inst) local function uniquehealing(inst) if TheWorld.state.issnowing then inst.components.health:DoDelta(5) inst.components.sanity:DoDelta(5) end if TheWorld.state.israining then inst.components.health:DoDelta(3) inst.components.sanity:DoDelta(3) end end inst:DoPeriodicTask(10, uniquehealing(inst)) local function winterlove(inst) if TheWorld.state.iswinter then inst.components.sanity.dapperness = TUNING.DAPPERNESS_HUGE * 2 inst:AddComponent("sanityaura") inst.components.sanityaura.aura = TUNING.SANITYAURA_LARGE inst.entity:AddLight() inst.entity:AddNetwork() inst.Light:SetFalloff(0.7) inst.Light:SetIntensity(.5) inst.Light:SetRadius(5) inst.Light:SetColour(0 / 255, 200 / 255, 110 / 255) inst.Light:Enable(true) end end and inst:DoTaskInTime(0, uniquehealing) inst:WatchWorldState("startrain", function() uniquehealing(inst) end) inst:WatchWorldState("stoprain", function() uniquehealing(inst) end) inst:WatchWorldState("startsnow", function() uniquehealing(inst) end) inst:WatchWorldState("stopsnow", function() uniquehealing(inst) end) inst:DoTaskInTime(0, winterlove) inst:WatchWorldState("startwinter", function() winterlove(inst) end) inst:WatchWorldState("stopwinter", function() winterlove(inst) end) Link to comment Share on other sites More sharing options...
Ultroman Posted March 10, 2019 Share Posted March 10, 2019 (edited) To help players resist cold better (or protect against overheating) is not an easy task in this game. All you can do, really, is mess with their insulation variables, since they're the only variables affecting cold and heat, but they don't work like you want them to. Take a look for yourself in the temperature.lua (specifically the DoDelta and Update functions and the variables available to play with), and you'll see what I mean. I'd like some more information about the problem. Does nothing work? Does it crash? You can figure out a lot of things for yourself, if you put in some print-statements and check your logs. That'll help you figure out which listeners work and when they're triggered, and you can print out names of affected players etc, so you can see exactly what is happening. You can read about how to use print-statements in this post under the Debugging paragraph. Edited March 10, 2019 by Ultroman Link to comment Share on other sites More sharing options...
TagumonYatsuray Posted March 10, 2019 Author Share Posted March 10, 2019 (edited) According to this... [00:01:00]: It is Winter! [00:01:00]: component sanityaura already exists! ../mods/tagu-DST/scripts/prefabs/tagu.lua:66 in (field) fn (Lua) <62-69> [00:01:00]: Deserializing tile data (425 x 425) [00:01:09]: Registering master server in US lobby It seems that my "Winter-Check" is Working, and the Aura is working as well? Also, I did what you said and made them resistant to the cold via the insulation variables, and in Winter, it seems that my character is not freezing or getting the freeze screen. so success...? I don't know how to make the GLOW work though for the aura, since that line crashed my game. ----- Edit: It also appears the healing gained from the snow and rain only applies once... I was hoping it would give 5 health every 10 seconds while snowing, and 3 health every 10 seconds while raining Edited March 10, 2019 by TagumonYatsuray Link to comment Share on other sites More sharing options...
Ultroman Posted March 11, 2019 Share Posted March 11, 2019 Good! Something is working, then Print-statements are REALLY helpful! There are some discrepancies in your code compared to what you're actually trying to do. Only the winterlove function needs to be activated/deactivated when the worldstate changes. Since you call a DoPeriodicTask(10, uniquehealing) uniquehealing is going to be called every 10 seconds anyway, and it internally checks and reacts to the worldstate. No need to watch the world state to activate that. However, it might be nice to stop the uniquehealing periodic task, when it is not supposed to be running, but let's put that on pause for a minute. That's an easy change at the end. First, remove any inst:WatchWorldState with uniquehealing in it, and the line inst:DoTaskInTime(0, uniquehealing). Then look at what you've got. uniquehealing is called every 10 seconds, due to the DoPeriodicTask(10, uniquehealing(inst)) line winterlove is called every time the "startwinter" and "stopwinter" states/events are pushed by the game. Look at what you're doing in winterlove(). If it is winter, you do some things. You never reverse these things. You should make a winterlovestop(inst) function, which rolls back your changes when "stopwinter" runs. If you keep winterlove(inst) as it is, you can still use it by calling it in postinit, because it only does things if the right state is active. Then your winterlovestop(inst) doesn't need to check the state, you can just remove the light- and sanityaura-components (or at least disable them. I know the light can be disabled. The sanityaura might as well just be removed) Put a print-statement in your uniquehealing function, to see when it is being called, and put another print-statement in both if-statements so you can be sure that they are entered when they should be. Link to comment Share on other sites More sharing options...
TagumonYatsuray Posted March 13, 2019 Author Share Posted March 13, 2019 Awesome! I’ll try this out when I get home from work! Link to comment Share on other sites More sharing options...
TagumonYatsuray Posted March 13, 2019 Author Share Posted March 13, 2019 local master_postinit = function(inst) local function uniquehealing(inst) if TheWorld.state.issnowing == true then print("It is Snowing!") inst.components.health:DoDelta(5) inst.components.sanity:DoDelta(5) end if TheWorld.state.israining == true then print("It is Raining!") inst.components.health:DoDelta(3) inst.components.sanity:DoDelta(3) end end local function winterlove(inst) if TheWorld.state.iswinter == true then print("It is Winter!") inst.components.sanity.dapperness = TUNING.DAPPERNESS_HUGE * 2 inst:AddComponent("sanityaura") inst.components.sanityaura.aura = TUNING.SANITYAURA_LARGE end end local function winterlovestop(inst) if TheWorld.state.iswinter == false then print("It is not Winter!") inst.components.sanity.dapperness = TUNING.DAPPERNESS_HUGE * 0 inst:RemoveComponent("sanityaura") end end inst:DoPeriodicTask(5, uniquehealing(inst)) inst:DoPeriodicTask(5, winterlove(inst)) inst:DoPeriodicTask(5, winterlovestop(inst)) and inst:DoTaskInTime(0, winterlove) inst:WatchWorldState("iswinter", function() winterlove(inst) end) inst:DoTaskInTime(0, winterlovestop) inst:WatchWorldState("issummer", function() winterlovestop(inst) end) With this setup winterlove and winterlovestop are working fine.... I think.... However, UniqueHealing won't heal or print at all... and I'm still not sure how to get it to heal each 10 seconds while it's raining... Link to comment Share on other sites More sharing options...
Ultroman Posted March 14, 2019 Share Posted March 14, 2019 You're missing some important print-statements. local function uniquehealing(inst) print("uniquehealing function was called!") -- this one, to make sure it runs at all if TheWorld.state.issnowing == true then print("It is Snowing!") inst.components.health:DoDelta(5) inst.components.sanity:DoDelta(5) end if TheWorld.state.israining == true then print("It is Raining!") inst.components.health:DoDelta(3) inst.components.sanity:DoDelta(3) end end If uniquehealing IS called, but doesn't enter any of the if-statements, try printing the actual world state e.g. print("TheWorld.state.issnowing: "..tostring(TheWorld.state.issnowing)) print("TheWorld.state.israining: "..tostring(TheWorld.state.israining)) Link to comment Share on other sites More sharing options...
TagumonYatsuray Posted March 17, 2019 Author Share Posted March 17, 2019 Hmm... it doesn't seem like it calls without the Watch States.... Link to comment Share on other sites More sharing options...
Ultroman Posted March 17, 2019 Share Posted March 17, 2019 If you have a DoPeriodicTask which calls uniquehealing, and uniquehealing is never being called, then there must be something wrong with your implementation. Please zip up your entire mod and attach it to a reply here, so we can have a look. 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