Jump to content

Recommended Posts

I'm working on a character mod and had a few ideas for them but I'm not sure how to implement them in the lua file.

Firstly, I want to decrease the movement penalty of carrying heavy objects from 0.15 to 0.3. I also want to negate the movement penalty of carrying piggyback completely and decrease the movement penalty of wearing marble armor from 0.7 to 0.9.

Additionally, I want my character to be able to consume electrical doodads to double her movement and action speed for 60 seconds, while also doubling the rate of losing hunger with a line of dialogue confirming the effect.

Finally, if my character is struck by lightning, I want her to take only a quarter of the health damage while also applying the same effect as consuming an electrical doodad but for 120 seconds with a separate line of dialogue confirming the effect. I also want to increase the odds that this character is struck by lightning.

In regards to balancing, I want the speed buff to cancel itself if hunger dips below 50 with a line of dialogue to indicate it. If hunger is below 50, electrical doodads can't be consumed and the character will speak a line of dialogue indicating this. If struck by lightning while hunger is below 50, the effect simply won't be applied with no additional dialogue.

Any help with this would be greatly appreciated!

Edited by Devgirl_Neko

My brother/sister in christ hello, I can offer help with some of these... maybe...
I am not extremely experienced but I can offer this:

On 7/12/2022 at 7:03 PM, Devgirl_Neko said:

I want my character to be able to consume electrical doodads

This should somewhat help with this -

Spoiler

 

Go to your modmain.lua, and for starters add this line somewhere at the very top:

    GetPlayer = GLOBAL.GetPlayer

Then you should go to your CharacterName.lua and add this:

AddPrefabPostInit("transistor", function(inst)
    if GetPlayer().prefab == "YourCharacter'sNameHere" then -- replace "YourCharacter'sNameHere" with whatever your character's name is.
        inst:AddComponent("edible")
        inst.components.edible.foodtype = "ELEMENTAL" -- I can only guess that's what you'd want it to be.
        inst.components.edible.healthvalue = 0
        inst.components.edible.hungervalue = 0
        inst.components.edible.sanityvalue = 0
    end
end)

 

 

 

I'm going to be completely honest with you, this is going to be quite an undertaking for someone who isn't familiar with Lua and is kind of a hard ask for on anyone on the forums to help you with heh I can try to point you in the right direction, but I recommend trying to get in contact with someone who knows Lua who can sit down with you to make the mod together with.

For the movement speed multiplier, it looks like you could probably write a wrapper to apply your own multiplier(s) on top of whatever other multipliers may also be applying to your character. As far as keeping track of when your character has a movement speed buff of some kind (whether by eating or lightning strike) you could probably get away with saving a task to a custom instance property on your character and then having your wrapper check to see if the task exists for the multiplier to apply. Something like this:

-- Use this whenever you eat a transistor or get struck by lightning, just change the number to 120
-- You will probably want to save this to a local function in your character prefab
if inst.ModSpeedTask ~= nil then
	inst.ModSpeedTask:Cancel()
	inst.ModSpeedTask = nil
end
inst.ModSpeedTask  = GLOBAL.DoTaskInTime(60, function() inst.ModSpeedTask = nil end)

-- This enables your wrapper, this goes in your modmain
function LocomotorCompPostInit(comp)
	local _GetSpeedMultiplier = comp.GetSpeedMultiplier

	comp.GetSpeedMultiplier = function(self)
		local mult = _GetSpeedMultiplier(self)	
		local inst = self.inst

		if inst.prefab ~= "YOUR_CHARACTER_PREFAB" then
			return mult
		end

		local inventory = inst.replica.inventory
		for k, v in pairs(inventory:GetEquips()) do
			if v:HasTag("heavy") then
				mult = mult * 2 -- We go from 0.15 to 0.3, essentially doubling the mult
			end
			if v.prefab == "armormarble" then
				mult = mult / GLOBAL.TUNING.ARMORMARBLE_SLOW * 0.9 -- first we reverse the the previous mult, then add your own
			end
			if v.prefab == "piggyback" then
				mult = mult / GLOBAL.TUNING.PIGGYBACK_SPEED_MULT -- here we just undo the speed mult
			end
		end
	
		if inst.ModSpeedTask then 
			return mult * 2 -- If we have a speed task, double overall speed
		end
		return mult
	end
end
AddComponentPostInit("locomotor", LocomotorCompPostInit)


You'll still have a bit of a ways to go to get the rest of the mechanics you want, but this should at least help get you started. Keep in mind that you'll need to serialize the task if you want it to last between game sessions/shards.

Edited by w00tyd00d

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
×
  • Create New...