Jump to content

Need help double check what might be dead code


Recommended Posts

The title says it all. I'm not the most fluent in lua, I just do this for fun and as a challenge, and I do manage fairly okay for the most part. Right now though I'm working on a character mod with some abilities I've never messed around with and ran into an issue I'd like a second opinion on.

Basically what I'm trying to do is make it so that the character gets slower and weaker at low sanity. I've got code, it doesn't give me an error message. But I very strongly suspect it's not actually doing anything/what it should, or that the scaling and effect is way weaker than I'd like. There's no glitching or anything but especially the walking speed (easier to tell) doesn't seem to be changing at all, no matter how i change the values. It's somewhat of a patchwork code. Could someone check it if there's any noticeable flaws I missed? Or any other way for me to fix it? Or is there a smarter way to do this?

-- ABOVE LOCAL COMMON_POSTINIT

-- sanity damage and speed scaling
local function sanitydelta(inst) 
  if inst.components.sanity.current >= 100 then
      inst.components.combat.damagemultiplier = 1
	  inst.components.locomotor.SetExternalSpeedMultiplier = 1.5
  elseif inst.components.sanity.current > 75 then
      inst.components.combat.damagemultiplier = 0.75
	  inst.components.locomotor.SetExternalSpeedMultiplier = 1
  elseif inst.components.sanity.current < 50 then
    inst.components.combat.damagemultiplier = 0.50
	inst.components.locomotor.SetExternalSpeedMultiplier = 0.50
   end
end
                                            
-- IN LOCAL MASTER_POSTINIT:
                                            
inst:ListenForEvent("sanitydelta", sanitydelta) -- sanity damage and speed scaling

And then just in case it might be necessary, here's the whole prefab folder. I'd appreciate any at all help and tips!  

hollow.lua

Link to comment
Share on other sites

well im not sure but you can try this

local function sanitydelta(inst) 
  if inst.components.sanity.current >= 100 then
      inst.components.combat.damagemultiplier = 1
	  inst.components.locomotor.SetExternalSpeedMultiplier = 1.5
  elseif inst.components.sanity.current >= 75 and < 100 then
      inst.components.combat.damagemultiplier = 0.75
	  inst.components.locomotor.SetExternalSpeedMultiplier = 1
  elseif inst.components.sanity.current < 50 then
    inst.components.combat.damagemultiplier = 0.50
	inst.components.locomotor.SetExternalSpeedMultiplier = 0.50
   end
end

try this and let me know if there is any problem

Edited by AkaiNight
Link to comment
Share on other sites

I believe setexternalspeedmultiplier is a function that takes in 2 arguments a key and a value.

What it seems you are doing is overriding the function and turning it into a static number. Your lucky you haven't crashed your game. Because if anything else called that function it would of crashed the game.

I'll edit this post later with the information on it but I believe its inst.components.locomotor:SetExternalSpeedMultiplier(inst, key, value) with key being a unique name that will override other multipliers with that key and value being the multiplier.

The function automatically removes the multiplier if the value is 1.

  • Like 1
Link to comment
Share on other sites

10 hours ago, snakeyarts said:

@IronHunter Oh woah yea, I'll be honest I never would have caught that, If that's the case I'd very much appreciate that information, since this isn't really something I know much of anything about.

I don't know much about coding but why not using 

	inst.components.locomotor.walkspeed = 4.6
	inst.components.locomotor.runspeed = 7

something like this? I believe this will not cause any problems

Link to comment
Share on other sites

2 hours ago, AkaiNight said:

I don't know much about coding but why not using 


	inst.components.locomotor.walkspeed = 4.6
	inst.components.locomotor.runspeed = 7

something like this? I believe this will not cause any problems

You could use those, but if they ever get changed in game by some other code then your code might conflict.

SetExternalMultiplier is cleaner in its unlikely other code will use the same key as your multiplier.

It really just depends how precise you want your stat changes to be. Maybe you only want to make run speed faster and have no effect on walk speed. Also it depends on what mod compatibility you want the mod to have as some mods might change default speeds for characters.

The information I provided is also accurate. It is a function with those parameters.

  • Like 1
Link to comment
Share on other sites

2 hours ago, IronHunter said:

You could use those, but if they ever get changed in game by some other code then your code might conflict.

SetExternalMultiplier is cleaner in its unlikely other code will use the same key as your multiplier.

It really just depends how precise you want your stat changes to be. Maybe you only want to make run speed faster and have no effect on walk speed. Also it depends on what mod compatibility you want the mod to have as some mods might change default speeds for characters.

The information I provided is also accurate. It is a function with those parameters.

I'm using a code for stat changes on moon phases like attack and movement speed and it works fine for me. Just to know

Link to comment
Share on other sites

56 minutes ago, AkaiNight said:

I'm using a code for stat changes on moon phases like attack and movement speed and it works fine for me. Just to know

Ya there is nothing wrong with it, there are multiple ways to get to a similar outcome, the original post was Finding the error in the code which was the SetExternalSpeedMultiplier function was being overriden.

Edit: read the attached lua file
Ya just change those lines where you override the SetExternalSpeedMultiplier to just using it
 

inst.components.locomotor:SetExternalSpeedMultiplier(inst, "hollow_speed_mod", 1.50)

like you have in your onbecamehuman and onbecameghost functions, just change the multiplier to your desired ones.

Edited by IronHunter
read the lua file
  • Like 3
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...