Page 1 of 1

Cycling through nodes

PostPosted: Wed Apr 04, 2012 22:09
by bgsmithjr
There should a poll player position function or something, Instead of cycling through every block in the game,about my previous post, this isn't the engines fault. That way you can always get the players position without relying on nodes. To get an object reference to a player, you have to find him in the radius from a node, hit a node, or step on a node. So now I have to use an abm, or the nodes on step function, or the nodes punch or dig funtion. Because I can't cycle through every air block to find it is the right height, then drop a snow entity underneath it without lagging. I was wanting to just add it 30 blocks above the player as long as it is air. Well there was another problem, I couldn't get the position of an air node. If the block 30 spaces above a player was not nil it should drop a snowflake, but it won't let me do that from an abm. Air abm possible???

PostPosted: Wed Apr 04, 2012 22:32
by bgsmithjr
Ok i got, you read the setting from the config using minetest.get_setting
get the player name
get player by name
player:getpos
But cycling thru so many nodes is still a problem.

PostPosted: Wed Apr 04, 2012 23:16
by randomproof
Why not use something like this:
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_globalstep(function(dtime)
    timer = timer + dtime
    if timer >= 2 then
        timer = timer - 2
    else
        return
    end
    for name, p_obj in pairs(minetest.get_connected_players()) do
        pos = p_obj:getpos()
        pos.y = pos.y+30
        if minetest.env:get_node(pos).name == "air" then
            -- Your code here to add snowflake at pos
        end   
    end
end)

PostPosted: Wed Apr 04, 2012 23:49
by bgsmithjr
Because it is not network related, it just for client, the player that is running the client is automatically the player and you automatically have their position, and I am not familiar with onstep, is this a tick of time.
global step? I would need more help, and what is the function with dtime for?

PostPosted: Wed Apr 04, 2012 23:55
by bgsmithjr
I need something that will place a snow flake at the top border of the chunk that is loaded, every other second. but it lags too much. your solution is good, but too many sprites lags it too much to play so its impossible to make anyweather. Unless you try making them craftitems or blocks, but I think blocks will lag too.

PostPosted: Thu Apr 05, 2012 01:35
by jn
You can now use minetest.get_connected_players().

PostPosted: Thu Apr 05, 2012 03:57
by bgsmithjr
thanks, but there is no way around the lag from having so many sprites.

PostPosted: Thu Apr 05, 2012 10:08
by Jordach
why not for singleplAyer, just make them spawn in front of the player?

PostPosted: Thu Apr 05, 2012 10:17
by bgsmithjr
I don't know what you mean, one block in front of the player only?

PostPosted: Thu Apr 05, 2012 11:54
by Jordach
Sorry, I WAS ON A TABLET.

Now, the snow particles should only spawn in front of the player in Singleplayer. and not in multi.

So, if the paticles spawn in front of the camera, shoudn't they reduce lag?

Well actually SSP should do so.

Make them spawn in 16 by 16 blocks around the player.