[SOLVED] Damage

Place to get help with not working mods / modding interface.
User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 736
Joined: Sun Mar 13, 2016 9:48 am
Contact:

[SOLVED] Damage

Post by DRY411S »

I want to check my understanding.

It appears that the API function for Damage does not make any allowances for resistances, and therefore my code must handle those itself.

So if I have a new acid weapon that inflicts 200 damage, I cannot call

Code: Select all

player.character.damage(200,"enemy","acid")
and let the function work out what resistances that the character has. I have to get the characters resistance myself?

Is that right? Where can I get the resistances?
Last edited by DRY411S on Thu Jun 28, 2018 3:42 pm, edited 1 time in total.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Damage

Post by eradicator »

LuaEntity.damage wrote:damage(damage, force, type) → float
Damages the entity.
Parameters
damage :: float: The amount of damage to be done
force :: string or LuaForce: The force that will be doing the damage.
type :: string (optional): The type of damage to be done.
Return value
the total damage actually applied after resistances.
Can only be used if this is EntityWithHealth
Huh? Are you saying it's bugged?
User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 736
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: Damage

Post by DRY411S »

eradicator wrote:
LuaEntity.damage wrote:damage(damage, force, type) → float
Damages the entity.
Parameters
damage :: float: The amount of damage to be done
force :: string or LuaForce: The force that will be doing the damage.
type :: string (optional): The type of damage to be done.
Return value
the total damage actually applied after resistances.
Can only be used if this is EntityWithHealth
Huh? Are you saying it's bugged?
I didn't see that bolded bit thanks.

A call like this:

Code: Select all

player.character.damage(100,"enemy")
(with a character wearing no armor at all) reduces character health by 100

A call like this:

Code: Select all

player.character.damage(100,"enemy")
(with a character wearing Power Armor MK2, no shields) reduces character health by 100 AND Power Armor durability by 200.

A call like this:

Code: Select all

player.character.damage(100,"enemy","acid")
(with a character wearing Power Armor MK2, no shields) reduces character health by 54 AND Power Armor durability by 8.

Putting 2 fusion reactors into the armor has no effect on these calls.

Bugged in your opinion?
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Damage

Post by eradicator »

DRY411S wrote:Bugged in your opinion?
Looks fine? I don't know what acid resist the armor has. And i'm not sure why you expect damage to change if you put fusion reactors into the armor but no shields? Also i have no clue how armor durability works.
User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 736
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: Damage

Post by DRY411S »

eradicator wrote:
DRY411S wrote:Bugged in your opinion?
Looks fine? I don't know what acid resist the armor has. And i'm not sure why you expect damage to change if you put fusion reactors into the armor but no shields? Also i have no clue how armor durability works.
Acid resist is 10/40% in mk2 armor, so that works out right.

Without the optional damage type in the call, I was expecting that the "Physical" type would be used to calculate the resistance effect. It isn't. No resistance is factored in.
I was expecting that with powered power armor, that the damage effect on durability would be smaller than if the power armor was not powered
I wasn't expecting that the durability damage would be double the damage to the person (although maximum durability of power armor mk2 is 80 times the maximum health of a character)

So I guess not buggy, but not the results I predicted.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [SOLVED] Damage

Post by eradicator »

If no damage type is specified it more likely defaults to skipping the resistance calculation alltogether and applies the damage directly to the entity. Also i don't know where you got your numbers (100:200,54:8?), but i just tried, and in all instances the player and armor take exactly the same amount of damage. When applying damage(100): 54 for acid, 30 for fire, 100 for void (which i added and thus the armor has no resistance to).
User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 736
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: [SOLVED] Damage

Post by DRY411S »

eradicator wrote:If no damage type is specified it more likely defaults to skipping the resistance calculation alltogether and applies the damage directly to the entity. Also i don't know where you got your numbers (100:200,54:8?), but i just tried, and in all instances the player and armor take exactly the same amount of damage. When applying damage(100): 54 for acid, 30 for fire, 100 for void (which i added and thus the armor has no resistance to).
So I am synthetically measuring the effects of damage by caliing the damage function when a character changes their gun inventory. The mod has some debug statements:

Code: Select all

  27.195 Script @P:/Program Files (x86)/Factorio_0.16/temp/currently-playing/control.lua:9: Roles: on_player_gun_inventory_changed: 1
  27.195 Script @P:/Program Files (x86)/Factorio_0.16/temp/currently-playing/control.lua:9: Roles: armor: {
  ["power-armor-mk2"] = 1
}
  27.195 Script @P:/Program Files (x86)/Factorio_0.16/temp/currently-playing/control.lua:9: Roles: health: 196.14999389648
The debug tells me that the payer has taken 54 damage to health (250 - 54 = 196). That is aligned to the calculation in the wiki. Acid resistance is 10/40% (100 - 10)*(100% -40%) = 54

Visual inspection in game of the armor durability shows me this 108 damage.
108damage.png
108damage.png (257.16 KiB) Viewed 3170 times
I guess it's possible that some other part of the game code has applied the durability damage a second time. How are you checking it?
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [SOLVED] Damage

Post by eradicator »

Code: Select all

/c game.print(game.player.character.damage(100,game.player.character.force,'acid'))
User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 736
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: [SOLVED] Damage

Post by DRY411S »

eradicator wrote:

Code: Select all

/c game.print(game.player.character.damage(100,game.player.character.force,'acid'))
So you are being damaged by your own force yourself. I am adding damage from the biter "enemy".

Code: Select all

player.character.damage(100,"enemy","acid")
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [SOLVED] Damage

Post by eradicator »

The force is irrelevant for this, as you could have found out in two seconds trying my command :P.
User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 736
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: [SOLVED] Damage

Post by DRY411S »

eradicator wrote:The force is irrelevant for this, as you could have found out in two seconds trying my command :P.
Yeah well I didn't. I was looking for differences. Maybe you could try my code instead of console, and see whether you get a different result than in the command line. ;)
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [SOLVED] Damage

Post by eradicator »

I might consider that if you link an online repository (github, etc), but don't expect miracles. Sounds pretty much like you're simply calling something twice.
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: [SOLVED] Damage

Post by bobingabout »

I have seen other instances of effects being applied twice in the game. When I was trying to make a fluid generator, I noticed that if you used less than 100% efficiency, you didn't get expected results. Examining the game code showed that the effect was being applied in two different places, which multiplied with each other, which effectively applied the efficiency twice, but only when lower than 100%. Needless to say, I fixed the bug, and added in a whole bunch of other features to fluid burning in the generator. I even added a tag for you to set what behaviour the steam engine should use when the fluid has more energy than expected. in 0.15, if your steam was too hot, it used less of it to maintain efficiency. but in 0.16 this was changed to just destroy the excess energy, consume at the specified rate to give the specified output energy. since I wanted burnable fluids to use less of a more powerful fluid, I could have just hard coded it to do that, but decided it would be better to give the modder the choice, so defined it as a tag.
scale_fluid_usage = true, which can only be used if max_power_output = is set.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
Post Reply

Return to “Modding help”