Limit the abuse of lava

Post Reply
Sporax
Member
Posts: 149
Joined: Mon Jul 11, 2016 16:33
GitHub: Sporax
IRC: Sporax
In-game: Sporax
Location: France

Limit the abuse of lava

by Sporax » Post

Hello guys,

i'm glad to ask for help here again :). I've a new problem, i would like to prevent the use of lava in a certain area.
I've made a quite little mod for that, but... now i would like to add an exception and permit to someone with a priv to put lava into this area.

Here is the problem, how to modify this to solve my problem ?

Code: Select all

local pos={x=0,y=0,z=0}
local rad=500
local rad2=-500

minetest.override_item("default:lava_source", {
   on_construct = function(pos)
      if rad2<pos.x and pos.x<rad and rad2<pos.y and pos.y<rad and rad2<pos.z and pos.z<rad then
         minetest.env:remove_node(pos)
      end
   end
})
That's an override, then... is there any solution ?

I've tested another idea with this:

Code: Select all

local pos={x=0,y=0,z=0}
local rad=500
local rad2=-500

minetest.register_privilege("overridelavazone", {
	description = "Autorise le placement de lave",
	give_to_singleplayer = false,
})

minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing)
    if rad2<pos.x and pos.x<rad and rad2<pos.y and pos.y<rad and rad2<pos.z and pos.z<rad and (newnode.name == "default:lava_source") and not minetest.check_player_privs(placer:get_player_name(),{overridelavazone = true}) then
        minetest.env:remove_node(pos)
    end
end)
but lava buckets are not detected :(

Thanks for reading !

Eran
Member
Posts: 123
Joined: Fri May 03, 2019 16:46

Re: Limit the abuse of lava

by Eran » Post

Accidental post, please ignore
Last edited by Eran on Sat Apr 18, 2020 15:13, edited 1 time in total.

Sporax
Member
Posts: 149
Joined: Mon Jul 11, 2016 16:33
GitHub: Sporax
IRC: Sporax
In-game: Sporax
Location: France

Re: Limit the abuse of lava

by Sporax » Post

Eran wrote:

Code: Select all

minetest.override_item("bucket:bucket_lava",
)
Hi,

I don't really understand what you are meaning... the first solution is an override (it works, it detect when a lava_bucket is placed) that's not the problem. It's to add an exception for a player with a priv.

The second idea is not an override, it only works with lava source, and the priv works... the problem here is te detect lava_bucket placement.

Thanks

Eran
Member
Posts: 123
Joined: Fri May 03, 2019 16:46

Re: Limit the abuse of lava

by Eran » Post

Not tested but try this

Code: Select all

local pos={x=0,y=0,z=0}
local rad=500
local rad2=-500

minetest.register_privilege("overridelavazone", {
   description = "Autorise le placement de lave",
   give_to_singleplayer = false,
})

local old_on_place = minetest.registered_items["bucket:bucket_lava"].on_place

minetest.override_item("bucket:bucket_lava", {
	on_place = function(itemstack, placer, pointed_thing)
		if not minetest.check_player_privs(placer, "overridelavazone") and --privilege check
			rad2<pos.x and pos.x<rad and rad2<pos.y and pos.y<rad and rad2<pos.z and --zone check
			pos.z<rad
		then
			return
		end
		old_on_place(itemstack, placer, pointed_thing)
	end
})
The problem with the on_placenode approach is that the default on_place (minetest.item_place_node) calls it but the bucket's custom on_place function doesn't.

Sporax
Member
Posts: 149
Joined: Mon Jul 11, 2016 16:33
GitHub: Sporax
IRC: Sporax
In-game: Sporax
Location: France

Re: Limit the abuse of lava

by Sporax » Post

That's a great explanation !

I've tried your code, i've an error when i've tested it:

Code: Select all

2020-04-18 17:34:30: ERROR[Main]: ModError: Failed to load and run script from C:\Users\***\Documents\Minetest\minetest\bin\..\mods\nolava\init.lua:
2020-04-18 17:34:30: ERROR[Main]: ...h\Documents\Minetest\minetest\bin\..\mods\nolava\init.lua:24: attempt to index field 'bucket:bucket_lava' (a nil value)
2020-04-18 17:34:30: ERROR[Main]: stack traceback:
2020-04-18 17:34:30: ERROR[Main]: 	...h\Documents\Minetest\minetest\bin\..\mods\nolava\init.lua:24: in main chunk
2020-04-18 17:34:30: ERROR[Main]: Voir debug.txt pour plus d'informations.
2020-04-18 17:34:30: ACTION[Main]: Server: Shutting down

Eran
Member
Posts: 123
Joined: Fri May 03, 2019 16:46

Re: Limit the abuse of lava

by Eran » Post

You need to put bucket as a dependency of your mod.

Sporax
Member
Posts: 149
Joined: Mon Jul 11, 2016 16:33
GitHub: Sporax
IRC: Sporax
In-game: Sporax
Location: France

Re: Limit the abuse of lava

by Sporax » Post

Okay right fix !

The code is running and the priv is working. Howerver there are 2 probs:
-Buckets are not empty after being placed
-The area is not respected, if i have the priv i can set a bucket everywhere and if i don't have the priv, i can't set a bucket everwhere

Eran
Member
Posts: 123
Joined: Fri May 03, 2019 16:46

Re: Limit the abuse of lava

by Eran » Post

Actually this got a bunch more complicated. Again, not tested.

Code: Select all

local rad=500
local rad2=-500

minetest.register_privilege("overridelavazone", {
   description = "Autorise le placement de lave",
   give_to_singleplayer = false,
})

local old_on_place = minetest.registered_items["bucket:bucket_lava"].on_place

minetest.override_item("bucket:bucket_lava", {
   on_place = function(itemstack, placer, pointed_thing)
	  if pointed_thing.type ~= "node" then
	      return
	  end
	  --position getting code from bucket mod
	  local node = minetest.get_node_or_nil(pointed_thing.under)
		local ndef = node and minetest.registered_nodes[node.name]
		local pos

		-- Check if pointing to a buildable node
		if ndef and ndef.buildable_to then
			-- buildable; replace the node
			pos = pointed_thing.under
		else
			-- not buildable to; place the liquid above
			-- check if the node above can be replaced

			pos = pointed_thing.above
			node = minetest.get_node_or_nil(pos)
			local above_ndef = node and minetest.registered_nodes[node.name]

			if not above_ndef or not above_ndef.buildable_to then
				-- do not remove the bucket with the liquid
				return itemstack
			end
		end
	  --check if is in no lava area and player doesn't have the privilege
      if not minetest.check_player_privs(placer, "overridelavazone") and --privilege check
         rad2<pos.x and pos.x<rad and rad2<pos.y and pos.y<rad and rad2<pos.z and --zone check
         pos.z<rad
      then
         return
      end
      --return this so the bucket is emptied
      return old_on_place(itemstack, placer, pointed_thing)
   end
})

Sporax
Member
Posts: 149
Joined: Mon Jul 11, 2016 16:33
GitHub: Sporax
IRC: Sporax
In-game: Sporax
Location: France

Re: Limit the abuse of lava

by Sporax » Post

It work as well!!!

Thanks for your time! And Thank you so much.

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests