Jump to content

How to remove certain crafting recipe for character?


Recommended Posts

...Hello, I have a problem... So, you see... my character's supposed to lose the ability to craft certain items (or all items) when it goes insane and I put code like this before.

-- Character can craft all items
inst.components.builder.science_bonus = 666
inst.components.builder.magic_bonus = 666
inst.components.builder.ancient_bonus = 666
inst.components.builder.shadow_bonus = 666
-- You've become Insane, you lost all crafting recipes.
	inst:ListenForEvent("goinsane", function(inst, data)
	inst.components.talker:Say(GetString(inst, "ANNOUNCE_INSANE"))
	inst.components.builder.science_bonus = -666
	inst.components.builder.magic_bonus = -666
	inst.components.builder.ancient_bonus = -666
	inst.components.builder.shadow_bonus = -666
    end)
-- You've become sane again, you regain all crafting recipes.
	inst:ListenForEvent("gosane", function(inst, data)
	inst.components.talker:Say(GetString(inst, "ANNOUNCE_SANE"))
	inst.components.builder.science_bonus = 666
	inst.components.builder.magic_bonus = 666
	inst.components.builder.ancient_bonus = 666
	inst.components.builder.shadow_bonus = 666
    end)

This code worked before but not anymore (it's incompatible with caves). So I was wondering is there something I can do like "Inst:RemoveRecipe"axe"" or remove the crafting tab?  Help would be appreciated very, very much :D!!!

Edited by SuperDavid
Link to comment
Share on other sites

When caverns are enabled the server enters shard mode, meaning the overworld is a shard and you are a full client connected to a full server instead of the normal half/half client/server you are used to.

 

Make sure the mod you're working on is one that is classified as a server mod that all clients need, and have it enabled in the server startup mods tab.

Link to comment
Share on other sites

Try this out.

local UpdateTabsInsanity = function() print("lol, closures") end
local function EditTabsForInsane(self)
	UpdateTabsInsanity = function(show, player)
		if player and player == GLOBAL.ThePlayer then
			for k, v in pairs(self.tabs) do
				if show then
					v:Show()
				else
					v:Hide()
				end				
			end
		end
	end
end
AddClassPostConstruct("widgets/tabgroup", EditTabsForInsane)

local function OnInsaneTabs(inst)
	inst.triggertabupdate:set(false)
end
local function OnSaneTabs(inst)
	inst.triggertabupdate:set(true)
end
local function UpdateOnJoin(inst)
	inst.triggertabupdate:set(inst.components.sanity:IsSane())
end
local function UpdateTabsBySanity(inst)
	UpdateTabsInsanity(inst.triggertabupdate:value(), inst)
end
local function EditBuilder(inst)
	inst.triggertabupdate = GLOBAL.net_bool(inst.GUID, "special.insane", "checktabsanity")
	inst.triggertabupdate:set_local(false)
	inst:ListenForEvent("checktabsanity", UpdateTabsBySanity)
	if inst.components.builder then
		local _DoBuild = inst.components.builder.DoBuild
		inst.components.builder.DoBuild = function(self, recname, pt, rotation, skin)
			if not inst.components.sanity:IsSane() then
				return false
			end
			return _DoBuild(self, recname, pt, rotation, skin)
		end
		inst:ListenForEvent("goinsane", OnInsaneTabs)
		inst:ListenForEvent("gosane", OnSaneTabs)
		inst.components.builder.science_bonus = 3
		inst.components.builder.magic_bonus = 3
		inst.components.builder.ancient_bonus = 4
		inst.components.builder.shadow_bonus = 4
		inst:DoTaskInTime(0, UpdateOnJoin)
	end
end
AddPrefabPostInit("wilson", EditBuilder)

It gives you all the bonuses to be able to craft everything.

But if you go insane, your tabs poof away.

Like when using 666 and -666 as a host.

This works by putting a function that will hide your tabs inside the TabGroup class, and then manipulating them using a network variable that holds true or false. When its value changes, it triggers the hiding/showing of tabs.

As always, modmain. Change "wilson" for your character.

A bit messy, but it makes it look like how it looked originally with the server only code.

 

Note: there are shorter ways to disable particular recipes, hiding them. This is useful to make tabs go away.

Edited by DarkXero
Link to comment
Share on other sites

You're so amazing DarkXero, I definitely will give you credit for all of this code you make for me when I finish my character :)!!! If you don't mind if I can ask for help with something else because I feel like my next problem isn't big enough to make a topic for it. So, I wanted my character when his insane to break trees, rocks, shovel and hammer things faster while using weapon attack animations, so I did it by putting inst:AddTag("beaver") to make him break trees, rocks, dig and hammer things faster and inst:AddTag("beaver") also made his chop, mine, dig & hammer animations into weapon attack animations which I really like, now the problem is that inst:AddTag("beaver") also changes his fist attack (when he attacks with no weapon) into the equip weapon attack animation which I don't want because it makes his arm his attacking with disappear for a couple seconds... I tried changing it into the punch anim in SGWilson like this  

 elseif inst:HasTag("beaver") then
                inst.sg.statemem.isbeaver = true
                inst.AnimState:PlayAnimation("punch") -- Was "atk_pre" before
                inst.AnimState:PushAnimation("atk", false)
                inst.SoundEmitter:PlaySound("dontstarve/wilson/attack_whoosh")
                cooldown = 13 * FRAMES
            else

but nothing happened :(... I want him to keep the beaver tag perks but I want his punch anim to be a punch anim, is there a way I can force that or will his arm forever have texture glitches? I appreciate your help a lot DarkXero, you have lots of coding wisdom it's like you know everything about Don't Starve coding, so thank you very much for everything & it's okay if you don't know how to fix this problem :D!!!!!!!!!!

Edited by SuperDavid
Link to comment
Share on other sites

1 hour ago, SuperDavid said:

I want him to keep the beaver tag perks but I want his punch anim to be a punch anim, is there a way I can force that or will his arm forever have texture glitches?

local function HackState(sg, state)
	local _attack_onenter = sg.states[state]["onenter"]
	sg.states[state]["onenter"] = function(inst)
		_attack_onenter(inst)
		local needs_fix = inst.prefab == "mycharacterprefab" and not inst.replica.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.HANDS)
		if needs_fix then
			inst.sg.statemem.isbeaver = nil
			inst.AnimState:PlayAnimation("punch")
			inst.sg:SetTimeout(24 * GLOBAL.FRAMES)
		end
	end
end
local function HackAttack(sg)
	HackState(sg, "attack")
	HackState(sg, "dojostleaction")
end
AddStategraphPostInit("wilson", HackAttack)
AddStategraphPostInit("wilson_client", HackAttack)

Use this in modmain.

Do not replace "wilson", since all players use the wilson stategraph.

Replace "mycharacterprefab" with yours.

Link to comment
Share on other sites

I can't thank you enough DarkXero!!!!! You're such an  super amazing guy helping someone like me with all my coding questions, writing them all down for me and telling me exactly what to do, you really are so awesome, SO AWESOME :D:D:D!!!!!!!!!

Link to comment
Share on other sites

Hello, DarkXero sorry to bother you after a while... That code you gave me 

-- Lose all crafting on insanity.
local UpdateTabsInsanity = function() print("lol, closures") end
local function EditTabsForInsane(self)
	UpdateTabsInsanity = function(show, player)
		if player and player == GLOBAL.ThePlayer then
			for k, v in pairs(self.tabs) do
				if show then
					v:Show()
				else
					v:Hide()
				end				
			end
		end
	end
end
AddClassPostConstruct("widgets/tabgroup", EditTabsForInsane)

local function OnInsaneTabs(inst)
	inst.triggertabupdate:set(false)
end
local function OnSaneTabs(inst)
	inst.triggertabupdate:set(true)
end
local function UpdateOnJoin(inst)
	inst.triggertabupdate:set(inst.components.sanity:IsSane())
end
local function UpdateTabsBySanity(inst)
	UpdateTabsInsanity(inst.triggertabupdate:value(), inst)
end
local function EditBuilder(inst)
	inst.triggertabupdate = GLOBAL.net_bool(inst.GUID, "special.insane", "checktabsanity")
	inst.triggertabupdate:set_local(false)
	inst:ListenForEvent("checktabsanity", UpdateTabsBySanity)
	if inst.components.builder then
		local _DoBuild = inst.components.builder.DoBuild
		inst.components.builder.DoBuild = function(self, recname, pt, rotation, skin)
			if not inst.components.sanity:IsSane() then
				return false
			end
			return _DoBuild(self, recname, pt, rotation, skin)
		end
		inst:ListenForEvent("goinsane", OnInsaneTabs)
		inst:ListenForEvent("gosane", OnSaneTabs)
		inst.components.builder.science_bonus = 3
		inst.components.builder.magic_bonus = 3
		inst.components.builder.ancient_bonus = 4
		inst.components.builder.shadow_bonus = 4
		inst:DoTaskInTime(0, UpdateOnJoin)
	end
end
AddPrefabPostInit("adam", EditBuilder)

local UpdateTabsInsanity = function() print("lol, closures") end
local function EditTabsForInsane(self)
	UpdateTabsInsanity = function(show, player)
		if player and player == GLOBAL.ThePlayer then
			for k, v in pairs(self.tabs) do
				if show then
					v:Show()
				else
					v:Hide()
				end				
			end
		end
	end
end
AddClassPostConstruct("widgets/tabgroup", EditTabsForInsane)

local function OnInsaneTabs(inst)
	inst.triggertabupdate:set(false)
end
local function OnSaneTabs(inst)
	inst.triggertabupdate:set(true)
end
local function UpdateOnJoin(inst)
	inst.triggertabupdate:set(inst.components.sanity:IsSane())
end
local function UpdateTabsBySanity(inst)
	UpdateTabsInsanity(inst.triggertabupdate:value(), inst)
end
local function EditBuilder(inst)
	inst.triggertabupdate = GLOBAL.net_bool(inst.GUID, "special.insane", "checktabsanity")
	inst.triggertabupdate:set_local(false)
	inst:ListenForEvent("checktabsanity", UpdateTabsBySanity)
	if inst.components.builder then
		local _DoBuild = inst.components.builder.DoBuild
		inst.components.builder.DoBuild = function(self, recname, pt, rotation, skin)
		if not inst.components.sanity:IsSane() then
		return false
	    end
	    return _DoBuild(self, recname, pt, rotation, skin)
		end
		inst:ListenForEvent("goinsane", OnInsaneTabs)
		inst:ListenForEvent("gosane", OnSaneTabs)
		inst.components.builder.science_bonus = 3
		inst.components.builder.magic_bonus = 3
		inst.components.builder.ancient_bonus = 4
		inst.components.builder.shadow_bonus = 4
		inst:DoTaskInTime(0, UpdateOnJoin)
	end
end
AddPrefabPostInit("wilson", EditBuilder)

it makes all characters on the server be able to craft everything and they all lose their crafting recipes when they go insane which's kinda bad for other characters playing with my character... Is there a way to make it that it only affects my character? And sorry for replying to you on a kinda old post I hope you can help me :)...

Link to comment
Share on other sites

7 hours ago, SuperDavid said:

it makes all characters on the server be able to craft everything and they all lose their crafting recipes when they go insane which's kinda bad for other characters playing with my character... Is there a way to make it that it only affects my character? And sorry for replying to you on a kinda old post I hope you can help me

Can you give me reproduction steps?

Also, the code you posted has a AddPrefabPostInit for Adam and another for Wilson.

Link to comment
Share on other sites

6 minutes ago, SuperDavid said:

I'm so, so sorry but I fixed the problem, so sorry for bothering you & thanks so much for replying :)...

And how ? That would help future people when the thread gets achieved and they have similar problems =)

Edited by SenpaiArtorias
Link to comment
Share on other sites

..........I actually didn't fix it... I think the problem's not that big of a deal, last night I was really tired & thought it might be a huge problem but it isn't now that I think about it. The problem is if you enable my character mod the host of the server if he/she picks a character that isn't my character will still receive my character's crafting bonus and losing them on insanity, but the solution's simple you just disable my mod character if you don't want to play with him :) or you can have a Wilson that can craft everything and lose it all on insanity...

Edited by SuperDavid
Link to comment
Share on other sites

27 minutes ago, SuperDavid said:

..........I actually didn't fix it... I think the problem's not that big of a deal, last night I was really tired & thought it might be a huge problem but it isn't now that I think about it. The problem is if you enable my character mod the host of the server if he/she picks a character that isn't my character will still receive my character's crafting bonus and losing them on insanity, but the solution's simple you just disable my mod character if you don't want to play with him :) or you can have a Wilson that can craft everything and lose it all on insanity...

... what if you want to play TOGETHER with someone, and you don't pick the same characters... that makes no sense..

Edited by Aquaterion
Link to comment
Share on other sites

8 minutes ago, SuperDavid said:

Well if that happens I guess nothing can be done :(...

Other than, you know, fixing it:

 

8 hours ago, DarkXero said:

Can you give me reproduction steps?

Also, the code you posted has a AddPrefabPostInit for Adam and another for Wilson.

 

Link to comment
Share on other sites

2 minutes ago, SuperDavid said:

I kinda don't know what that means, hahaha :).........

Upload your entire mod to the forums and then explain what you did to make the bug happen so we can replicate the steps to make it happen ourselves too.

Link to comment
Share on other sites

Okay, the bug is when my character mod is enabled the host is character will be able to craft all items and lose all their crafting recipes when Insane even if they aren't playing as my character which's kinda not supposed to happen since it should be unique only to my character not Wilson, Willow ect.

Steps to make bug happen:

1-Enable Adam mod

2-Create a world and host it

3-Pick a character which isn't adam

4-That character can now craft all items and lose all crafting tabs when Insane

Mod.zip

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