Jump to content

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.

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.

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.

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

@alainmcd Have you got any idea why the beard does not show on a character despite the game starting up normally? I deleted the extra features I got from here so it was just basic Wilson beard, but the beard still did not show up on my test character in game.

@DarivenCZ, changing yourcharacter should be enough. Change the values as you please.

@dudedudedude, no, since I haven't seen your code. Even then, I'm hardly the person to ask about animations. Have you used the beard component's AddCallBack? AnimState:OverrideSymbol?

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

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