icantevenname Posted January 8, 2019 Share Posted January 8, 2019 I'm planning on making a mod of Risky Boots and figure it'd be fun to have her lose sanity when close to certain characters, like my other Shantae character mods, hero types, Willow (she hates the girl scouts), ect. Is there a way to have this happen that's easy to edit when more modded characters show up? I think it's possible with a table or something... Link to comment Share on other sites More sharing options...
Norfeder Posted January 8, 2019 Share Posted January 8, 2019 local range = TUNING.SANITY_EFFECT_RANGE local count = 0 local ents = TheSim:FindEntities(x, y, z, range) inst:DoPeriodicTask(0, function() for k,v in pairs(ents) do if v.prefab == " The guy I really hate " then count = count + 1 end end if count > 0 then inst.components.sanity.dapperness = count * TUNING.DAPPERNESS_SMALL * -1 else inst.components.sanity.dapperness = 0 end count = 0 end) This should do the job. Link to comment Share on other sites More sharing options...
icantevenname Posted January 21, 2019 Author Share Posted January 21, 2019 (edited) On 1/8/2019 at 4:45 AM, Norfeder said: local range = TUNING.SANITY_EFFECT_RANGE local count = 0 local ents = TheSim:FindEntities(x, y, z, range) inst:DoPeriodicTask(0, function() for k,v in pairs(ents) do if v.prefab == " The guy I really hate " then count = count + 1 end end if count > 0 then inst.components.sanity.dapperness = count * TUNING.DAPPERNESS_SMALL * -1 else inst.components.sanity.dapperness = 0 end count = 0 end) This should do the job. Err... I had to change the X Y Z because the game yelled at me for not giving them a value. And if I only replace range with a number, a glitched-out lobby happens. Edited January 22, 2019 by icantevenname More info Link to comment Share on other sites More sharing options...
Ultroman Posted March 1, 2019 Share Posted March 1, 2019 (edited) To get the x, y and z, you just need to do this: local x,y,z = inst.Transform:GetWorldPosition() where inst is your character. What do you mean by "glitched out lobby"? You also need to replace " The guy I really hate " with the name of the character to want to hate. And if I'm not mistaken, you need to move this line local ents = TheSim:FindEntities(x, y, z, range) to be right after this line inst:DoPeriodicTask(0, function() otherwise it'll never update the ents-collection. Edited April 19, 2019 by Ultroman Link to comment Share on other sites More sharing options...
icantevenname Posted March 2, 2019 Author Share Posted March 2, 2019 15 hours ago, Ultroman said: To get the x, y and z, you just need to do this: local x,y,z = inst:GetPosition() where inst is your character. What do you mean by "glitched out lobby"? You also need to replace " The guy I really hate " with the name of the character to want to hate. And if I'm not mistaken, you need to move this line local ents = TheSim:FindEntities(x, y, z, range) to be right after this line inst:DoPeriodicTask(0, function() otherwise it'll never update the ents-collection. Not sure if I did it right... Link to comment Share on other sites More sharing options...
Ultroman Posted March 2, 2019 Share Posted March 2, 2019 (edited) You deleted the line local ents = TheSim:FindEntities(x, y, z, range) As I said, move that line just under this line inst:DoPeriodicTask(0, function() Obviously, now that you've put in the line local x,y,z = inst.Transform:GetWorldPosition() just below that line, it should instead be: inst:DoPeriodicTask(0, function() local x,y,z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, range) Just updated the answer. Edited April 19, 2019 by Ultroman Link to comment Share on other sites More sharing options...
icantevenname Posted March 2, 2019 Author Share Posted March 2, 2019 3 hours ago, Ultroman said: You deleted the line local ents = TheSim:FindEntities(x, y, z, range) As I said, move that line just under this line inst:DoPeriodicTask(0, function() Obviously, now that you've put in the line local x,y,z = inst:GetPosition() just below that line, it should instead be: inst:DoPeriodicTask(0, function() local x,y,z = inst:GetPosition() local ents = TheSim:FindEntities(x, y, z, range) Just updated the answer. Now it's saying "calling 'FindEntities' on bad self (number expected, got table) Is the local range not enough? Link to comment Share on other sites More sharing options...
Ultroman Posted March 2, 2019 Share Posted March 2, 2019 If your code is in modmain.lua, you probably have to do GLOBAL.TheSim instead of just TheSim Link to comment Share on other sites More sharing options...
icantevenname Posted March 2, 2019 Author Share Posted March 2, 2019 1 hour ago, Ultroman said: If your code is in modmain.lua, you probably have to do GLOBAL.TheSim instead of just TheSim I was supposed to put this in the modmain all this time? Link to comment Share on other sites More sharing options...
Ultroman Posted March 2, 2019 Share Posted March 2, 2019 No. Just saying that there's a difference between how it's used depending on whether or not it is used in modmain.lua Post a zip of your mod with your newest code (the one giving the last error) so I can take a look. Link to comment Share on other sites More sharing options...
icantevenname Posted March 3, 2019 Author Share Posted March 3, 2019 2 hours ago, Ultroman said: No. Just saying that there's a difference between how it's used depending on whether or not it is used in modmain.lua Post a zip of your mod with your newest code (the one giving the last error) so I can take a look. Here. Risky.zip Link to comment Share on other sites More sharing options...
Ultroman Posted March 3, 2019 Share Posted March 3, 2019 Change it to this inst:DoPeriodicTask(0, function(inst) local x,y,z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, range) Link to comment Share on other sites More sharing options...
icantevenname Posted March 4, 2019 Author Share Posted March 4, 2019 On 3/2/2019 at 11:28 PM, Ultroman said: Change it to this inst:DoPeriodicTask(0, function(inst) local x,y,z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, range) Works now! Now to see if it can respond to more than one type of character. Link to comment Share on other sites More sharing options...
Ultroman Posted March 4, 2019 Share Posted March 4, 2019 It can Link to comment Share on other sites More sharing options...
icantevenname Posted March 4, 2019 Author Share Posted March 4, 2019 26 minutes ago, Ultroman said: It can If it can, then I don't see it... If I use "or", it affects Risky even when no one listed is nearby. Or in the world. If I use "and", it only affects Risky when everyone listed is nearby. If I use ("shantae") + ("willow") + ect..., I get a crash report. If I use ",", I get another crash report. Link to comment Share on other sites More sharing options...
Ultroman Posted March 4, 2019 Share Posted March 4, 2019 I don't know what you're talking about Show me your code, and tell me what you want it to do. Link to comment Share on other sites More sharing options...
icantevenname Posted March 5, 2019 Author Share Posted March 5, 2019 16 hours ago, Ultroman said: I don't know what you're talking about Show me your code, and tell me what you want it to do. I want it so that characters other than Shantae cause Risky to lose Sanity when nearby. But when I set it up like this, she loses sanity regardless if anyone's nearby. Link to comment Share on other sites More sharing options...
IronHunter Posted March 5, 2019 Share Posted March 5, 2019 (edited) Well your operators are a little incorrect. You are doing a comparison properly in the first one but not the other 3 prefabs. I would suggest just making a table containing all your strings outside above your loop Local hates = { "shantae" = true, "willow" = true, Etc } --Then just do one comparison if hates[v.prefab] then count = count +1 end This makes it easier to update as you just add your new characters to the table. Rather than having to make that if statement longer. Edited March 5, 2019 by IronHunter Also doing this on mobile sucks... Link to comment Share on other sites More sharing options...
icantevenname Posted March 5, 2019 Author Share Posted March 5, 2019 1 hour ago, IronHunter said: Well your operators are a little incorrect. You are doing a comparison properly in the first one but not the other 3 prefabs. I would suggest just making a table containing all your strings outside above your loop Local hates = { "shantae" = true, "willow" = true, Etc } --Then just do one comparison if hates[v.prefab] then count = count +1 end This makes it easier to update as you just add your new characters to the table. Rather than having to make that if statement longer. Had a feeling a table would work fine. Just only needed to make a tweak here an' there, there already was a hate list for vegetables (Risky hates vegetables) so I had to rename the hated characters table and needed to remove the "". It works just fine now! Thanks, you lot! Link to comment Share on other sites More sharing options...
Ultroman Posted March 5, 2019 Share Posted March 5, 2019 (edited) Just to complete the original code (not sure what you ended up with), and support a few hated characters, you'd need to do: if v.prefab == "shantae" or v.prefab == "willow" then count = count + 1 end I thought it was only going to be one hated character. To support more hated characters and allow for easier extendability, IronHunter's solution is more elegant. Edited March 5, 2019 by Ultroman Link to comment Share on other sites More sharing options...
MetaGiga Posted April 18, 2019 Share Posted April 18, 2019 I might use the opposite of this for a certain character. For uh. Reasons. 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