Eusong Posted February 2, 2017 Share Posted February 2, 2017 I've been working on this mod and I can't seem to get it to work. I want her to lose sanity from attacking and hit harder/move slower while insane. local MakePlayerCharacter = require "prefabs/player_common" local assets = { Asset("SCRIPT", "scripts/prefabs/player_common.lua"), } local prefabs = {} -- Custom starting items local start_inv = { } -- When the character is revived from human local function onbecamehuman(inst) end local function onbecameghost(inst) end -- When loading or spawning the character local function onload(inst) inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman) inst:ListenForEvent("ms_becameghost", onbecameghost) if inst:HasTag("playerghost") then onbecameghost(inst) else onbecamehuman(inst) end end local function OnKill(inst, data) inst.components.sanity:DoDelta(-10) end local function OnAttack(inst, data) inst.components.sanity:DoDelta(-1) end -- This initializes for both the server and client. Tags can be added here. local common_postinit = function(inst) -- Minimap icon inst.MiniMapEntity:SetIcon( "yanderechan.tex" ) if inst.components.sanity.current < 0.3 then inst.components.combat.damagemultiplier = 2 inst.components.locomotor.walkspeed = 1 inst.components.locomotor.runspeed = 2 end if inst.components.sanity.current > 0.3 then inst.components.combat.damagemultiplier = 1 inst.components.locomotor.walkspeed = 4 inst.components.locomotor.runspeed = 5 end 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 = "wendy" -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used --inst.talker_path_override = "dontstarve_DLC001/characters/" -- Stats inst.components.health:SetMaxHealth(100) inst.components.hunger:SetMax(150) inst.components.sanity:SetMax(150) -- Damage multiplier (optional) -- Hunger rate (optional) inst.components.hunger.hungerrate = TUNING.WILSON_HUNGER_RATE inst.OnLoad = onload inst.OnNewSpawn = onload end return MakePlayerCharacter("yanderechan", prefabs, assets, common_postinit, master_postinit, start_inv) It doesn't recognize sanity as being a component (It causes a crash) and nothing happens when attacking a creature or killing one. Any help would be greatly appriciated Link to comment https://forums.kleientertainment.com/forums/topic/73771-losing-sanity-from-attacking-and-altered-stats-when-insane/ Share on other sites More sharing options...
Lumina Posted February 2, 2017 Share Posted February 2, 2017 if inst.components.sanity.current < 0.3 then inst.components.combat.damagemultiplier = 2 inst.components.locomotor.walkspeed = 1 inst.components.locomotor.runspeed = 2 end if inst.components.sanity.current > 0.3 then inst.components.combat.damagemultiplier = 1 inst.components.locomotor.walkspeed = 4 inst.components.locomotor.runspeed = 5 end So i'm not sure, but this way to manage it could be problematic because what would happen if the number is 0.3 ? You have the case when it's lower, and when it's higher, but not the case when it's 0.3. So maybe it's better to do : if inst.components.sanity.current < 0.3 then inst.components.combat.damagemultiplier = 2 inst.components.locomotor.walkspeed = 1 inst.components.locomotor.runspeed = 2 else inst.components.combat.damagemultiplier = 1 inst.components.locomotor.walkspeed = 4 inst.components.locomotor.runspeed = 5 end (I can't help about inst.component.sanity because i don't know this part) For the "lose sanity when attacking", the best way is probably to use the function local function OnAttackOther(inst, data) Search in the game code for example of enemy using this function to see how it work. Hound use it if i'm not wrong. Link to comment https://forums.kleientertainment.com/forums/topic/73771-losing-sanity-from-attacking-and-altered-stats-when-insane/#findComment-863138 Share on other sites More sharing options...
Lumina Posted February 2, 2017 Share Posted February 2, 2017 47 minutes ago, Eusong said: local function OnAttack(inst, data) inst.components.sanity:DoDelta(-1) end I didn't saw this. This is only a part of the code. You need to add :: inst:ListenForEvent("onattackother", OnAttack) Into the main function, for example after 48 minutes ago, Eusong said: inst.OnNewSpawn = onload Link to comment https://forums.kleientertainment.com/forums/topic/73771-losing-sanity-from-attacking-and-altered-stats-when-insane/#findComment-863139 Share on other sites More sharing options...
. . . Posted February 3, 2017 Share Posted February 3, 2017 For losing sanity from attacking something, put this in YOURCHARACTER.lua inside the master_postinit Spoiler inst:ListenForEvent("onattackother", function(inst, data) inst.components.sanity:DoDelta(-1) -- Replace "-1" with any number u want end) -- If you want only lose sanity on attack when insane then use below 1 inst:ListenForEvent("onattackother", function(inst, data) if not inst.components.sanity:IsSane() then inst.components.sanity:DoDelta(-1) end end) For your character becoming slower when insane put this in YOURCHARACTER.lua inside the master_postinit Spoiler inst:ListenForEvent("gosane", function(inst, data) inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "insane_spd_debuff") end) inst:ListenForEvent("goinsane", function(inst, data) inst.components.locomotor:SetExternalSpeedMultiplier(inst, "insane_spd_debuff", .7) end) Hopefully, this works for you !! Link to comment https://forums.kleientertainment.com/forums/topic/73771-losing-sanity-from-attacking-and-altered-stats-when-insane/#findComment-863188 Share on other sites More sharing options...
Eusong Posted February 3, 2017 Author Share Posted February 3, 2017 Thank you both for your help! SuperDavid's code worked. Thank you very much! Link to comment https://forums.kleientertainment.com/forums/topic/73771-losing-sanity-from-attacking-and-altered-stats-when-insane/#findComment-863199 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