Jump to content

Beard heating abillity


Recommended Posts

@dudedudedude, you can put this in your modmain.lua:

local function beardpostinit(self)
	local OldShave = self.Shave
	self.Shave = function(self, who, withwhat)
		if who == self.inst and who.prefab == "yourcharacter" then
			local SANITYBONUS = 0
			local sanitysmall = GLOBAL.TUNING.SANITY_SMALL
			GLOBAL.TUNING.SANITY_SMALL = SANITYBONUS
			local shaved, reason = OldShave(self, who, withwhat)
			GLOBAL.TUNING.SANITY_SMALL = sanitysmall
			return shaved, reason
		else
			return OldShave(self, who, withwhat)
		end
	end

end

AddComponentPostInit("beard", beardpostinit)

Or try something more elegant.

Link to comment
Share on other sites

3 hours ago, DarivenCZ said:

And now i would like that in every phase of the beard my character will have different stats (health,sanity,hunger).

Thanks for Answer

local function beardpostinit(self)
	local OldShave = self.Shave
	self.Shave = function(self, who, withwhat)
		if who == self.inst and who.prefab == "yourcharacter" then
			local SANITYBONUS = (GLOBAL.TheWorld.state.isday and 0) or (GLOBAL.TheWorld.state.isdusk and 5) or -50
			local sanitysmall = GLOBAL.TUNING.SANITY_SMALL
			GLOBAL.TUNING.SANITY_SMALL = SANITYBONUS
			local shaved, reason = OldShave(self, who, withwhat)
			GLOBAL.TUNING.SANITY_SMALL = sanitysmall
			if shaved and who.components.health and not who:HasTag("playerghost") then
				local HEALTHBONUS = (GLOBAL.TheWorld.state.isday and 10) or (GLOBAL.TheWorld.state.isdusk and -20) or 30
				who.components.health:DoDelta(HEALTHBONUS)
			end
			return shaved, reason
		else
			return OldShave(self, who, withwhat)
		end
	end
end

AddComponentPostInit("beard", beardpostinit)

Untested.

Link to comment
Share on other sites

Thanks for help alainmcd I really appreciate it. I have one and last thing. What means "AddcomponentPostInIt is not declared". I am still new in programming dont starve mods and I do not know what I have to do

Link to comment
Share on other sites

It means it can't find AddcomponentPostInIt. Lua is case sensitive, so AddcomponentPostInIt is not the same as AddComponentPostInit. AddComponentPostInit is a special function that allows your mod to modify or extend a certain component; its first argument is the component to manipulate, the second argument should be a function to apply to said component. AddPrefabPostInit does the same for prefabs.

Link to comment
Share on other sites

22 hours ago, alainmcd said:

local function beardpostinit(self)
	local OldShave = self.Shave
	self.Shave = function(self, who, withwhat)
		if who == self.inst and who.prefab == "yourcharacter" then
			local SANITYBONUS = (GLOBAL.TheWorld.state.isday and 0) or (GLOBAL.TheWorld.state.isdusk and 5) or -50
			local sanitysmall = GLOBAL.TUNING.SANITY_SMALL
			GLOBAL.TUNING.SANITY_SMALL = SANITYBONUS
			local shaved, reason = OldShave(self, who, withwhat)
			GLOBAL.TUNING.SANITY_SMALL = sanitysmall
			if shaved and who.components.health and not who:HasTag("playerghost") then
				local HEALTHBONUS = (GLOBAL.TheWorld.state.isday and 10) or (GLOBAL.TheWorld.state.isdusk and -20) or 30
				who.components.health:DoDelta(HEALTHBONUS)
			end
			return shaved, reason
		else
			return OldShave(self, who, withwhat)
		end
	end
end

AddComponentPostInit("beard", beardpostinit)

Untested.

Is there anything else I have to rename except yourcharacter ? And thanks for the awnser.

Edited by DarivenCZ
Link to comment
Share on other sites

Still nothing. The Warning sreen still tells "variable AddComponentInit is not declared" have i done something wrong ?

my characters name is wintel :

local function beardpostinit(self)
    local OldShave = self.Shave
    self.Shave = function(self, who, withwhat)
        if who == self.inst and who.prefab == "wintel" then
            local SANITYBONUS = (GLOBAL.TheWorld.state.isday and 0) or (GLOBAL.TheWorld.state.isdusk and 5) or -50
            local sanitysmall = GLOBAL.TUNING.SANITY_SMALL
            GLOBAL.TUNING.SANITY_SMALL = SANITYBONUS
            local shaved, reason = OldShave(self, who, withwhat)
            GLOBAL.TUNING.SANITY_SMALL = sanitysmall
            if shaved and who.components.health and not who:HasTag("playerghost") then
                local HEALTHBONUS = (GLOBAL.TheWorld.state.isday and 10) or (GLOBAL.TheWorld.state.isdusk and -20) or 30
                who.components.health:DoDelta(HEALTHBONUS)
            end
            return shaved, reason
        else
            return OldShave(self, who, withwhat)
        end
    end
end

AddComponentPostInit("beard", beardpostinit)
thanks for help

Edited by DarivenCZ
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...