Adding custom entity flags?

Place to get help with not working mods / modding interface.
User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 587
Joined: Tue May 19, 2015 1:56 am
Contact:

Adding custom entity flags?

Post 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
Image
keyboardhack
Filter Inserter
Filter Inserter
Posts: 478
Joined: Sat Aug 23, 2014 11:43 pm
Contact:

Re: Adding custom entity flags?

Post 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.
Waste of bytes : P
User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 587
Joined: Tue May 19, 2015 1:56 am
Contact:

Re: Adding custom entity flags?

Post 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.
Image
Gemzo
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sat Nov 01, 2014 7:45 am
Contact:

Re: Adding custom entity flags?

Post 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?
User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 587
Joined: Tue May 19, 2015 1:56 am
Contact:

Re: Adding custom entity flags?

Post 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.
Image
keyboardhack
Filter Inserter
Filter Inserter
Posts: 478
Joined: Sat Aug 23, 2014 11:43 pm
Contact:

Re: Adding custom entity flags?

Post 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
Waste of bytes : P
User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 587
Joined: Tue May 19, 2015 1:56 am
Contact:

Re: Adding custom entity flags?

Post 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?
Image
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Adding custom entity flags?

Post by prg »

Reika wrote:...What is the third category (just "turret") for?
Search for 'type = "turret"' in prototypes/entity/*turrets.lua.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 587
Joined: Tue May 19, 2015 1:56 am
Contact:

Re: Adding custom entity flags?

Post 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...
Image
User avatar
ownlyme
Filter Inserter
Filter Inserter
Posts: 445
Joined: Thu Dec 21, 2017 8:02 am
Contact:

Re: Adding custom entity flags?

Post 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...
creator of 55 mods
My api requests/suggestions: ui relative for overlay||Grenade arc||Player Modifiers||textbox::selection||Singleplayer RCON||disable car's ground sounds
Post Reply

Return to “Modding help”