minetest.register_privilege("build", "Can place and dig nodes/blocks")
minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing)
if not minetest.get_player_privs(placer:get_player_name()).build then
minetest.remove_node(pos)
return itemstack
end
end)
minetest.register_on_dignode(function(pos, oldnode, digger)
if not minetest.get_player_privs(digger:get_player_name()).build then
minetest.set_node({x=pos.x, y=pos.y, z=pos.z}, oldnode)
return
end
end)
CWz wrote:Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
minetest.register_privilege("build", "Can place and dig nodes/blocks")
minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing)
if not minetest.get_player_privs(placer:get_player_name()).build then
minetest.remove_node(pos)
return itemstack
end
end)
minetest.register_on_dignode(function(pos, oldnode, digger)
if not minetest.get_player_privs(digger:get_player_name()).build then
minetest.set_node({x=pos.x, y=pos.y, z=pos.z}, oldnode)
return
end
end)
this isn't working right. for some reason it still registers players as placing the nodes. also the register on dignode dignode give the player the item it digs.
local oldProtect = minetest.is_protected;
function minetest.is_protected(pos, playerName)
return not minetest.get_player_privs(playerName).build or
oldProtect(pos, playerName);
end;
prestidigitator wrote:Or use protection. This is pretty much what protection is designed for. For example:Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
local oldProtect = minetest.is_protected;
function minetest.is_protected(pos, playerName)
return not minetest.get_player_privs(playerName).build or
oldProtect(pos, playerName);
end;
Hybrid Dog wrote:this also would disallow using e.g. chests which are accessible for only the owner and members of a protected area
local cRadarLength = 3
local vNormalizedVel = vector.normalize(self.object:getvelocity())
local pEntityPos = self.object:getpos()
minp = {x = pEntityPos.x, y = pEntityPos.y - 2.5, z = pEntityPos.z}
maxp = vector.add(pEntityPos, vector.multiply(vNormalizedVel,cRadarLength))
maxp = {x = maxp.x, y = maxp.y + 1.5, z = maxp.z}
local nodes = minetest.find_nodes_in_area(minp, maxp, {"group:water"})
if #nodes > 0 then
for _,node in ipairs(nodes) do
print("node = "..minetest.pos_to_string(node))
end
end
funambulista wrote:I have seen these methods in the Player entity:
* get_look_dir() — get camera direction as a unit vector
* get_look_pitch() — pitch in radians
* get_look_yaw() — yaw
That maybe are the starting point to try to figure out if a node in a particular position is visible under that camera data and player position.
But this will require me to code some somewhat complex things. I wonder if there is a better and simpler way of doing it, some sort of API call or convenience function? maybe a different approach?
local function vectorDot(va, vb)
return va.x * vb.x + va.y * vb.y + va.z * vb.z;
end;
local blockDir = vector.normalize(vector.subtract(blockPos, player:getpos()));
local angle = math.acos(vectorDot(blockDir, player:get_look_dir()));
if angle <= VIEW_ANGLE then ... end;
nodebox_stack = {
type = "fixed",
fixed = {
{-0.4375, -0.5, 0.0625, -0.0625, -0.125, 0.4375}, -- unten, hinten_links
{0.125, -0.5, 0.125, 0.5, -0.125, 0.5}, -- unten, hinten_rechts
{-0.4375, -0.5, -0.375, -0.0625, -0.125, 0}, -- unten,vorne_links
{0.0625, -0.5, -0.4375, 0.4375, -0.125, -0.0625}, -- unten, vorne_rechts
{-0.1875, -0.125, -0.125, 0.1875, 0.25, 0.25}, -- oben, mitte
},
}
function generate_stack(item)
local nodedef = table.copy(minetest.registered_nodes[item]);
local modnode = string.split(item,":");
local mod = modnode[1];
local node = modnode[2];
nodedef.description = nodedef.description .." Stack";
nodedef.drawtype = "nodebox";
nodedef.selection_box = nil;
local nodebox = {
type = "fixed",
fixed = {},
}; --initialize empty nodebox
for number = 1, 5, 1 do
nodebox.fixed[number] = nodebox_stack.fixed[number];--copy a part to nodebox
nodedef.node_box = nodebox;--add nodebox to nodedef
nodedef.selection_box = {type="fixed",fixed= nodebox_stack.fixed[number]}
nodedef["drop"] = item.." "..number;--set drop
nodedef.name = item.."_stack_"..number;--set name
minetest.register_node(":"..nodedef.name, nodedef)--register node
print(dump2(minetest.registered_nodes[nodedef.name],nodedef.name))
end
end
minetest.register_node("test:item", {
description = "Item",
stack_max = 99,
tiles = {"default_wood.png"},
paramtype = "light",
groups = {cracky=2}
})
generate_stack("test:item");
addi wrote:I have a realy odd problem:
I have written a function that registeres 5 nodes and names that *_stack_<1-5>Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
nodebox_stack = {
type = "fixed",
fixed = {
{-0.4375, -0.5, 0.0625, -0.0625, -0.125, 0.4375}, -- unten, hinten_links
{0.125, -0.5, 0.125, 0.5, -0.125, 0.5}, -- unten, hinten_rechts
{-0.4375, -0.5, -0.375, -0.0625, -0.125, 0}, -- unten,vorne_links
{0.0625, -0.5, -0.4375, 0.4375, -0.125, -0.0625}, -- unten, vorne_rechts
{-0.1875, -0.125, -0.125, 0.1875, 0.25, 0.25}, -- oben, mitte
},
}
function generate_stack(item)
local nodedef = table.copy(minetest.registered_nodes[item]);
local modnode = string.split(item,":");
local mod = modnode[1];
local node = modnode[2];
nodedef.description = nodedef.description .." Stack";
nodedef.drawtype = "nodebox";
nodedef.selection_box = nil;
local nodebox = {
type = "fixed",
fixed = {},
}; --initialize empty nodebox
for number = 1, 5, 1 do
nodebox.fixed[number] = nodebox_stack.fixed[number];--copy a part to nodebox
nodedef.node_box = nodebox;--add nodebox to nodedef
nodedef.selection_box = {type="fixed",fixed= nodebox_stack.fixed[number]}
nodedef["drop"] = item.." "..number;--set drop
nodedef.name = item.."_stack_"..number;--set name
minetest.register_node(":"..nodedef.name, nodedef)--register node
print(dump2(minetest.registered_nodes[nodedef.name],nodedef.name))
end
end
minetest.register_node("test:item", {
description = "Item",
stack_max = 99,
tiles = {"default_wood.png"},
paramtype = "light",
groups = {cracky=2}
})
generate_stack("test:item");
The problem is, if i now use /giveme test:item_stack_3 (or another number 1-4)
its correctly in the inventory. But if I now place the node in the wold, it converts directly into test:item_stack_5
i dont see why it is placing _5 there instead of _3
Does someone have an idea?
prestidigitator wrote:funambulista wrote:I have seen these methods in the Player entity:
* get_look_dir() — get camera direction as a unit vector
* get_look_pitch() — pitch in radians
* get_look_yaw() — yaw
That maybe are the starting point to try to figure out if a node in a particular position is visible under that camera data and player position.
But this will require me to code some somewhat complex things. I wonder if there is a better and simpler way of doing it, some sort of API call or convenience function? maybe a different approach?
It's not really that complex. The dot product between the viewing direction and the direction of the block is the cosine of the angle between them. Basically:Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
local function vectorDot(va, vb)
return va.x * vb.x + va.y * vb.y + va.z * vb.z;
end;
local blockDir = vector.normalize(vector.subtract(blockPos, player:getpos()));
local angle = math.acos(vectorDot(blockDir, player:get_look_dir()));
if angle <= VIEW_ANGLE then ... end;
EDIT: Oops. Fixed vector subtraction.
afeys wrote:Hi,
I have two questions:
1/
there probably is a simple solution to this, but I'm making a mod (obviously) and I want to get a list of the location of all players.
Alternatively (even better), if someone knows the fastest way to check if any player currently playing in the minetest-world is within 10 blocks of x,y,z, I'd greatly appreciate it.
2/
is there an easy way to know if the world is already rendered at position x,y,z ?
In my mod I use abm's to generate world content, but I seem to remember reading somewhere on this forum that it can cause problems when the world is not available at the location I'm add content to.
thanks a lot
Ivà wrote:Hi afeys,
First question is solved in the example below :-)
http://dev.minetest.net/minetest.get_objects_inside_radius
Hybrid Dog wrote:Ivà wrote:Hi afeys,
First question is solved in the example below :-)
http://dev.minetest.net/minetest.get_objects_inside_radius
l guess it's faster if minetest.get_connected_players() (and vector.length(vector.subtract(yourpos, player:getpos()))) is used.
for _, player in ipairs(minetest.get_connected_players()) do
local v = vector.subtract(yourpos, player:getpos())
if v.x * v.x + v.y * v.y + v.z * v.z < 100 then
-- is less than 10 blocks
end
end
rubenwardy wrote:and it would be faster if you avoided the vector.subtract call (although not by much).
local chunk_active = minetest.get_node_or_nil(pos) and true or false
TenPlus1 wrote:Running two different protection mods isnt recommended at all and re-writing one to suit the other will only slow things down having to check for protection on both fronts... Use one or the other or if you want a happy inbetween try Protection Redo which allows you to modify the protected area around the protector nodes (using 'protector_radius = 5' setting in minetest.conf) as well as giving protected chests and doors:
viewtopic.php?f=9&t=9376
deezl wrote:I would like to make it possible for both to exist peacefully.
rubenwardy wrote:TenPlus1 wrote:Running two different protection mods isnt recommended at all and re-writing one to suit the other will only slow things down having to check for protection on both fronts... Use one or the other or if you want a happy inbetween try Protection Redo which allows you to modify the protected area around the protector nodes (using 'protector_radius = 5' setting in minetest.conf) as well as giving protected chests and doors:
viewtopic.php?f=9&t=9376
He can't just use one or the other, because he is running an active server world and needs backwards compatibility.
----
What is the behaviour you want if two zones overlap?
Sokomine wrote:deezl wrote:I would like to make it possible for both to exist peacefully.
How about an abm running on the protector nodes that automaticly sets up areas for the areas mod and make the protector node disappear afterwards? At least for those places where there's no conflict?
deezl wrote:Sokomine, not a bad idea. I was trying to look at the code for your markers mod for some clues on how to make the the protector mod work with areas, but I get a little lost in the coding sometimes. Any ideas from that direction, or is that a dead end?
Users browsing this forum: No registered users and 1 guest