Jump to content

Help applying custom perks to mod?


Recommended Posts

Hey everyone! I'm pretty new to this game, and even newer to coding and modding, so I had a couple questions. I didn't really want to make a post specifically, as I didn't have an account on this site and I'm rather hesitant to make accounts on too many sites, as it gets hard to manage. But after looking for threads regarding similar questions, I found none (that could help with my exact question), and decided I should just post my own thread; so here I am with my own account lol.

so my issue is adding custom perks to a mod. I'm rather new to coding, and I'm able to figure out the mod's basic coding, but when it comes to perks, I do not know what to add to the coding, and where to put it, and if I even have to add a new line of coding.

 

I am trying to add three perks to my character in the game:

- Stronger on full belly (at 200-150 hunger, does 1.50 damage, at 149-100 hunger, does 1.25 damage, at 99-0 hunger, does 1.00 damage)

- can see in the dark

-Sanity loss rate increases when hungry (at 200-100 hunger, 1.00 loss rate, at 99-0 hunger, 2.00 loss rate)

 

I do not know what I need to add to the .lua files to be able to add these perks to the mod. I'm pretty sure they go under the character's local master_postinit somewhere, but correct me if I'm wrong. (which I probably am lol)

I do know that Wolfgang's .lua file has similar perks to the first and third perks listed above, and (Beaver)Woodie with the second, so I went through their .lua files, but I wasn't able to figure out what part of the coding causes this in either of them.

Any help would be greatly appreciated. I would love it if you could explain what I need to add, and where it needs to go. I'm not sure if I need to add a screenshot of the character's .lua file, as I am just trying to figure out what to add where, and I don't have a coding error, but if you do need a screenshot for any reason, I will gladly send it. 

Thank you so much for reading, and for providing an answer to my question if you help! It's greatly appreciated!

Link to comment
Share on other sites

The confusing thing about Wolfgang is because his "mightiness" affects a lot of different stats, the code is split up among several places. The relevant code is in onhungerchange and applymightiness. Wolfgang also has code which turns off his mightiness while he's a ghost so he doesn't suddenly become wimpy and change into his wimpy human form as a ghost, which you probably won't need if you're not swapping graphics. You will want something like this:

local function onhungerchange(inst, data, forcesilent)
    if inst.components.hunger.current > 150 then
    	inst.components.combat.damagemultiplier = 1.5
    elseif . . .
    
end

Then in master_init, add:

inst:ListenForEvent("hungerdelta", onhungerchange)

 

Link to comment
Share on other sites

thank you so much for a quick reply, very helpful! I'd just like to ask one more thing (so sorry for another question); do you know if master_init and master_postinit are the same thing/work the same way? My character's .lua file has a 'master_postinit' in the place of other characters' 'master_init', and I don't know if that changes how things work.

 

thank you again SO MUCH for your help, you'e been great! :)

Link to comment
Share on other sites

For Nightvision:

--put these somewhere above common_postinit
local NIGHTVISION_COLOURCUBES =
{
    day = "images/colour_cubes/ruins_light_cc.tex",
    dusk = "images/colour_cubes/ruins_dim_cc.tex",
    night = "images/colour_cubes/purple_moon_cc.tex",
    full_moon = "images/colour_cubes/purple_moon_cc.tex",
}

local function SetNightVision(inst, enable)
    if TheWorld.state.isnight or TheWorld:HasTag("cave") then
        inst.components.playervision:ForceNightVision(true)
        inst.components.playervision:SetCustomCCTable(NIGHTVISION_COLOURCUBES)
    else
        inst.components.playervision:ForceNightVision(false)
        inst.components.playervision:SetCustomCCTable(nil)
    end
end

--put this in your common_postinit:
inst:WatchWorldState( "isday", function() SetNightVision(inst) end)
  	inst:WatchWorldState( "isdusk", function() SetNightVision(inst) end)
  	inst:WatchWorldState( "isnight", function() SetNightVision(inst)  end)
	inst:WatchWorldState( "iscaveday", function() SetNightVision(inst) end)
  	inst:WatchWorldState( "iscavedusk", function() SetNightVision(inst) end)
  	inst:WatchWorldState( "iscavenight", function() SetNightVision(inst)  end)
	
	SetNightVision(inst)

 

Link to comment
Share on other sites

4 hours ago, DarkKingBoo said:

For Nightvision:


--put these somewhere above common_postinit
local NIGHTVISION_COLOURCUBES =
{
    day = "images/colour_cubes/ruins_light_cc.tex",
    dusk = "images/colour_cubes/ruins_dim_cc.tex",
    night = "images/colour_cubes/purple_moon_cc.tex",
    full_moon = "images/colour_cubes/purple_moon_cc.tex",
}

local function SetNightVision(inst, enable)
    if TheWorld.state.isnight or TheWorld:HasTag("cave") then
        inst.components.playervision:ForceNightVision(true)
        inst.components.playervision:SetCustomCCTable(NIGHTVISION_COLOURCUBES)
    else
        inst.components.playervision:ForceNightVision(false)
        inst.components.playervision:SetCustomCCTable(nil)
    end
end

--put this in your common_postinit:
inst:WatchWorldState( "isday", function() SetNightVision(inst) end)
  	inst:WatchWorldState( "isdusk", function() SetNightVision(inst) end)
  	inst:WatchWorldState( "isnight", function() SetNightVision(inst)  end)
	inst:WatchWorldState( "iscaveday", function() SetNightVision(inst) end)
  	inst:WatchWorldState( "iscavedusk", function() SetNightVision(inst) end)
  	inst:WatchWorldState( "iscavenight", function() SetNightVision(inst)  end)
	
	SetNightVision(inst)

 

thank you SO MUCH for this; I did not play long enough to night to see if it actually worked (I'm doing the art for the mod right now and didn't want to spend too much time on it until after) so thank you very much for taking your time to give me this :) you have been most helpful!

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...