abm / cactus / damage

Post Reply
User avatar
bosapara
Member
Posts: 637
Joined: Fri Apr 07, 2017 08:49

abm / cactus / damage

by bosapara » Post

abm for cactus damage isnt too much expensive for minetest perfomance?

Image

Code: Select all

minetest.register_abm({
   nodenames = {"default:cactus"},
   interval = 0.5,
   chance = 1,
   action = function(pos, node, active_object_count, active_object_count_wider)
      local players = minetest.get_objects_inside_radius(pos, 1)
         for i, player in ipairs(players) do
            player:set_hp(player:get_hp() - 3)
         end
   end,
})

User avatar
Casimir
Member
Posts: 1207
Joined: Fri Aug 03, 2012 16:59
GitHub: CasimirKaPazi

Re: abm / cactus / damage

by Casimir » Post

This is how I did it in Voxelgarden. Essentially it's just a smaller collision box, so you can stand "inside" the node, but with an smaller node box so it doesn't look strange.

Code: Select all

minetest.register_node("default:cactus", {
	description = "Cactus",
	drawtype = "nodebox",
	paramtype = "light",
	tiles = {"default_cactus_top.png", "default_cactus_top.png", "default_cactus_side.png"},
	groups = {snappy=1, choppy=3, flammable=2},
	node_box = {
		type = "fixed",
		fixed = {
			{-0.375, -0.5, -0.5, -0.375, 0.5, 0.5},
			{0.375, -0.5, -0.5, 0.375, 0.5, 0.5},
			{-0.5, -0.5, 0.375, 0.5, 0.5, 0.375},
			{-0.5, -0.5, -0.375, 0.5, 0.5, -0.375},
			{-0.375, -0.5, -0.375, 0.375, 0.5, 0.375},
		}
	},
	selection_box = {
		type = "fixed",
		fixed = {-0.375, -0.5, -0.375, 0.375, 0.5, 0.375}
	},
	collision_box = {
		type = "fixed",
		fixed = {
			{-0.1875, -0.5, -0.1875, 0.1875, 0.5, 0.1875},
		}
	},
	damage_per_second = 1,
	sounds = default.node_sound_wood_defaults(),
	after_dig_node = function(pos, node, metadata, digger)
		default.dig_up(pos, node, digger)
		default.dig_up(pos, {name = "default:cactus_fig"}, digger)
	end,
})
Image

User avatar
bosapara
Member
Posts: 637
Joined: Fri Apr 07, 2017 08:49

Re: abm / cactus / damage

by bosapara » Post

Casimir wrote:This is how I did it in Voxelgarden. Essentially it's just a smaller collision box, so you can stand "inside" the node, but with an smaller node box so it doesn't look strange.
Already checked this variant, unfortunately damage will not work when we walk at the cactus

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: abm / cactus / damage

by Krock » Post

bosapara wrote:Already checked this variant, unfortunately damage will not work when we walk at on the cactus
Then try manipulating the Y value of the collision box a bit like this: (untested)

Code: Select all

	collision_box = {
		type = "fixed",
		fixed = {
			{-0.1875, -0.5, -0.1875, 0.1875, 0.45, 0.1875},
		}
	},
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
bosapara
Member
Posts: 637
Joined: Fri Apr 07, 2017 08:49

Re: abm / cactus / damage

by bosapara » Post

Krock wrote: Then try manipulating the Y value of the collision box a bit like this: (untested)
yep, almost, this works perfect:

Code: Select all

	collision_box = {
      type = "fixed",
      fixed = {
         {-0.1875, -0.5, -0.1875, 0.1875, 0.375, 0.1875},
    },

User avatar
Hybrid Dog
Member
Posts: 2834
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: abm / cactus / damage

by Hybrid Dog » Post

Sam shouldn't be damaged when standing on a cactus because he wears shoes.

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

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

Re: abm / cactus / damage

by Hamlet » Post

Technical question:

Given that the same can be achieved with node timers, which would be the best method?

Or, which is the best one for memory saving and server load?
My repositories: Codeberg.org | My ContentDB's page

User avatar
sorcerykid
Member
Posts: 1847
Joined: Fri Aug 26, 2016 15:36
GitHub: sorcerykid
In-game: Nemo
Location: Illinois, USA

Re: abm / cactus / damage

by sorcerykid » Post

This is the collision box setting I use for default:cactus on JT2, derived from rnd's "cactus hurt" patch.

Code: Select all

        collision_box = {
                type = "fixed",
                -- Adjust collision box so it damages players that are too
                -- close. We need to allow them to "enter" into the node a
                -- little bit for this to actually happen. The top is low
                -- enough that feet damage occurs if standing on it.
                fixed = { -7/16, -1/2, -7/16, 7/16, 5/16, 7/16 },
        },

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: abm / cactus / damage

by Krock » Post

@Hamlet, @bosapara: Some additions in regard to the best performance, as there are currently four possibilities to do this:

1) ABMs
Pro: Is triggered for each cactus node, can damage players using `minetest.get_objects_inside_radius(pos, 1)`
Contra: Somewhat slow and triggers on irrelevant nodes. Don't use it.
2) Node Timers
Pro: Is triggered only for the top cactus node (requires optimizations in the mod)
Contra: Node Timers are triggered even when there's no player + requires optimizations to reduce the active node timers
3) register globalstep
Pro: Only checks positions where the players are
Contra: Also checks positions where no cactus is found nearby
4) Engine/built-in
Pro: Only checks positions where the players are + no Lua callbacks to execute
Contra: Also checks positions where no cactus is found nearby + the feet are inside the visible cactus (looks weird)

Idea (3) and (4) have generally a better efficiency because there are more cactus nodes than players in the loaded mapblocks. However, if there are many players in a world where cactus is (near to) non-existent, then it's idea (2) which is the next best solution when you want to avoid the visual side-effect of (4).
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
TenPlus1
Member
Posts: 3721
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: abm / cactus / damage

by TenPlus1 » Post

My PlayerPlus mod handles everything inside a single globalstep so that it's less strain on a server and will do cactus damage, suffocation, player knockback, walking speed changes, on_walk_over nodes and has player_monoids and pova support for the changes...

https://notabug.org/tenplus1/playerplus

Astrobe
Member
Posts: 577
Joined: Sun Apr 01, 2018 10:46

Re: abm / cactus / damage

by Astrobe » Post

Krock wrote:@Hamlet, @bosapara: Some additions in regard to the best performance, as there are currently four possibilities to do this:

1) ABMs
2) Node Timers
3) register globalstep
4) Engine/built-in
5) "on_collide" callback for players and entities
Pros: it solves all sorts of other problems
Cons: backport to version 0.0.1 needed because it should have been there right from the beginning.

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: abm / cactus / damage

by Krock » Post

Astrobe wrote:5) "on_collide" callback for players and entities
I think you forgot the part with "Lua function call performance" and "redundant callback call flood". It's not like this was requested before, or anything like that. (sarcasm)

Letting the engine handle this internally by the given node definition is actually the best approach performance-wise in this case.
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

Astrobe
Member
Posts: 577
Joined: Sun Apr 01, 2018 10:46

Re: abm / cactus / damage

by Astrobe » Post

"redundant callback call flood": just have the user to rearm the callback once fired (like we do with after()), so that mods can deal with the problem with a timer if needed. Works in this case, it works with arrows, it works with mobs.

"Lua function call performance": compared to either the broken collision detection Lua code I have seen (with get_object_in_radius) or the correct but expensive collision box checks, it doesn't look that bad to me.

Offloading the burden to Lua scripts just hurts everyone more. But yeah, keep the issue closed and keep adding ad hoc solutions instead.

User avatar
Hybrid Dog
Member
Posts: 2834
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: abm / cactus / damage

by Hybrid Dog » Post

With server-provided CSM an on_collide function could be executed client-side.

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

Astrobe
Member
Posts: 577
Joined: Sun Apr 01, 2018 10:46

Re: abm / cactus / damage

by Astrobe » Post

I don't want to be look like the stubborn guy who takes down any other solution than his, but I have two issues with CSM.

First, I don't like the idea of running random code from a random source. Browsers do this all the time. It lead to abuse, so now there are browser extensions to block JS.

More importantly, the second problem is that you don't know the client machine specs (could be a gaming PC, could be a low-end tablet), so you don't know how much you can offload to them.

Suppose we do the on_collide stuff via CSM. We assume that it's no big deal for the client machine. Now add Paramat's Snowdrift that adds some particle handling stuff to the workload of the client. Is it still ok? Then add a couple of other mods that delegate other awesome stuff to the client and when your players say the game is "laggy", you will have no idea if it's a network problem or if that was because your players had a cactus bumping party under heavy rain.

Astrobe
Member
Posts: 577
Joined: Sun Apr 01, 2018 10:46

Re: abm / cactus / damage

by Astrobe » Post

For the collision box solution above, since that hack makes the character "enter" the node, you might want to disable backface culling; for instance:

Code: Select all

	tiles = {"default_cactus_top.png", "default_cactus_top.png", {name="default_cactus_side.png", backface_culling=false}},

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

Re: abm / cactus / damage

by Hamlet » Post

Krock wrote: 1) ABMs
[...]
2) Node Timers
[...]
3) register globalstep
[...]
4) Engine/built-in
[...]

Idea (3) and (4) have generally a better efficiency because there are more cactus nodes than players in the loaded mapblocks. However, if there are many players in a world where cactus is (near to) non-existent, then it's idea (2) which is the next best solution when you want to avoid the visual side-effect of (4).
Thanks, your answer has cleared my doubts; when I will rewrite "Killer Nodes" I will use the fourth method - I thought about using node timers instead of ABMs, but running timers when there aren't players around isn't an option.

I don't mind about the visual glitch: after all we already have mobs that often end with their heads buried into nodes due to how collision boxes work.

Thanks again. :)
My repositories: Codeberg.org | My ContentDB's page

Post Reply

Who is online

Users browsing this forum: rudzik8 and 11 guests