ArkamInmate00451 Posted September 24, 2015 Share Posted September 24, 2015 I'm a first time modder and I'm creating two separate characters. These are the traits I'd like them to have-Looses sanity during the day-Sanity unaffected at dusk -Increases sanity in the dark/at night-Increases sanity during thunder storms/rain (I still want the sanity to be effected based on wetness though) Also one:-Is a monster/befriends spiders The other:-Comes with a personal hat and umbrella And help would be great! Link to comment Share on other sites More sharing options...
DrSmugleaf Posted September 25, 2015 Share Posted September 25, 2015 Sanity, in your character.lua:local function sanityfn(inst) if inst.sg:HasStateTag("nomorph") or inst:HasTag("playerghost") or inst.components.health:IsDead() then return end if TheWorld.state.israining then inst.components.sanity.dapperness = TUNING.DAPPERNESS_SMALL elseif TheWorld.state.isday then inst.components.sanity.dapperness = -TUNING.DAPPERNESS_TINY elseif TheWorld.state.isdusk then inst.components.sanity.dapperness = 0 elseif TheWorld.state.isnight then inst.components.sanity.dapperness = TUNING.DAPPERNESS_TINY endendIn your character.lua's master_postinit:inst.components.sanity.custom_rate_fn = sanityfnMonster, befriends spiders, in your character.lua's master_postinit:inst:AddTag("monster")inst:AddTag("spiderwhisperer")Comes with a personal hat and umbrella, in your character.lua:local start_inv = { "tophat" "umbrella"} Link to comment Share on other sites More sharing options...
BlueSideWind Posted September 25, 2015 Share Posted September 25, 2015 Sanity, in your character.lua:local function sanityfn(inst) if inst.sg:HasStateTag("nomorph") or inst:HasTag("playerghost") or inst.components.health:IsDead() then return end if TheWorld.state.israining then inst.components.sanity.dapperness = TUNING.DAPPERNESS_SMALL elseif TheWorld.state.isday then inst.components.sanity.dapperness = -TUNING.DAPPERNESS_TINY elseif TheWorld.state.isdusk then inst.components.sanity.dapperness = 0 elseif TheWorld.state.isnight then inst.components.sanity.dapperness = TUNING.DAPPERNESS_TINY endendIn your character.lua's master_postinit:inst.components.sanity.custom_rate_fn = sanityfnMonster, befriends spiders, in your character.lua's master_postinit:inst:AddTag("monster")inst:AddTag("spiderwhisperer")Comes with a personal hat and umbrella, in your character.lua:local start_inv = { "tophat" "umbrella"} Starting items need a comma at the end. example local start_inv = {"tophat","umbrella", Link to comment Share on other sites More sharing options...
ArkamInmate00451 Posted October 2, 2015 Author Share Posted October 2, 2015 So I got the monster trait to work no problem. But my sanity still stays the same during the day and drains at night. I copied and pasted the text into my character lua. Any advice? Link to comment Share on other sites More sharing options...
Zackreaver Posted October 2, 2015 Share Posted October 2, 2015 (edited) local function sanityfn(inst) if inst.sg:HasStateTag("nomorph") or inst:HasTag("playerghost") or inst.components.health:IsDead() then return end if TheWorld.state.israining then inst.components.sanity.dapperness = TUNING.DAPPERNESS_SMALL elseif TheWorld.state.isday then inst.components.sanity.dapperness = -TUNING.DAPPERNESS_TINY elseif TheWorld.state.isdusk then inst.components.sanity.dapperness = 0 elseif TheWorld.state.isnight then inst.components.sanity.dapperness = TUNING.DAPPERNESS_TINY endend This isn't the best way to do this, the custom_rate_fn in the sanity component is awaiting the function to return a value. Willows sanity function returns a number depending on the number and size of fire near her. This function is replacing the value of the characters dapperness, if another mod or feature was changing this it will create a conflict. Here's a better waylocal function sanityfn(inst) if inst.sg:HasStateTag("nomorph") or inst:HasTag("playerghost") or inst.components.health:IsDead() then return end if TheWorld.state.israining then return TUNING.DAPPERNESS_SMALL * TUNING.SANITY_DAPPERNESS elseif TheWorld.state.isday then return -TUNING.DAPPERNESS_TINY * TUNING.SANITY_DAPPERNESS elseif TheWorld.state.isdusk then return 0 elseif TheWorld.state.isnight then return TUNING.DAPPERNESS_TINY * TUNING.SANITY_DAPPERNESS endendDoes the same thing that was intended, except now it works completely separate from the characters built in dapperness stat. So I got the monster trait to work no problem. But my sanity still stays the same during the day and drains at night. I copied and pasted the text into my character lua. Any advice? Did you remember to put the change in your master_postinit? It looks like this in your character.lua at the bottom of itlocal master_postinit = function(inst)inst.components.sanity.custom_rate_fn = sanityfnThe sanity function smugleaf and I gave only work if it gets set as your characters custom_rate_fn, so if you overlooked that part then it won't do anything. His method works too, but I suggest using mine, it does the same thing but has better compatibility. Edited October 2, 2015 by Zackreaver Link to comment Share on other sites More sharing options...
ArkamInmate00451 Posted October 2, 2015 Author Share Posted October 2, 2015 Here's my character lua. I can't seem to find where to paste the code? I searched for sanity in the document and only found it once.patrick.lua Link to comment Share on other sites More sharing options...
Noggle Posted October 2, 2015 Share Posted October 2, 2015 (edited) I believe this should work, though I must admit I haven't put much time into it, I'm lazying off at work right now. -edit: Darn, thought that I could get away with posting it with a code snippet.patrick.lua Edited October 2, 2015 by Noggle Link to comment Share on other sites More sharing options...
ArkamInmate00451 Posted October 2, 2015 Author Share Posted October 2, 2015 Thanks! Much appreciated. But the mod crashed during the world generation and didn't seem to work. Link to comment Share on other sites More sharing options...
Valkyrie19k Posted October 3, 2015 Share Posted October 3, 2015 (edited) @ArkamInmate00451, local MakePlayerCharacter = require "prefabs/player_common"local assets = { Asset( "ANIM", "anim/player_basic.zip" ), Asset( "ANIM", "anim/player_idles_shiver.zip" ), Asset( "ANIM", "anim/player_actions.zip" ), Asset( "ANIM", "anim/player_actions_axe.zip" ), Asset( "ANIM", "anim/player_actions_pickaxe.zip" ), Asset( "ANIM", "anim/player_actions_shovel.zip" ), Asset( "ANIM", "anim/player_actions_blowdart.zip" ), Asset( "ANIM", "anim/player_actions_eat.zip" ), Asset( "ANIM", "anim/player_actions_item.zip" ), Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ), Asset( "ANIM", "anim/player_actions_bugnet.zip" ), Asset( "ANIM", "anim/player_actions_fishing.zip" ), Asset( "ANIM", "anim/player_actions_boomerang.zip" ), Asset( "ANIM", "anim/player_bush_hat.zip" ), Asset( "ANIM", "anim/player_attacks.zip" ), Asset( "ANIM", "anim/player_idles.zip" ), Asset( "ANIM", "anim/player_rebirth.zip" ), Asset( "ANIM", "anim/player_jump.zip" ), Asset( "ANIM", "anim/player_amulet_resurrect.zip" ), Asset( "ANIM", "anim/player_teleport.zip" ), Asset( "ANIM", "anim/wilson_fx.zip" ), Asset( "ANIM", "anim/player_one_man_band.zip" ), Asset( "ANIM", "anim/shadow_hands.zip" ), Asset( "SOUND", "sound/sfx.fsb" ), Asset( "SOUND", "sound/wilson.fsb" ), Asset( "ANIM", "anim/beard.zip" ), Asset( "ANIM", "anim/patrick.zip" ), Asset( "ANIM", "anim/ghost_patrick_build.zip" ),}local prefabs = {}-- Custom starting itemslocal start_inv = { "tophat", "umbrella", }-- When the character is revived from humanlocal function onbecamehuman(inst) -- Set speed when loading or reviving from ghost (optional) inst.components.locomotor.walkspeed = 4 inst.components.locomotor.runspeed = 6end-- When loading or spawning the characterlocal function onload(inst) inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman) if not inst:HasTag("playerghost") then onbecamehuman(inst) endend--Sanity Test local function sanityfn(inst) if inst.sg:HasStateTag("nomorph") or inst:HasTag("playerghost") or inst.components.health:IsDead() then return end if TheWorld.state.israining then return TUNING.DAPPERNESS_SMALL * TUNING.SANITY_DAPPERNESS elseif TheWorld.state.isday then return -TUNING.DAPPERNESS_TINY * TUNING.SANITY_DAPPERNESS elseif TheWorld.state.isdusk then return 0 elseif TheWorld.state.isnight then return TUNING.DAPPERNESS_TINY * TUNING.SANITY_DAPPERNESS endend -- This initializes for both the server and client. Tags can be added here.local common_postinit = function(inst) -- Minimap icon inst.MiniMapEntity:SetIcon( "patrick.tex" )end -- This initializes for the server only. Components are added here.local master_postinit = function(inst) -- choose which sounds this character will play inst.soundsname = "woodie" -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used --inst.talker_path_override = "dontstarve_DLC001/characters/" -- Stats inst.components.health:SetMaxHealth(150) inst.components.hunger:SetMax(150) inst.components.sanity:SetMax(200) -- Damage multiplier (optional) inst.components.combat.damagemultiplier = 1 -- Hunger rate (optional) inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE --This is what calls the custom_rate function above inst.components.sanity.custom_rate_fn = sanityfn inst.OnLoad = onload inst.OnNewSpawn = onload --Monster Trait-- inst:AddTag("monster") inst:AddTag("spiderwhisperer") endreturn MakePlayerCharacter("patrick", prefabs, assets, common_postinit, master_postinit, start_inv) No crash, tried it myself.It is also good practice to do indentation so it is easier to read. :3Things to consider too, your sanity drain is so low even during daylight while 100% soaked.Might want to tweak it some. Edited October 3, 2015 by Valkyrie19k Link to comment Share on other sites More sharing options...
ArkamInmate00451 Posted October 3, 2015 Author Share Posted October 3, 2015 Wow thanks a bunch!!! I'll give it a try. Link to comment Share on other sites More sharing options...
ArkamInmate00451 Posted October 3, 2015 Author Share Posted October 3, 2015 No game crashing, loss of sanity during the day, and none at night! Any tips to make adjustments to increase the sanity loss at day and stop the loss at dusk? Everything else works great! Thanks! Link to comment Share on other sites More sharing options...
ArkamInmate00451 Posted October 3, 2015 Author Share Posted October 3, 2015 Ok update: everything works fine until the character becomes a ghost....then the game crashes. Any ideas? Link to comment Share on other sites More sharing options...
Noggle Posted October 3, 2015 Share Posted October 3, 2015 Ok update: everything works fine until the character becomes a ghost....then the game crashes. Any ideas?Please post your crash logs. If you're on a windows computer it will be located (by default) at C:\Users\PC\Documents\Klei\DoNotStarveTogether\log.txt This will tell you the exact line of code that is causing an issue usually. Link to comment Share on other sites More sharing options...
Valkyrie19k Posted October 3, 2015 Share Posted October 3, 2015 @Noggle, [string "scripts/components/sanity.lua"]:304: attempt to perform arithmetic on a nil valueLUA ERROR stack traceback:scripts/components/sanity.lua:304 in (method) Recalc (Lua) <262-319> self = _oldissane = true dapperness_mult = 1 dapperness = 0 rate = -0.21998019159109 rate_modifier = 1 _oldpercent = 0.97702524758045 night_drain_mult = 1 inst = 109368 - jet (valid:true) fxtime = 0 neg_aura_mult = 1 sanity_penalties = table: 0EA78160 _ = table: 0EA78070 custom_rate_fn = function - ../mods/jetro/scripts/prefabs/jet.lua:66 dt = 0.033333335071802 total_dapperness = 0 dapper_delta = 0 moisture_delta = 0 light_delta = 0 aura_delta = -0.21998019159109 x = -348.41632080078 y = 0 z = 50.545486450195 ents = table: 0E2AD358 ghost_delta = -0scripts/components/sanity.lua:236 in (method) OnUpdate (Lua) <231-245> self = _oldissane = true dapperness_mult = 1 dapperness = 0 rate = -0.21998019159109 rate_modifier = 1 _oldpercent = 0.97702524758045 night_drain_mult = 1 inst = 109368 - jet (valid:true) fxtime = 0 neg_aura_mult = 1 sanity_penalties = table: 0EA78160 _ = table: 0EA78070 custom_rate_fn = function - ../mods/jetro/scripts/prefabs/jet.lua:66 dt = 0.033333335071802scripts/update.lua:183 in () ? (Lua) <146-219> dt = 0.033333335071802 tick = 771 k = 109368 v = 109368 - jet (valid:true) cmp = table: 0EA78250 [00:01:27]: [string "scripts/components/sanity.lua"]:304: attempt to perform arithmetic on a nil valueLUA ERROR stack traceback: scripts/components/sanity.lua:304 in (method) Recalc (Lua) <262-319> scripts/components/sanity.lua:236 in (method) OnUpdate (Lua) <231-245> scripts/update.lua:183 in () ? (Lua) <146-219> Link to comment Share on other sites More sharing options...
Valkyrie19k Posted October 3, 2015 Share Posted October 3, 2015 @ArkamInmate00451, Looking at other people's lua is also a great way of getting some information.Why not try looking into http://steamcommunity.com/sharedfiles/filedetails/?id=505264181 His character somewhat fits your description. Link to comment Share on other sites More sharing options...
ArkamInmate00451 Posted October 3, 2015 Author Share Posted October 3, 2015 (edited) Managed to fix the ghost crashing error! Aaaand now the sanity drains constantly....during day, dusk, and night..... I'm sure everyone is annoyed with me at this point. I honestly have no idea what I'm doing and am thankful for everyone's help so far! Here's my code, attached. I'd still like to increase the drain at day, and stop the drain at dusk and night.patrick.lua Edited October 3, 2015 by ArkamInmate00451 Link to comment Share on other sites More sharing options...
Zackreaver Posted October 4, 2015 Share Posted October 4, 2015 (edited) I'm sure everyone is annoyed with me at this point.Your wrong, were not annoyed at all. We're glad to help Edit: I don't see anything wrong with the code on the outlook, I'm going to do a field test and see what might be the problem. Edit2: Ah I see the problem, our code doesn't STOP the drain at night, it add's sanity recover during night. However the sanity recover we gave your character isn't higher than the amount he loses. Our code was working, it just wasn't strong enough, so we'll just raise the numbers. TUNING.DAPPERNESS_TINY = 0.0222222222 Thats the number that tuning.dapperness_tiny gives you could just make it sayreturn 0.02If you raise that number, it will increase the amount of sanity that you gain. The exact amount of sanity that you lose at night normally is -0.083when your in light at nighttime-0.83when your in pitch black at nighttime. So if you have the nighttime value set asreturn 0.83You'll never lose sanity at night even when your at pitch black. And you'll gain it if your near a light source But if you instead want to not lose any sanity from night time at all, but you don't want to gain any either, you can do thislocal lightval = CanEntitySeeInDark(inst) and .9 or inst.LightWatcher:GetLightValue() return -1 * ((lightval > TUNING.SANITY_HIGH_LIGHT and TUNING.SANITY_NIGHT_LIGHT) or (lightval < TUNING.SANITY_LOW_LIGHT and TUNING.SANITY_NIGHT_DARK) or TUNING.SANITY_NIGHT_MID) * inst.components.sanity.night_drain_multAfter adjusted it should look something like thislocal function sanityfn(inst) if inst.sg:HasStateTag("nomorph") or inst:HasTag("playerghost") or inst.components.health:IsDead() then return end if TheWorld.state.israining then return TUNING.DAPPERNESS_SMALL * TUNING.SANITY_DAPPERNESS elseif TheWorld.state.isday then return -TUNING.DAPPERNESS_TINY * TUNING.SANITY_DAPPERNESS else local lightval = CanEntitySeeInDark(inst) and .9 or inst.LightWatcher:GetLightValue() return -1 * ((lightval > TUNING.SANITY_HIGH_LIGHT and TUNING.SANITY_NIGHT_LIGHT) or (lightval < TUNING.SANITY_LOW_LIGHT and TUNING.SANITY_NIGHT_DARK) or TUNING.SANITY_NIGHT_MID) * inst.components.sanity.night_drain_mult endend Edited October 4, 2015 by Zackreaver Link to comment Share on other sites More sharing options...
ArkamInmate00451 Posted October 4, 2015 Author Share Posted October 4, 2015 Hey, that works great! Thanks! I tested it in game, nothing crashes even after death. You're fantastic. Link to comment Share on other sites More sharing options...
Valkyrie19k Posted October 4, 2015 Share Posted October 4, 2015 @Zackreaver, off topic. That moosegoose picture though. Lovin' it. Link to comment Share on other sites More sharing options...
Zackreaver Posted October 7, 2015 Share Posted October 7, 2015 (edited) @Valkyrie19k, Moosegoose's face feels like how I feel most of the time, very derpy. Also, rezecib rock's the angry dragonfly portrait, and Darkxero was made a picture of glommer pooping code (perfect representation), so I felt like trying to fit in. Also, I actually am a Moose, after being a bearger, all accidental.http://forums.kleientertainment.com/topic/52761-help-i-accidently-became-a-bearger/?hl=%2Baccidently+%2Bbearger I should be more careful. Hey, that works great! Thanks! I tested it in game, nothing crashes even after death. You're fantastic. Glad to hear it, feel free to ask for help anytime. Edited October 7, 2015 by Zackreaver 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