[Done] Preventing Multiple Table Entries
Posted: Thu Jul 12, 2018 5:41 pm
Hi,
I'm trying to add a resistance type "ne_fire" if the current entity already had the resistance type "fire".
I was able to accomplish that, by using the below code:
This works, but then I ran into the following situation. It does not check if the entity already has "ne_fire" as a resistance and if it has, it should see if that "ne_fire" is higher or lower than "fire" and if lower, update.
So in the below example, I added 50% "ne_fire", though the entity already had it.
So I need to check if "ne_fire" is present and then check if that is higher or lower than "fire" and update if lower.
Not sure how to add this check in my code.
Thanks.
I'm trying to add a resistance type "ne_fire" if the current entity already had the resistance type "fire".
I was able to accomplish that, by using the below code:
Code: Select all
for i = 1, ent_count do
--- Add the same amount of "ne_fire" Resistances as the current "fire" Resistances
for _, ent_type in pairs(data.raw[entity_types_list[i]]) do
if ent_type.resistances then
for _, r_type in pairs(ent_type.resistances) do
if r_type.type == "fire" and r_type.percent then
table.insert(ent_type.resistances, {type = "ne_fire", percent = r_type.percent})
end
end
end
end
end
So in the below example, I added 50% "ne_fire", though the entity already had it.
Code: Select all
data.raw["unit-spawner"]["ne-spawner-pink"].resistances[3].type = "fire"
data.raw["unit-spawner"]["ne-spawner-pink"].resistances[3].decrease = 5
data.raw["unit-spawner"]["ne-spawner-pink"].resistances[3].percent = 50
data.raw["unit-spawner"]["ne-spawner-pink"].resistances[4].type = "ne_fire"
data.raw["unit-spawner"]["ne-spawner-pink"].resistances[4].percent = 100
data.raw["unit-spawner"]["ne-spawner-pink"].resistances[5].type = "ne_fire"
data.raw["unit-spawner"]["ne-spawner-pink"].resistances[5].percent = 50
Not sure how to add this check in my code.
Thanks.