lord2clash Posted June 22, 2022 Share Posted June 22, 2022 I'm working on my character mod, I'm trying to make him transform when he has low sanity but I cant seem to do that... I've tried getting help in discord we have gotten it so it doesn't crash now but he just doesn't transform nor does it print to tell me its being called or anything so I'm stumped :/ if anyone could help it'd be greatly appreciated.. I've tried looking at a bunch of different guides and its just not doing what I need it to... I can get him to transform with a keyhandler and just pressing a button with no issues but I would like for it to be done with sanity not a button on the keyboard... thank you in advance this is my code.. its all in the script prefab file I've tried it with parts in the modmain, all in modmain, as well as all in the script (like it is currently) but its the same outcome regardless of what I do. It just doesn't call and make him transform. I want him to transform at low sanity and back when above that sanity. local master_postinit = function(inst) -- bunch of master_postinit stuff -- inst:ListenForEvent("sanitydelta") end local function TurnBackToNormal(inst) -- Do whatever is needed to be in the normal state. -- You at least need to change the animation build, if your character needs to look different. inst.AnimState:SetBuild("crowlie") isInSecondForm = false end local function TurnIntoSecondForm(inst) -- Do whatever is needed to be in the shadow creature state. -- You at least need to change the animation build, if your character needs to look different. inst.AnimState:SetBuild("crowley_form") isInSecondForm = true end local function sanitydelta(inst, data) CurrentSanity = inst.components.sanity.current -- Make sure not to react while the player is dead. if inst:HasTag("playerghost") or inst.components.health and inst.components.health:IsDead() then return end -- If sanity drops below 1, we become a shadow creature. if not isInSecondForm and CurrentSanity <= 2 then TurnIntoSecondForm(inst) print("Transformed to Crowley") elseif isInSecondForm and CurrentSanity >= 15 then TurnBackToNormal(inst) print("Transformed back to normal") end end Link to comment https://forums.kleientertainment.com/forums/topic/141120-dst-character-transformation-wont-work/ Share on other sites More sharing options...
Wonderlarr Posted June 22, 2022 Share Posted June 22, 2022 Seems like you didn't finish up your event listener, inst:ListenForEvent("sanitydelta") This doesn't do anything on it's own, you're telling the game to listen for the event "sanitydelta", without telling it to do anything. You'd want it to be inst:ListenForEvent("sanitydelta", sanitydelta) This will run the function sanitydelta whenever the event sanitydelta is received. Personally I find this confusing, I would rename the function to OnSanityDelta, so there's an obvious difference. Also, you may want to store the isInSecondForm variable as part of the entity itself. Try this out inst.isInSecondForm = false -- or inst.isInSeconfForm = true This way, it will be stored with the entity, rather than existing as a floating variable in script. Link to comment https://forums.kleientertainment.com/forums/topic/141120-dst-character-transformation-wont-work/#findComment-1578896 Share on other sites More sharing options...
lord2clash Posted June 22, 2022 Author Share Posted June 22, 2022 (edited) @TheSkylarr thank you for one and for two, I'm not sure where I would put the isinsecondform true/false if not where its at :/ I'm new to modding so if you could be more specific on that id appreciate it however I changed the function to DoSanityDelta and now i crash and get this error [string "../mods/Crowlie/scripts/prefabs/crowlie.lua"]:103: variable 'OnSanityDelta' is not declared this is my code after just changing the name of the function unless i did that wrong somehow :/ local master_postinit = function(inst) -- bunch of master postinit stuff -- inst:ListenForEvent("sanitydelta", OnSanityDelta) end local function TurnBackToNormal(inst) -- Do whatever is needed to be in the normal state. -- You at least need to change the animation build, if your character needs to look different. inst.AnimState:SetBuild("crowlie") isInSecondForm = false end local function TurnIntoSecondForm(inst) -- Do whatever is needed to be in the shadow creature state. -- You at least need to change the animation build, if your character needs to look different. inst.AnimState:SetBuild("crowley_form") isInSecondForm = true end local function OnSanityDelta(inst, data) CurrentSanity = inst.components.sanity.current -- Make sure not to react while the player is dead. if inst:HasTag("playerghost") or inst.components.health and inst.components.health:IsDead() then return end -- If sanity drops below 1, we become a shadow creature. if not isInSecondForm and CurrentSanity <= 2 then TurnIntoSecondForm(inst) print("Transformed to Crowley") -- Otherwise, if sanity gets back above 50, we become normal again. elseif isInSecondForm and CurrentSanity >= 15 then TurnBackToNormal(inst) print("Transformed back to normal") end end edit ~ I now see (well I believe at least lol) that you meant to add "inst." In front of it instead of a "hanging variable", regardless that didn't fix it its still the same crash :/ i added my client log incase that might help, client_log.txt Edited June 22, 2022 by lord2clash Link to comment https://forums.kleientertainment.com/forums/topic/141120-dst-character-transformation-wont-work/#findComment-1578912 Share on other sites More sharing options...
Wonderlarr Posted June 22, 2022 Share Posted June 22, 2022 You might need to move your sanity delta functions and such ABOVE master_postinit, rather than below. Link to comment https://forums.kleientertainment.com/forums/topic/141120-dst-character-transformation-wont-work/#findComment-1578913 Share on other sites More sharing options...
lord2clash Posted June 22, 2022 Author Share Posted June 22, 2022 15 hours ago, TheSkylarr said: You might need to move your sanity delta functions and such ABOVE master_postinit, rather than below. that worked thank you so much, i had a couple other error i had to fix but they where straight forward and easy, now he transforms when he is supposed to now its time to just tweak the values he does it at thanks again its greatly appreciated Link to comment https://forums.kleientertainment.com/forums/topic/141120-dst-character-transformation-wont-work/#findComment-1579062 Share on other sites More sharing options...
lord2clash Posted June 23, 2022 Author Share Posted June 23, 2022 (edited) **EDIT** --i figured it out i had to get rid of my health tuning and use set max health-- ******** @TheSkylarr i now have the issue of not being able to change the health/hunger values while he is transformed and back to normal i tried just moving them into the transform functions instead of masterpostinit however that cause it to crash when i ate my edible nightmare fuel so i didn't really get to test it further than that... so i guess my question is how do i change his hunger and health values when in his crow form and back to his normal values when he goes into scarecrow form Edited June 26, 2022 by lord2clash Link to comment https://forums.kleientertainment.com/forums/topic/141120-dst-character-transformation-wont-work/#findComment-1579098 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