[Mod] Radiant damage [0.4]

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

[Mod] Radiant damage [0.4]

by FaceDeer » Sun May 27, 2018 05:45

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 10
    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), -- 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.

Links


License: MIT
Last edited by FaceDeer on Mon Oct 22, 2018 03:02, edited 5 times in total.
 

User avatar
RSLRedstonier
Member
 
Posts: 439
Joined: Wed May 10, 2017 21:00
Location: some were in middle earth
GitHub: RSL-Redstonier
In-game: RSLRedstonier

Re: [Mod] Radiant damage [0.1]

by RSLRedstonier » Sun May 27, 2018 19:53

this is pretty good. hopefully technic mod will remove its radiation code and depend on this as its better
"A programmer is just a tool which converts caffeine into code"

try out my skytest mod always being updated!
https://forum.minetest.net/viewtopic.php?f=9&t=17568
 

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

Re: [Mod] Radiant damage [0.1]

by FaceDeer » Sun May 27, 2018 20:57

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
RSLRedstonier
Member
 
Posts: 439
Joined: Wed May 10, 2017 21:00
Location: some were in middle earth
GitHub: RSL-Redstonier
In-game: RSLRedstonier

Re: [Mod] Radiant damage [0.1]

by RSLRedstonier » Sun May 27, 2018 23:03

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
"A programmer is just a tool which converts caffeine into code"

try out my skytest mod always being updated!
https://forum.minetest.net/viewtopic.php?f=9&t=17568
 

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

Re: [Mod] Radiant damage [0.1]

by FaceDeer » Mon May 28, 2018 03:41

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: 1013
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: texmex

Re: [Mod] Radiant damage [0.1]

by texmex » Mon May 28, 2018 10:35

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: 461
Joined: Sat Jul 29, 2017 21:09
Location: Italia
IRC: H4mlet

Re: [Mod] Radiant damage [0.1]

by Hamlet » Mon May 28, 2018 12:54

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!
 

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

Re: [Mod] Radiant damage [0.2]

by FaceDeer » Tue May 29, 2018 06:45

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: 258
Joined: Sat Aug 29, 2015 19:01
GitHub: FaceDeer

Re: [Mod] Radiant damage [0.3]

by FaceDeer » Sun Jun 03, 2018 07:19

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: 735
Joined: Mon Apr 25, 2016 16:09
Location: Maryland, USA
GitHub: Gerold55
IRC: Gerold55
In-game: Gerold55

Re: [Mod] Radiant damage [0.3]

by GamingAssociation39 » Mon Jun 04, 2018 01:23

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

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

Re: [Mod] Radiant damage [0.3]

by FaceDeer » Mon Jun 04, 2018 01:39

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: 1013
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: texmex

Re: [Mod] Radiant damage [0.3]

by texmex » Mon Oct 01, 2018 18:34

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

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

Re: [Mod] Radiant damage [0.3]

by FaceDeer » Sun Oct 21, 2018 00:02

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: 1013
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: texmex

Re: [Mod] Radiant damage [0.3]

by texmex » Sun Oct 21, 2018 08:43

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: 258
Joined: Sat Aug 29, 2015 19:01
GitHub: FaceDeer

Re: [Mod] Radiant damage [0.3]

by FaceDeer » Mon Oct 22, 2018 02:29

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: 1013
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: texmex

Re: [Mod] Radiant damage [0.4]

by texmex » Mon Oct 22, 2018 06:15

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. ;)
 


Return to WIP Mods



Who is online

Users browsing this forum: No registered users and 10 guests