BP13 Posted December 11, 2016 Share Posted December 11, 2016 Hi, I'm sort of new to modding (atm I'm just tweaking some mods for my personal usage) and in one of the mods I'm using, the character is supposed to have different attributes/ during different periods of the day. Is there some kind of function or method I could use to do that? Currently I'm thinking about using a keybind to manually update it (could someone verify if what I added below works?), but I want to see if anyone knows how to do something like that automatically. The code is from the actual character's prefab under scripts\prefab. Thanks in advance! TheInput:AddKeyUpHandler(KEY_K, function() --What I added. if TheWorld.state.isnight then --if/else statements from original .lua file. inst.components.locomotor.runspeed = 1.3 * TUNING.WILSON_RUN_SPEED inst.components.health.absorb = 0.4 inst.components.combat.damagemultiplier = 0.9 inst.components.hunger.hungerrate = 1.1 * TUNING.WILSON_HUNGER_RATE inst.components.health:StartRegen(1,4) else inst.components.locomotor.runspeed = 1.0 * TUNING.WILSON_RUN_SPEED inst.components.health.absorb = 0.1 inst.components.combat.damagemultiplier = 1.2 inst.components.hunger.hungerrate = 0.8 * TUNING.WILSON_HUNGER_RATE end end) --What I added. P.S. Does anyone knows what happened to the unofficial API documentation or know of an alternative? I kinda spent some time hosting my own site and setting up wordpress and tried using UpdraftPlus with the .zip Mobbstar left to no avail (I assume I have the wrong file for now since Blueberrys had files from hottehead or it was backed up using a different plugin). Only thing I found that's similar and still around was the Introduction to some Components topic. Link to comment Share on other sites More sharing options...
halfrose Posted December 11, 2016 Share Posted December 11, 2016 local function updatestats(inst) if TheWorld.state.phase == "day" then elseif TheWorld.state.phase == "dusk" then elseif TheWorld.state.phase == "night" then end end In master_postinit: inst:WatchWorldState( "startday", function(inst) updatestats(inst) end ) inst:WatchWorldState( "startdusk", function(inst) updatestats(inst) end ) inst:WatchWorldState( "startnight", function(inst) updatestats(inst) end ) updatestats(inst) it works on my side at least. Link to comment Share on other sites More sharing options...
Aquaterion Posted December 11, 2016 Share Posted December 11, 2016 (edited) 18 minutes ago, halfrose said: it works on my side at least. if you're gonna use phases why not watch for phases local function updatestats(inst, phase) if phase == "night" then inst.components.locomotor.runspeed = 1.3 * TUNING.WILSON_RUN_SPEED inst.components.health.absorb = 0.4 inst.components.combat.damagemultiplier = 0.9 inst.components.hunger.hungerrate = 1.1 * TUNING.WILSON_HUNGER_RATE inst.components.health:StartRegen(1,4) else inst.components.locomotor.runspeed = 1.0 * TUNING.WILSON_RUN_SPEED inst.components.health.absorb = 0.1 inst.components.combat.damagemultiplier = 1.2 inst.components.hunger.hungerrate = 0.8 * TUNING.WILSON_HUNGER_RATE end end inst:WatchWorldState("phase", updatestats) updatestats(inst, TheWorld.state.phase) Edited December 11, 2016 by Aquaterion Link to comment Share on other sites More sharing options...
BP13 Posted December 11, 2016 Author Share Posted December 11, 2016 (edited) Thanks for the help, that worked but (hope it does too when I try it multiple players) I noticed another problem: the character doesn't stop regenerating health after the night ends. I don't think this was intended, is there an existing function to tell it to stop regenerating health? If not, does the below seem okay? I saw this from a DS thread, so I'm not sure if it's compatible with DST (I could check but I'm translating some other things from this mod). local function fhlregen() inst.components.health:DoDelta(1) end inst:DoPeriodicTask(4,fhlregen(inst)) --Replaces inst.components.health:StartRegen(1,4) under if phase == "night" statement Edited December 11, 2016 by BP13 Code fix Link to comment Share on other sites More sharing options...
Aquaterion Posted December 11, 2016 Share Posted December 11, 2016 (edited) 7 minutes ago, BP13 said: Thanks for the help, that worked but (hope it does too when I try it multiple players) I noticed another problem: the character doesn't stop regenerating health after the night ends. I don't think this was intended, is there an existing function to tell it to stop regenerating health? If not, does the below seem okay? I saw this from a DS thread, so I'm not sure if it's compatible with DST (I could check but I'm translating some other things from this mod). local function fhlregen() inst.components.health:DoDelta(1) end inst:DoPeriodicTask(4,fhlregen(inst)) --Replaces inst.components.health:StartRegen(1,4) under if phase == "night" statement oh ye i was suppose to add it to my version of the code; in your code you're using at night inst.components.health:StartRegen(1,4) so you should be able to do when its not night inst.components.health:StopRegen() Edited December 11, 2016 by Aquaterion Link to comment Share on other sites More sharing options...
BP13 Posted December 11, 2016 Author Share Posted December 11, 2016 9 minutes ago, Aquaterion said: oh ye i was suppose to add it to my version of the code; in your code you're using at night inst.components.health:StartRegen(1,4) so you should be able to do when its not night inst.components.health:StopRegen() It works, thanks again, do you know if inst:WatchWorldState("phase", updatestats) is being constantly called or only when the world transitions into the next phase? I'm worried it might interfere with other mods that grant health regen in the same way. Link to comment Share on other sites More sharing options...
Aquaterion Posted December 11, 2016 Share Posted December 11, 2016 (edited) 8 hours ago, BP13 said: It works, thanks again, do you know if inst:WatchWorldState("phase", updatestats) is being constantly called or only when the world transitions into the next phase? I'm worried it might interfere with other mods that grant health regen in the same way. only when the phase hits, but if another mod tries to call StartRegen while its night, then your regen will get overriden what you can do: local function updatestats(inst, phase) if phase == "night" then inst.components.locomotor.runspeed = 1.3 * TUNING.WILSON_RUN_SPEED inst.components.health.absorb = 0.4 inst.components.combat.damagemultiplier = 0.9 inst.components.hunger.hungerrate = 1.1 * TUNING.WILSON_HUNGER_RATE inst.nightregen = inst:DoPeriodicTask(4, function()--4 seconds to do the below function if not inst.components.health:IsDead() then inst.components.health:DoDelta(1, true, "regen")--heal 1hp end end) else inst.components.locomotor.runspeed = 1.0 * TUNING.WILSON_RUN_SPEED inst.components.health.absorb = 0.1 inst.components.combat.damagemultiplier = 1.2 inst.components.hunger.hungerrate = 0.8 * TUNING.WILSON_HUNGER_RATE if inst.nightregen then inst.nightregen:Cancel() inst.nightregen = nil end end end Edit: Fixed the error incase someone copies this code Edited December 12, 2016 by Aquaterion If you do copy it, rename nightregen to something else to make sure to avoid conflict Link to comment Share on other sites More sharing options...
BP13 Posted December 11, 2016 Author Share Posted December 11, 2016 (edited) 27 minutes ago, Aquaterion said: only when the phase hits, but if another mod tries to call StartRegen while its night, then your regen will get overriden what you can do: local function updatestats(inst, phase) if phase == "night" then inst.components.locomotor.runspeed = 1.3 * TUNING.WILSON_RUN_SPEED inst.components.health.absorb = 0.4 inst.components.combat.damagemultiplier = 0.9 inst.components.hunger.hungerrate = 1.1 * TUNING.WILSON_HUNGER_RATE inst.nightregen = inst:DoPeriodicTask(4, function()--4 seconds to do the below function if not inst.components.health:IsDead() then inst.components.health:DoDelta(1, true "regen")--heal 1hp end end) else inst.components.locomotor.runspeed = 1.0 * TUNING.WILSON_RUN_SPEED inst.components.health.absorb = 0.1 inst.components.combat.damagemultiplier = 1.2 inst.components.hunger.hungerrate = 0.8 * TUNING.WILSON_HUNGER_RATE if inst.nightregen then inst.nightregen:Cancel() inst.nightregen = nil end end end Got an error, is it because nightregen isn't an existing variable (or event?) or is it because of something else? I'm not really familiar with lua yet. Not sure if this helps, but I'm including part of the client/error log: Spoiler [string "../mods/workshop-804317397/scripts/prefabs/fhl.lua"]:155: ')' expected near '"regen"' LUA ERROR stack traceback: =[C] in function 'assert' scripts/mainfunctions.lua(90,1) =(tail call) ? =[C] in function 'xpcall' scripts/mods.lua(130,1) scripts/mods.lua(569,1) in function 'RegisterPrefabs' scripts/gamelogic.lua(216,1) in function 'LoadAssets' Edited December 11, 2016 by BP13 Link to comment Share on other sites More sharing options...
BP13 Posted December 12, 2016 Author Share Posted December 12, 2016 2 hours ago, BP13 said: Got an error, is it because nightregen isn't an existing variable (or event?) or is it because of something else? I'm not really familiar with lua yet. Not sure if this helps, but I'm including part of the client/error log: Got it working, let's just say I miss using braces in Java/C++ (that and forgetting the tips/tricks I learned while I was programming). Honestly didn't expect the console log to be useful, guess I saw it way too many times and just mentally ignored it before I got back into DS/DST. Anyway, enough blabbering from me, I'm still hoping someone replies about that documentation or knows a few (character) mods that has some good documentation in their files. 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