Fidu Posted May 22, 2019 Author Share Posted May 22, 2019 holy crap... you are my hero(ine) Finally. And i even understand why now. Thank you oh so very very much for everything. I hope you have a great day and get some similar satisfying feelings like myself right now. I am so glad. Even though it's easy for you my head hurts ^^. But i also feel like i learned a lot. And i am just happy the mod works and is (imho) massively improved with this feature. And for anybody who might need it here is the final and correct code (with the return near the end ): Spoiler local function ToggleMoggleRPC(inst) if inst.TransformState == 1 then inst.components.talker:Say("I can smell it!", 2.5,true) else inst.components.talker:Say("I can't smell anything!", 2.5,true) return end inst.player_classified.mogglevision:set(not inst.components.playervision.forcenightvision) print(inst.components.playervision.forcenightvision) end Little bug i noticed. When i am in State 1 and have mogglevision active and then change states the vision stays activated no matter what i do. I understand that the keyfunction just doesn't work anymore because thats intended. But how can i make it so mogglevision gets canceled no matter if its activated or not when the other states trigger? I think i need something that just does the opposite of "return" in this case. Or just a function that cancels mogglevision when he is in State 2 or State 3. Link to comment Share on other sites More sharing options...
Ultroman Posted May 22, 2019 Share Posted May 22, 2019 I'm sure you'll figure it out I just wanted to chime in and say that structure and indentation does wonders for readability and understanding what your code is actually doing. local function ToggleMoggleRPC(inst) if inst.TransformState == 1 then inst.components.talker:Say("I can smell it!", 2.5,true) else inst.components.talker:Say("I can't smell anything!", 2.5,true) return end inst.player_classified.mogglevision:set(not inst.components.playervision.forcenightvision) print(inst.components.playervision.forcenightvision) end versus local function ToggleMoggleRPC(inst) if inst.TransformState == 1 then inst.components.talker:Say("I can smell it!", 2.5, true) else inst.components.talker:Say("I can't smell anything!", 2.5, true) return end inst.player_classified.mogglevision:set(not inst.components.playervision.forcenightvision) print(inst.components.playervision.forcenightvision) end Link to comment Share on other sites More sharing options...
Fidu Posted May 22, 2019 Author Share Posted May 22, 2019 (edited) Thank you Ultroman, and you are absolutely right. I just thought i already structured it but you showed me how to improve. thanks a lot. i am not sure if i'll figure it out myself but won't try it today either way ^^. I am busted and my brain hurts XD. Still i want to fix it... and i hope i can ask again if i can't figure it out. but like i said, it's enough for a day. It's still an improved version so i reuploaded it: https://steamcommunity.com/sharedfiles/filedetails/?id=1662813017 Edited May 22, 2019 by Fidu Link to comment Share on other sites More sharing options...
Ultroman Posted May 22, 2019 Share Posted May 22, 2019 Yeah, code gets pretty complicated in itself. No reason to help it be even more complicated Of course you can ask I don't consider this thread closed, and I'm sure the ever-amazing Yakumo doesn't either. I just don't have time to actually help right now. Kinda swamped the next two weeks. Link to comment Share on other sites More sharing options...
Fidu Posted May 22, 2019 Author Share Posted May 22, 2019 (edited) Ok i know what i wanna do but not exactly how. I wanna make a variable for mogglevision. (or use one thats already there, if i can figure that out) After that i just use this variable (like: inst.mogglevision) and simply set this to "false" under the Transformstates 2 and 3 in the quanyecha.lua. example of idea: inst.transformstate = 3 inst.mogglevision:enable(false) In my mind this would make it so when state 2 or 3 triggers the mogglevision gets canceled regardless if already active. ps: i am only recently able to even have such thoughts because of all the stuff i learned today. Yes this is a compliment Edited May 22, 2019 by Fidu Link to comment Share on other sites More sharing options...
Fidu Posted May 23, 2019 Author Share Posted May 23, 2019 Sadly i got to report back that your faith in me, and myself, seemed to be misplaced Even though i learned a lot and understand more and more how things work, i am still unable to translate that in an actual working format. I tried everything i could think of and that was quite a lot... Even reading some more about functions in general like here: http://lua-users.org/wiki/FunctionsTutorial But still to no avail. I tried setting different functions from the mogglevision code in modmain.lua to false in the quenyecha.lua ... error i tried to tell states 3 and 2 to simply don't use the "nightvision_colourcubes" when triggered... error I tried to reverse the mogglevision function from modmain in the transformstates in quanyecha... error As it stands now i still do lack the knowledge what needs to be where and how it must be written exactly for that case to do what i want. I think i am not on the wrong track completely, but it still is quite frustrating that i still can't fix it myself. I get a feeling i would need a lot more time on my hands for this to work out properly than i have right now. I hope you are not as dissapointed as myself at this point and still wanna gimme the right example of how it should be done to work, because i still love this character so much and playing around with it, trying to improve things (that i am actual capable of). I surely should refrain from doing to complicated things that demand a knowledge only you guys here possess. Link to comment Share on other sites More sharing options...
Ultroman Posted May 23, 2019 Share Posted May 23, 2019 We can make it work at some point. I don't have time right now, but others do. And it sounds like you just need some more time with LUA tutorials. Did you take the LUA Crash Course? That site has a lot more than the crash course, but it's a great place to start. Just start practicing a bit with simpler things. You'll get the hang of it. Link to comment Share on other sites More sharing options...
Fidu Posted May 23, 2019 Author Share Posted May 23, 2019 (edited) I'll take a look at it and thank you for the kind words. Regarding the support of others... i hope so. ps: in my opinion the simplest way of fixing this little bug would be: When state 2 or state 3 triggers the "standart" vision activates. Or the vision is reset to standart. But i just don't know the code for that (maybe) simple function. Edited May 23, 2019 by Fidu Link to comment Share on other sites More sharing options...
Fidu Posted May 24, 2019 Author Share Posted May 24, 2019 I inserted the following code (bold) into the character.lua. It seems to work at first: moggle vision is active, the character changes into state 2 and moggle vision is canceled but than the mogglevision function stops working completely and doesn't do anything anymore no matter what state i am in. Spoiler inst.AnimState:SetBuild("quanyecharumo") inst.TransformState = 2 inst.components.playervision:ForceNightVision(false) inst.components.playervision:SetCustomCCTable(nil) Link to comment Share on other sites More sharing options...
Fidu Posted May 26, 2019 Author Share Posted May 26, 2019 Another bug i noticed: Even though it's a local function in the modmain.lua... in line 387 Spoiler local function ToggleMoggleRPC(inst) if inst.TransformState == 1 then inst.components.talker:Say("I can smell it!", 2.5,true) else inst.components.talker:Say("I can't smell anything!", 2.5,true) return end inst.player_classified.mogglevision:set(not inst.components.playervision.forcenightvision) print(inst.components.playervision.forcenightvision) end AddModRPCHandler("globalfun", "togglemoggle", ToggleMoggleRPC) When i play with a totaly different character and press the "x" key the character says I can't smell anything. Even though Inuyasha is not even in the same world (i play solo in dst). modmain.lua Link to comment Share on other sites More sharing options...
Fidu Posted June 1, 2019 Author Share Posted June 1, 2019 Is there any kind soul out there who is able to fix those two things, which are actually one...? I just can't do it. And when it's fixed the mod would be perfectly fine imho. Link to comment Share on other sites More sharing options...
Ultroman Posted June 24, 2019 Share Posted June 24, 2019 (edited) On 26.5.2019 at 7:05 PM, Fidu said: Another bug i noticed: Even though it's a local function in the modmain.lua... in line 387 Hide contents local function ToggleMoggleRPC(inst) if inst.TransformState == 1 then inst.components.talker:Say("I can smell it!", 2.5,true) else inst.components.talker:Say("I can't smell anything!", 2.5,true) return end inst.player_classified.mogglevision:set(not inst.components.playervision.forcenightvision) print(inst.components.playervision.forcenightvision) end AddModRPCHandler("globalfun", "togglemoggle", ToggleMoggleRPC) When i play with a totaly different character and press the "x" key the character says I can't smell anything. Even though Inuyasha is not even in the same world (i play solo in dst). modmain.lua Your code runs for every character added to the game. What your code is doing, is saying that: if the condition (inst.TransformState == 1) is true, then it should do one thing, and if it is false, then it should do another thing. Your character is the only one that has the TransformState variable, so for all other characters it will be nil, and nil is considered to be false. Ergo, any time the value of the TransformState variable is NOT 1 (also if it is not there at all), the character will say "I can't smell anything!". Here are two examples of how to fix it: Encapsulate your if-statement within another if-statement that says: if inst.TransformState then If you do that, and make sure that your character ALWAYS has TransformState set to a value (which I think you have). Encapsulate your if-statement within another if-statement that says: if inst.prefab == "MY_CHARACTER_PREFAB_NAME" then Also, indentation Your code is incredibly hard to read, because the indentation is all over the place or completely missing. In your AddPlayerPostInit function, you should probably also start by exiting immediately if the inst is not your player character, e.g., by doing: if inst.prefab ~= "MY_CHARACTER_PREFAB_NAME" then return end I'm not sure why it would stop working. As I said, I'm having a hard time comprehending your code because of its structure, and I don't have the full mod which I would need in order to help you further. I would guess it has something to do with the way you handle the player_classified.mogglevision boolean and the net-code surrounding it. I see you have a print in there. This kind of bug should be solvable just by putting in print-statements everywhere to make a log of the state and when the nightvision is activated, when the keys are pressed etc.. Edited June 25, 2019 by Ultroman Link to comment Share on other sites More sharing options...
Fidu Posted June 25, 2019 Author Share Posted June 25, 2019 @Ultroman Thank you soooo much for replying and i love you. ^^ I was able to fix the global talking issue thanks to your advice with this: Quote local function ToggleMoggleRPC(inst) if inst.TransformState then if inst.TransformState == 1 then inst.components.talker:Say("I can smell it!", 2.5,true) else inst.components.talker:Say("I can't smell anything!", 2.5,true) return end inst.player_classified.mogglevision:set(not inst.components.playervision.forcenightvision) print(inst.components.playervision.forcenightvision) end end AddModRPCHandler("globalfun", "togglemoggle", ToggleMoggleRPC) I hope i didn't mess anything up but it seems to work now as intended. When i tried to add your postint advice the mod stopped to work completely without error message to look into. But because the mod already got some fans (besides me) and i really want this mod to work as good as possible i attached the updated version to this message. It's also the number to the workshop item as which i reuploaded it. workshop-1662813017.zip Link to comment Share on other sites More sharing options...
Ultroman Posted June 25, 2019 Share Posted June 25, 2019 (edited) You're welcome 31 minutes ago, Fidu said: When i tried to add your postint advice the mod stopped to work completely without error message to look into. Yeah, I accidentally left something extra in that line. I corrected it in the previous post. Try putting that if-statement at the top of your AddPlayerPostInit, and if that works, try doing the same for the AddPrefabPostInit for "player_classified". Edited June 25, 2019 by Ultroman Link to comment Share on other sites More sharing options...
Fidu Posted June 25, 2019 Author Share Posted June 25, 2019 ps: still don't know how i can reset the mogglevision to "normal view" if it's still active while the character changes states. believe me i tried a lot of which i thought should work but it didn't Link to comment Share on other sites More sharing options...
Ultroman Posted June 25, 2019 Share Posted June 25, 2019 (edited) 2 minutes ago, Fidu said: ps: still don't know how i can reset the mogglevision to "normal view" if it's still active while the character changes states. believe me i tried a lot of which i thought should work but it didn't Yeah, I have no idea about that one either. Might be something with the netvars. I had made a mistake in my description of the usage of the if-statement. I have corrected the description above to: Try putting that if-statement at the top of your AddPlayerPostInit, and if that works, try doing the same for the AddPrefabPostInit for "player_classified". Edited June 25, 2019 by Ultroman Link to comment Share on other sites More sharing options...
Fidu Posted June 25, 2019 Author Share Posted June 25, 2019 It does work now for the AddPlayerPostInit, but does not work when i add it to the AddPrefabPostInit Quote AddPrefabPostInit("player_classified", function(inst) if inst.prefab ~= "quanyecha" then inst.mogglevision = GLOBAL.net_bool(inst.GUID, "setmogglevision", "setmogglevisiondirty") inst.mogglevision:set(false) inst:DoTaskInTime(2 * GLOBAL.FRAMES, RegisterModNetListeners) -- delay two more FRAMES to ensure the original NetListeners to run first. end) Link to comment Share on other sites More sharing options...
Ultroman Posted June 26, 2019 Share Posted June 26, 2019 You're missing an 'end'. AddPrefabPostInit("player_classified", function(inst) if inst.prefab ~= "quanyecha" then inst.mogglevision = GLOBAL.net_bool(inst.GUID, "setmogglevision", "setmogglevisiondirty") inst.mogglevision:set(false) end inst:DoTaskInTime(2 * GLOBAL.FRAMES, RegisterModNetListeners) -- delay two more FRAMES to ensure the original NetListeners to run first. end) Link to comment Share on other sites More sharing options...
Fidu Posted June 26, 2019 Author Share Posted June 26, 2019 Oh shoot... ofc, you're right. my bad thank you very much. Works. 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