Page 1 of 1

Adding custom entity flags?

Posted: Thu Dec 03, 2015 4:37 am
by Reika
I wanted to make a (radiation-based) weapon that only damaged biters and their bases (so that I did not have to worry about destroying large areas of forest with my current weapons). No entity flag seems applicable; the closest was placeable-enemy, and that caused it to damage turrets as well.

So I made my own flag "animal", and added it to all the appropriate entities:

Code: Select all

table.insert(data.raw["unit-spawner"]["biter-spawner"].flags,"animal")
table.insert(data.raw["unit-spawner"]["spitter-spawner"].flags,"animal")
table.insert(data.raw["unit"]["small-biter"].flags,"animal")
table.insert(data.raw["unit"]["medium-biter"].flags,"animal")
table.insert(data.raw["unit"]["big-biter"].flags,"animal")
table.insert(data.raw["unit"]["behemoth-biter"].flags,"animal")
table.insert(data.raw["unit"]["small-spitter"].flags,"animal")
table.insert(data.raw["unit"]["medium-spitter"].flags,"animal")
table.insert(data.raw["unit"]["big-spitter"].flags,"animal")
table.insert(data.raw["unit"]["behemoth-spitter"].flags,"animal")
table.insert(data.raw["player"]["player"].flags,"animal")
However, this triggers a crash:
4.370 Error Util.cpp:49: Error while loading entity prototype "player" (player): Unknown flag "animal"
Modifications: base->Larger Inventory->EndgameCombat->bobassembly

Re: Adding custom entity flags?

Posted: Thu Dec 03, 2015 6:04 am
by keyboardhack
it's not possible to make your own flags. Instead you could check if an entity has both the "placeable-enemy" and the "placeable-off-grid" flags as base turrets doesn't have both.

Re: Adding custom entity flags?

Posted: Thu Dec 03, 2015 7:21 am
by Reika
keyboardhack wrote:it's not possible to make your own flags. Instead you could check if an entity has both the "placeable-enemy" and the "placeable-off-grid" flags as base turrets doesn't have both.
I tried that. The table of flags in the checking code - inside the projectile class - appears to be an OR, not an AND. Putting "breaths-air" as the second made it kill trees as well as everything it already could.

Re: Adding custom entity flags?

Posted: Thu Dec 03, 2015 12:52 pm
by Gemzo
What about if you made turrets 100% resistant to the damage type the weapon uses? As long as the enemies don't use that damage type, it should allow you to use "placeable-enemy" just fine, right?

Re: Adding custom entity flags?

Posted: Thu Dec 03, 2015 9:42 pm
by Reika
Gemzo wrote:What about if you made turrets 100% resistant to the damage type the weapon uses? As long as the enemies don't use that damage type, it should allow you to use "placeable-enemy" just fine, right?
That would not account for modded turrets, though.

Re: Adding custom entity flags?

Posted: Fri Dec 04, 2015 5:27 am
by keyboardhack
Reika wrote: That would not account for modded turrets, though.
That can be solved with the code below. There is only 3 different kinds of turrets and the below code should add a 100% resistance of "your type" to all turrets including modded turrets. Place the code in a file called data-final-fixes.lua to run the code after other mods have added their turrets

Code: Select all

for k, v in pairs(data.raw["electric-turret"]) do
	if not v.resistances then
		v.resistances = {}
	end
	v.resistances[#resistances + 1] = 
	{
		type = "your type",
		percent = 100
	}
end
for k, v in pairs(data.raw["ammo-turret"]) do
	if not v.resistances then
		v.resistances = {}
	end
	v.resistances[#resistances + 1] = 
	{
		type = "your type",
		percent = 100
	}
end
for k, v in pairs(data.raw["turret"]) do
	if not v.resistances then
		v.resistances = {}
	end
	v.resistances[#resistances + 1] = 
	{
		type = "your type",
		percent = 100
	}
end

Re: Adding custom entity flags?

Posted: Sat Dec 05, 2015 8:23 pm
by Reika
keyboardhack wrote:
Reika wrote: That would not account for modded turrets, though.
That can be solved with the code below. There is only 3 different kinds of turrets and the below code should add a 100% resistance of "your type" to all turrets including modded turrets. Place the code in a file called data-final-fixes.lua to run the code after other mods have added their turrets

Code: Select all

for k, v in pairs(data.raw["electric-turret"]) do
	if not v.resistances then
		v.resistances = {}
	end
	v.resistances[#resistances + 1] = 
	{
		type = "your type",
		percent = 100
	}
end
for k, v in pairs(data.raw["ammo-turret"]) do
	if not v.resistances then
		v.resistances = {}
	end
	v.resistances[#resistances + 1] = 
	{
		type = "your type",
		percent = 100
	}
end
for k, v in pairs(data.raw["turret"]) do
	if not v.resistances then
		v.resistances = {}
	end
	v.resistances[#resistances + 1] = 
	{
		type = "your type",
		percent = 100
	}
end
I already have resistance-injection code, but yes, I suppose a table iteration would work, yes.

...What is the third category (just "turret") for?

Re: Adding custom entity flags?

Posted: Sat Dec 05, 2015 8:41 pm
by prg
Reika wrote:...What is the third category (just "turret") for?
Search for 'type = "turret"' in prototypes/entity/*turrets.lua.

Re: Adding custom entity flags?

Posted: Sat Dec 05, 2015 9:02 pm
by Reika
prg wrote:
Reika wrote:...What is the third category (just "turret") for?
Search for 'type = "turret"' in prototypes/entity/*turrets.lua.
Ah. Worms. That means I want to exclude them from this check, as they would be radiation-susceptible.

That gives me an interesting idea...

Re: Adding custom entity flags?

Posted: Fri Sep 07, 2018 6:35 pm
by ownlyme
i need custom flags too...
would be nice for filtering damage effects
currently i had to add the breaths-air flag and 100% poison resistance to all cars and tanks, which obviously won't be very compatible with some mods..

using the deprecated "pushable" flag doesn't work either...