[Mod] Radiant damage [0.5] [radiant_damage]

Post Reply
FaceDeer
Member
Posts: 506
Joined: Sat Aug 29, 2015 19:01
GitHub: FaceDeer

[Mod] Radiant damage [0.5] [radiant_damage]

by FaceDeer » Post

This mod allows registered nodes to damage a player if the player is simply near them, rather than having to be immersed in them directly. For example, in real life simply being close to lava would burn you. Or perhaps being near a highly radioactive material would be damaging.

This mod comes with a set of predefined radiant damage types, all of which can be enabled and disabled independently, and allows other mods to make use of its system to register their own.

Configurable Presets

Important note: none of these predefined radiant damage types are enabled by default. This is because one of this mod's intended uses is as a library for other mods to use to enable their own radiant damage types. There is no way to de-register a globalstep callback (the mechanism used by this mod to deliver damage) once it has been registered, so to keep the mod maximally flexible nothing is registered by default.

Set one or more of the following types to enabled if you want this mod to have an effect out-of-the-box.

The following settings exist for predefined radiant damage types:

Code: Select all

    radiant_damage_enable_heat_damage (Enable radiant heat damage) bool false
    radiant_damage_lava_damage (Damage dealt per second when standing directly adjacent to one lava node) int 8
    radiant_damage_fire_damage (Damage dealt per second when standing directly adjacent to one fire node) int 2
    
    radiant_damage_enable_mese_damage (Enable mese ore radiation damage) bool false
    radiant_damage_mese_interval (Number of seconds between mese radiation damage checks) int 5
    radiant_damage_mese_damage (Damage dealt per second when standing directly adjacent to one mese ore node) int 2
Mese radiation is attenuated by a factor of 0.9 when passing through most materials, by 0.5 when passing through anything with group:stone, by 0.1 when passing through anything with group:mese_radiation_shield (all default metal blocks are given this group), and is _amplified_ by a factor of 4 when passing through nodes with group:mese_radiation_amplifier (default coal and diamond blocks). Note that these fine-grained attenuation factors only work in Minetest 0.5 and higher, for 0.4.16 any non-air node will block all damage.

API

Call:

Code: Select all

	radiant_damage.register_radiant_damage(damage_name, damage_def)
where damage_name is a string used to identify this damage type and damage_def is a table such as:

Code: Select all

{
	interval = 1, -- number of seconds between each damage check. Defaults to 1 when undefined.
	range = 3, -- range of the damage. Can be omitted if inverse_square_falloff is true,
		-- in that case it defaults to the range at which 0.125 points of damage is done
		-- by the most damaging emitter node type.
	emitted_by = {}, -- nodes that emit this damage. At least one emission node type
		-- and damage value pair is required.
	attenuated_by = {} -- This allows certain intervening node types to modify the damage
		-- that radiates through it. This parameter is optional.
		-- Note: Only works in Minetest version 0.5 and above.
	default_attenuation = 1, -- the amount the damage is multiplied by when passing 
		-- through any other non-air nodes. Defaults to 0 when undefined. Note that
		-- in versions before Minetest 0.5 any value other than 1 will result in total
		-- occlusion (ie, any non-air node will block all damage)
	inverse_square_falloff = true, -- if true, damage falls off with the inverse square
		-- of the distance. If false, damage is constant within the range. Defaults to
		-- true when undefined.
	above_only = false, -- if true, damage only propagates directly upward. Useful for
		-- when you want to damage players only when they stand on the node.
		-- Defaults to false when undefined.
	on_damage = function(player_object, damage_value, pos), -- An optional callback to allow mods
		-- to do custom behaviour. If this is set to non-nil then the default damage will
		-- *not* be done to the player, it's up to the callback to handle that. If it's left
		-- undefined then damage_value is dealt to the player.
}
emitted_by has the following format:

Code: Select all

	{["default:stone_with_mese"] = 2, ["default:mese"] = 9}
where the value associated with each entry is the amount of damage dealt. Groups are permitted. Note that negative damage represents "healing" radiation.

attenuated_by has the following similar format:

Code: Select all

	{["group:stone"] = 0.25, ["default:steelblock"] = 0}
where the value is a multiplier that is applied to the damage passing through it. Groups are permitted. Note that you can use values greater than one to make a node type magnify damage instead of attenuating it.

To modify or add new parameters to an existing already-registered damage type use the following function:

Code: Select all

	radiant_damage.override_radiant_damage(damage_name, damage_def)
Where damage_def is a table as above but which only includes the new information. For example, a mod could add a new type of mese radiation emitter with the following:

Code: Select all

	radiant_damage.override_radiant_damage("mese", {
		emitted_by = {
			["dfcaverns:glow_mese"] = radiant_damage.config.mese_damage * 12,
		},
	})
To remove an emission source set its emitted damage to 0.

To remove an attenuation node type, set its attenuation factor to equal the default attenuation factor.

If you wish to "disable" a registered damage type, use this override function to set its range to 1 and its interval to an enormous value (millions of seconds) to neutralize the damage type's global callback most efficiently.

Dependencies

optional depends = default, fire, 3d_armor

Links
License: MIT
Last edited by FaceDeer on Mon Nov 30, 2020 08:04, edited 8 times in total.

User avatar
TechNolaByte
Member
Posts: 465
Joined: Wed May 10, 2017 21:00
GitHub: TechNolaByte

Re: [Mod] Radiant damage [0.1]

by TechNolaByte » Post

this is pretty good. hopefully technic mod will remove its radiation code and depend on this as its better
The great quest of alchemy neither failed nor attained gold; programmers are those great alchemists who transmute caffeine into code.

FaceDeer
Member
Posts: 506
Joined: Sat Aug 29, 2015 19:01
GitHub: FaceDeer

Re: [Mod] Radiant damage [0.1]

by FaceDeer » Post

RSLRedstonier wrote:this is pretty good. hopefully technic mod will remove its radiation code and depend on this as its better
Oh, I wasn't aware there was a mod with radiation in it already. Though I guess I shouldn't be surprised. :) Am I missing any features Technic needs?

The upcoming Minetest 0.5 version has a "raycast" API function that should allow me to add attenuation to radiation, so that for example each block of metal between you and the radiation source reduces the damage by 0.5 and each block of stone by 0.25. Since I was mainly focused on getting the lava damage working I didn't explore that much. Does Technic have a radiation suit or other such worn protection? I could add in something like that as well.

User avatar
TechNolaByte
Member
Posts: 465
Joined: Wed May 10, 2017 21:00
GitHub: TechNolaByte

Re: [Mod] Radiant damage [0.1]

by TechNolaByte » Post

FaceDeer wrote:The upcoming Minetest 0.5 version has a "raycast" API function
0.0 wait 0.5 adds raycasting? man that update keeps getting better
The great quest of alchemy neither failed nor attained gold; programmers are those great alchemists who transmute caffeine into code.

FaceDeer
Member
Posts: 506
Joined: Sat Aug 29, 2015 19:01
GitHub: FaceDeer

Re: [Mod] Radiant damage [0.1]

by FaceDeer » Post

Okay, I spent a little time thinking about the cool things I could do with radiation and raycasts and whatnot, and I completely rewrote the radiant_damage mod. :) Check out the Attenuation branch.

The damage definition table is rather different now, so hopefully no modders pounced on this 0.1 version over the past day and based a whole project around it. Now a specific damage type can be emitted at different strengths by different source nodes, for example there's no separate "lava" and "fire" damage types, there's just "heat" damage type and lava puts out a lot more of it than basic_fire nodes do.

More significantly, different nodes can attenuate the damage to different degrees. If you want the old all-or-nothing behaviour you can have that pretty easily too, but for things like ionizing radiation you can get quite fancy. The "mese radiation" preset shows what I mean. I set it up so that most nodes attenuate mese radiation by 0.9, but stone attenuates it by 0.5, and metal blocks attenuate it by 0.1. So if you've got two stone nodes in between you and a mese block it'll multiply the damage by 0.25 (0.5*0.5) and if you've got two metal blocks it'll attenuate it'll multiply the damage by 0.01 (ie, practically nothing).

But just for funzies I also added an amplification effect for blocks of carbon. Coal blocks and diamond blocks will multiply the damage by 2. Though I just realized, thanks to inverse square falloff it won't make it hugely nasty, I should probably boost that to 4. Yeah, I'll do that.

If you want to get magical, I believe this mod will also allow you to define blocks that radiate negative damage - ie, healing rays. You could even define an attenuator block that turns harmful radiation into healing radiation.

It's a pretty big change and I haven't tested it extensively yet so I've put it in a branch. It should still work with Minetest 0.4.16, however the fancy attenuation effects won't work - it'll just behave as all-or-nothing shadow-casting, like the old "occlusion" check. If this tests out I'll merge it to master soon.

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: [Mod] Radiant damage [0.1]

by texmex » Post

The mod and your care for detail in designing it opens up for interesting game types. I’ve always had a weak spot for the MC mod ”Tough as Nails” (though I’ve never played it) which introduces player temperature: hypo- and hyperthermia by nodes and biomes radiating cold and heat. It forces the player to set up proper shelter so that heat stays inside when living in cold biomes and vice versa. (Check out the new ”vacuum” mod for propagation of ”custom air”)

Sorry for the OT but it’s just inspiring. :)

User avatar
Hamlet
Member
Posts: 766
Joined: Sat Jul 29, 2017 21:09
IRC: H4mlet
In-game: Hamlet
Location: Lombardy, Italy

Re: [Mod] Radiant damage [0.1]

by Hamlet » Post

I've been using this mod and I must say that:
- does not use ABMs or node timers, thus does not cause lag
- the damage dealt depends on how close you are to the lava/radioactive/etc. node; i.e. non predictable, which is good for realism's sake

Try it!
My repositories: Codeberg.org | My ContentDB's page

FaceDeer
Member
Posts: 506
Joined: Sat Aug 29, 2015 19:01
GitHub: FaceDeer

Re: [Mod] Radiant damage [0.2]

by FaceDeer » Post

I tested this out with 0.4.16 and it seems to work as expected there (with occlusion but not attenuation). So I've pulled the trigger and updated this to 0.2. Lava and fire should work much as they did before but mese has fancy "radiation" effects now.

Next on my to-do list for this mod is to come up with a further API call that will allow new emitters and attenuators to be added to an existing damage type. I've got a mapgen mod that adds a sort of "super-mese" crystal node and I'd like to be able to give them correspondingly souped-up mese radiation.

FaceDeer
Member
Posts: 506
Joined: Sat Aug 29, 2015 19:01
GitHub: FaceDeer

Re: [Mod] Radiant damage [0.3]

by FaceDeer » Post

Updated with an "override_radiant_damage" method to allow existing damage types to be amended.

I also boosted the default range for inverse_square_falloff damage types to the point where a single node of the most damaging type does 0.125 points of damage, this means that a group of 8 nodes at maximum range will be doing 1 damage per interval to you. I was noticing that if you approached a large mass of lava you'd go from taking no damage to taking tons of damage suddenly with the old default, this allows a more gradual ramping up of the damage as you approach.

Next todo: look into adding attenuation based on something the player is wearing (such as armor) or has in his inventory quickbar, to allow for things like radiation suits or heat-proof suits to be defined. Maybe even some kind of generic function callback hook to allow mods to get fancy about modifying the damage, like maybe a magical plant that deals radiation damage during the day but not at night.

User avatar
GamingAssociation39
Member
Posts: 858
Joined: Mon Apr 25, 2016 16:09
GitHub: Gerold55
IRC: Gerold55
In-game: Gerold55
Location: Maryland, USA

Re: [Mod] Radiant damage [0.3]

by GamingAssociation39 » Post

So I can use this mod to make water hurt you since they are poisonous right?
Jesus Is Lord and Savior!!!

FaceDeer
Member
Posts: 506
Joined: Sat Aug 29, 2015 19:01
GitHub: FaceDeer

Re: [Mod] Radiant damage [0.3]

by FaceDeer » Post

GamingAssociation39 wrote:So I can use this mod to make water hurt you since they are poisonous right?
Yes, if you want water to hurt a player simply by them being near the water. Like perhaps it's got a miasma around it.

If you just want water to hurt the player when they're actually immersed in it, use this:

Code: Select all

minetest.override_item("default:water_source", {damage_per_second = 1})
minetest.override_item("default:water_flowing", {damage_per_second = 1})
minetest.override_item("default:river_water_source", {damage_per_second = 1})
minetest.override_item("default:river_water_flowing", {damage_per_second = 1})
And that should do it. (note: code has not been tested)

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: [Mod] Radiant damage [0.3]

by texmex » Post

Can I somehow use this mod to increase or decrease other player variables such as breath or (modded) hunger?

FaceDeer
Member
Posts: 506
Joined: Sat Aug 29, 2015 19:01
GitHub: FaceDeer

Re: [Mod] Radiant damage [0.3]

by FaceDeer » Post

No, but I will look into how easy that would be to add as an option.

Sorry it took a while for me to respond, real life's been hectic. Little time for play-coding. :)

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: [Mod] Radiant damage [0.3]

by texmex » Post

Excellent. No hurries, we all participate freely. :)

I’m thinking this mod may serve as general framework for radiance or spherical influnence. I’m adding player temperature to my game, so in my case I want it to be able to influence that variable.

FaceDeer
Member
Posts: 506
Joined: Sat Aug 29, 2015 19:01
GitHub: FaceDeer

Re: [Mod] Radiant damage [0.3]

by FaceDeer » Post

I was fortunate to be laid out this weekend with a cold, meaning I couldn't go in to work, meaning I could catch up on some of the backlog of Minetest messages. :)

To make it completely generic perhaps I could add the option of inserting some kind of callback function you could register in the definition that would be given the player's name and the "intensity" of the radiance, and then you can have it do whatever you want to him.

Edit: Done, that was a nice simple thing to knock a little rust off (though I seem to have messed something up with github, I made several commits but only the first is showing up yet on the website - I'll check if it's fixed itself in the morning). There's now an optional "on_damage" function you can add to a damage_def that will be given the player object and damage value, you can use that to do whatever you want to the player. If on_damage is defined then damage will not be automatically done to the player, but if it's omitted then the mod behaves as it did before.

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: [Mod] Radiant damage [0.4]

by texmex » Post

That is truly great! It’s all I will need. Thank you FaceDeer. I would say ”get well soon” but since you called the cold ”fortunate” it leads me to think that the break from the daily grind is welcome. ;)

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: [Mod] Radiant damage [0.4]

by texmex » Post

I should be able to use this mod in a minimalist way to pipe values over to my player effect library (LATE) using a custom on_damage function… In this case I wouldn't interpret the value as damage/health but instead as a factor for an effect increasing or decreasing heat.

Red_King_Cyclops
Member
Posts: 324
Joined: Sun Jun 16, 2019 20:17
Location: x=123, y=120, z=534

Re: [Mod] Radiant damage [0.4]

by Red_King_Cyclops » Post

Is it possible for mods to add ways to block/prevent the radiant damage (for example, a hazmat suit prevent the player from taking radiation damage)?
Currently working on new mods.

FaceDeer
Member
Posts: 506
Joined: Sat Aug 29, 2015 19:01
GitHub: FaceDeer

Re: [Mod] Radiant damage [0.4]

by FaceDeer » Post

Red_King_Cyclops wrote:Is it possible for mods to add ways to block/prevent the radiant damage (for example, a hazmat suit prevent the player from taking radiation damage)?
Just took a look through how 3d_armor handles fire protection and it should be possible. It involves player monoids though and I've never worked with those before, so give me a little bit to figure out the best way to do this.

FaceDeer
Member
Posts: 506
Joined: Sat Aug 29, 2015 19:01
GitHub: FaceDeer

Re: [Mod] Radiant damage [0.4]

by FaceDeer » Post

Okay, I've added armor support. Turns out I didn't need to deal with monoids directly, but I *did* need to deal with the idiosyncratic way that 3d_armor implements fire protection. Turns out it doesn't use the default armor system implemented for Minetest for that, instead it uses custom handling where there's a fire protection level calculated for the player's armor and then certain nodes either do or don't do damage at all based on that level. For example, a fire protection level of 3 means fire won't hurt you at all but lava will, while a fire protection of 5 means neither fire nor lava will hurt you.

It's pretty arbitrary and doesn't translate directly into an attenuation factor at all. So I made it translate into an attenuation factor. Making a few assumptions about what "total protection" meant, I fitted an exponential curve to the known data points and it seems to be giving plausible results.

I also let "radiation" armor value give protection against mese radiation. I believe technic has a suit that gives "radiation" armor? Haven't actually tested it, but I see the "radiation" armor group being checked in technic's radiation.lua so I think it'll work.

Also, since I had the code's abdominal cavity opened up anyway, I added sounds to both the heat and radiation damage types. Being damaged by heat radiation will produce a sizzling sound that you and everyone around you can hear, and being damaged by mese radiation produces a geiger counter clicking sort of sound. The loudness of the sound will vary with how much damage is being done (technically radiation intensity changes the frequency of a geiger counter's clicking rather than its loudness, but this was way easier :).

I pushed the change to master, let me know if it works for you. Haven't tried going for a boat ride in magma with the molten_sailor mod yet, I think it may still be overwhelmed by the amount of radiant heat you'd get from that amount of lava exposure. That may require modifications to the molten_sailor suit.

User avatar
FreeGamers
Member
Posts: 650
Joined: Sat May 25, 2019 00:15
GitHub: is proprietary I use NotABug
Location: United States
Contact:

Re: [Mod] Radiant damage [0.5]

by FreeGamers » Post

I'd like to request support for the molten_sailor mod.

That mod is nice for exploring the lava sea in df_caverns and also for wading into the deep magma conduits and volcanoes. However, the radiant_damage system will still damage players despite them using the molten_sailor armor.

Not urgent, I'm holding off adding molten_sailor into my world until this can be implemented.
FreeGamers.org has moved to MeseCraft.net | FreeGamers on this forum is now MeseCraft

User avatar
FreeGamers
Member
Posts: 650
Joined: Sat May 25, 2019 00:15
GitHub: is proprietary I use NotABug
Location: United States
Contact:

Re: [Mod] Radiant damage [0.5]

by FreeGamers » Post

My game created an error when players were near a stone ladder that was removed from the game with servercleaner disabled (not deleting unknowns). Radiant damage created a critical error when encountering this.

Code: Select all

2020-05-10 16:58:12: ERROR[Main]: ServerError: AsyncErr: environment_Step: Runtime error from mod 'radiant_damage' in callback environment_Step(): ...re/games/minetest/mods/lib_world/radiant_damage/init.lua:36: attempt to index local 'node_def' (a nil value)
2020-05-10 16:58:12: ERROR[Main]: stack traceback:
2020-05-10 16:58:12: ERROR[Main]:       ...re/games/minetest/mods/lib_world/radiant_damage/init.lua:36: in function 'get_val'
2020-05-10 16:58:12: ERROR[Main]:       ...re/games/minetest/mods/lib_world/radiant_damage/init.lua:88: in function 'attenuation_check'
2020-05-10 16:58:12: ERROR[Main]:       ...re/games/minetest/mods/lib_world/radiant_damage/init.lua:312: in function <...re/games/minetest/mods/lib_world/radiant_damage/init.lua:284>
2020-05-10 16:58:12: ERROR[Main]:       /usr/share/games/minetest/builtin/game/register.lua:429: in function </usr/share/games/minetest/builtin/game/register.lua:413>
2020-05-10 16:58:12: ERROR[Main]: stack traceback:
FreeGamers.org has moved to MeseCraft.net | FreeGamers on this forum is now MeseCraft

Badkraft
Member
Posts: 28
Joined: Wed Jan 27, 2021 13:44

Re: [Mod] Radiant damage [0.5] [radiant_damage]

by Badkraft » Post

Couple of things:
  • I was thinking I'd want a biome to radiate a damage type.
  • You mentioned 3D armor does something different with damage protection than the default minetest method. I assume your mod is compatible with the default?
I'm working on an environment that is deadly on the surface. To obtain some powerful craft ingredients, a player must spend some time working on the surface. There will be several tiers of protection to minimize or negate damage.

Also, water on the surface is more like acid. Because of the temperature on the surface, there is a cloud hovering over surface water that will radiate over a short distance suffocating the player. Will also burn like fire.

Anyway, sounds promising.

User avatar
AccidentallyRhine
Member
Posts: 252
Joined: Sun Aug 02, 2015 05:43

Re: [Mod] Radiant damage [0.5] [radiant_damage]

by AccidentallyRhine » Post

Spoiler
I am trying to call this API from another mod

Code: Select all

radiant_damage.register_radiant_damage("effect", {
	interval = 1,
	emitted_by = {["mymod:mynode"] = 1},
	inverse_square_falloff = true,
	default_attenuation = 0,
But it fails to load at all

ModError: Failed to load and run script from /home/user/.minetest/mods/mymod/init.lua:
2021-12-12 : ERROR[Main]: /home/user/.minetest/mods/mymod/init.lua:126: attempt to call global 'register_radiant_damage' (a nil value)
2021-12-12 : ERROR[Main]: stack traceback:
2021-12-12 : ERROR[Main]: /home/user/.minetest/mods/mymod/init.lua:126: in main chunk
2021-12-12 : ERROR[Main]: Check debug.txt for details.

How do you communicate with the API?
EDIT: I found that mods now require dependencies to be listed in mods.conf (since the last time I touched minetest modding...). It is working now.

Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests