Sign in to follow this  
Tesumoto

Need help for creating mod (interacting with walls)

Recommended Posts

Tesumoto    19

Hello!

I created a mod to increase walls strength on x10.
But then came another player and broke my wall with a hammer for 3 hitting.
The strength of the wall increased, if you hits them with an axe or a spear.
But hammer ignores the fact that I raised HP for walls.

I want that other players could not easily destroy my walls.
But I do not want the immortal walls.
I just need improve the resistance of the walls to the hammer.

Can you help me with this?

Edited by Tezumoto

Share this post


Link to post
Share on other sites
Tesumoto    19
43 minutes ago, CarlZalph said:

Check out the workable component's SetMaxWork and SetWorkLeft functions.

Now I use this code:

local Effectiveness = GetModConfigData("Effectiveness")


local old_ACTION_HAMMER = GLOBAL.ACTIONS.HAMMER.fn

GLOBAL.ACTIONS.HAMMER.fn = function(act)
	if act.target and act.target.prefab and (act.target.prefab == 'wall_stone' or act.target.prefab == 'wall_moonrock' or act.target.prefab == 'wall_ruins') then
		if act.invobject and act.invobject.components.tool then act.invobject.components.tool:SetAction(GLOBAL.ACTIONS.HAMMER, Effectiveness) end
		return old_ACTION_HAMMER(act)
	else
		if act.invobject and act.invobject.components.tool then act.invobject.components.tool:SetAction(GLOBAL.ACTIONS.HAMMER, 1) end
		return old_ACTION_HAMMER(act)
	end
end

But with this code walls are destroyed in different hits (rock, moon and ruins walls).
I can simply set a specific number of beats for all selected walls?

Edited by Tezumoto

Share this post


Link to post
Share on other sites
Aquaterion    821

you should be able to do (in modmain.lua):

local wallmaterials = { MATERIALS.STONE, MATERIALS.WOOD, MATERIALS.HAY, "ruins", MATERIALS.MOONROCK}

for id,material in pairs(wallmaterials) do
	AddPrefabPostInit("wall_" .. material, function(inst)
		if not GLOBAL.TheWorld.ismastersim then
			return inst
		end
		if inst.components.workable then
			--use these 2 lines:
			inst.components.workable:SetMaxWork(200)-- these lines sets all walls to 200 hammer hits
			inst.components.workable:SetWorkLeft(200)
			--or these 4 lines(not all 6):
			local maxwork = inst.components.workable.maxwork
			local multiplier = 3
			inst.components.workable:SetMaxWork(maxwork * multiplier)--these lines instead multiple the amount of hammer hits
			inst.components.workable:SetMaxWork(maxwork * multiplier)--depending on multiplier, or in ur case "Effectiveness"
		end
		return inst
	end)
end

 

Edited by Aquaterion
fixed an issue

Share this post


Link to post
Share on other sites
Tesumoto    19
11 minutes ago, Aquaterion said:

you should be able to do (in modmain.lua):


local wallmaterials = { MATERIALS.STONE, MATERIALS.WOOD, MATERIALS.HAY, "ruins", "MATERIALS.MOONROCK}

for id,material in pairs(wallmaterials) do
	AddPrefabPostInit("wall_" .. material, function(inst)
		if not GLOBAL.TheWorld.ismastersim then
			return inst
		end
		if inst.components.workable then
			--use these 2 lines:
			inst.components.workable:SetMaxWork(200)-- these lines sets all walls to 200 hammer hits
			inst.components.workable:SetWorkLeft(200)
			--or these 4 lines(not all 6):
			local maxwork = inst.components.workable.maxwork
			local multiplier = 3
			inst.components.workable:SetMaxWork(maxwork * multiplier)--these lines instead multiple the amount of hammer hits
			inst.components.workable:SetMaxWork(maxwork * multiplier)--depending on multiplier, or in ur case "Effectiveness"
		end
		return inst
	end)
end

 

I must use this code without my old code?

Share this post


Link to post
Share on other sites
Aquaterion    821
Just now, Tezumoto said:

I must use this code without my old code?

yeah, make sure to read the comments and pick which part of my code you want to use. And to implement your Effective variable

Edited by Aquaterion

Share this post


Link to post
Share on other sites
Tesumoto    19
4 minutes ago, Aquaterion said:

yeah, make sure to read the comments and pick which part of my code you want to use

How do I change the code so that I could through the settings change the number of hits?

local wallmaterials = { MATERIALS.STONE, MATERIALS.MOONROCK, MATERIALS.RUINS}

for id,material in pairs(wallmaterials) do
	AddPrefabPostInit("wall_" .. material, function(inst)
		if not GLOBAL.TheWorld.ismastersim then
			return inst
		end
		if inst.components.workable then
			inst.components.workable:SetMaxWork(200)-- these lines sets all walls to 200 hammer hits
			inst.components.workable:SetWorkLeft(200)
		end
		return inst
	end)
end

 

Share this post


Link to post
Share on other sites
Aquaterion    821
Just now, Tezumoto said:

How do I change the code so that I could through the settings change the number of hits?


local wallmaterials = { MATERIALS.STONE, MATERIALS.MOONROCK, MATERIALS.RUINS}

for id,material in pairs(wallmaterials) do
	AddPrefabPostInit("wall_" .. material, function(inst)
		if not GLOBAL.TheWorld.ismastersim then
			return inst
		end
		if inst.components.workable then
			inst.components.workable:SetMaxWork(200)-- these lines sets all walls to 200 hammer hits
			inst.components.workable:SetWorkLeft(200)
		end
		return inst
	end)
end

 

does your "Effectiveness" number have a multiplier or a big number? You can easily just put that variable instead of the 200 if its a big number, but if its a multiplier you could use the other part of the code that you removed instead.

Share this post


Link to post
Share on other sites
Tesumoto    19
1 minute ago, Aquaterion said:

does your "Effectiveness" number have a multiplier or a big number? You can easily just put that variable instead of the 200 if its a big number, but if its a multiplier you could use the other part of the code that you removed instead.

This code will work for mod Wall Gates?

Share this post


Link to post
Share on other sites
Aquaterion    821
Just now, Tezumoto said:

This code will work for mod Wall Gates?

without some modification no, as it is only modifying the 3 prefabs wall_stone, wall_moonrock and wall_ruins (btw MATERIALS.RUINS doesnt exist, so change it back to "ruins")

Share this post


Link to post
Share on other sites
Tesumoto    19
1 minute ago, Aquaterion said:

without some modification no, as it is only modifying the 3 prefabs wall_stone, wall_moonrock and wall_ruins (btw MATERIALS.RUINS doesnt exist, so change it back to "ruins")

You can replace materials on prefabs?

Share this post


Link to post
Share on other sites
Tesumoto    19
7 minutes ago, Aquaterion said:

without some modification no, as it is only modifying the 3 prefabs wall_stone, wall_moonrock and wall_ruins (btw MATERIALS.RUINS doesnt exist, so change it back to "ruins")

local wallmaterials = { MATERIALS.STONE, MATERIALS.MOONROCK, "ruins"}

for id,material in pairs(wallmaterials) do
	AddPrefabPostInit("wall_" .. material, function(inst)
		if not GLOBAL.TheWorld.ismastersim then
			return inst
		end
		if inst.components.workable then
			inst.components.workable:SetMaxWork(200)-- these lines sets all walls to 200 hammer hits
			inst.components.workable:SetWorkLeft(200)
		end
		return inst
	end)
end

So?
I hope it will work for walls and walls gates.

Edited by Tezumoto

Share this post


Link to post
Share on other sites
Aquaterion    821
1 minute ago, Tezumoto said:

local wallmaterials = { MATERIALS.STONE, MATERIALS.MOONROCK, "ruins"}

for id,material in pairs(wallmaterials) do
	AddPrefabPostInit("wall_" .. material, function(inst)
		if not GLOBAL.TheWorld.ismastersim then
			return inst
		end
		if inst.components.workable then
			inst.components.workable:SetMaxWork(200)-- these lines sets all walls to 200 hammer hits
			inst.components.workable:SetWorkLeft(200)
		end
		return inst
	end)
end

So?

yeah. Is your Effectiveness variable a Multiplier? like x1 to x5 for example?

Share this post


Link to post
Share on other sites
Tesumoto    19
6 minutes ago, Aquaterion said:

yeah. Is your Effectiveness variable a Multiplier? like x1 to x5 for example?

Effectiveness?
This in old code, yep multiplier

Share this post


Link to post
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
Sign in to follow this