player on_step?

Post Reply
User avatar
PolySaken
Member
Posts: 817
Joined: Thu Nov 09, 2017 05:18
GitHub: PolySaken-I-Am
In-game: PolySaken
Location: Wānaka, Aotearoa
Contact:

player on_step?

by PolySaken » Post

is there a way (api or otherwise) to have a per-player function that is called at the same interval as a globalstep?
Guidebook Lib, for in-game docs | Poly Decor, some cool blocks | Vision Lib, an all-purpose library.

User avatar
PolySaken
Member
Posts: 817
Joined: Thu Nov 09, 2017 05:18
GitHub: PolySaken-I-Am
In-game: PolySaken
Location: Wānaka, Aotearoa
Contact:

Re: player on_step?

by PolySaken » Post

well, registering a globalstep in on_joinplayer seems to work...
Guidebook Lib, for in-game docs | Poly Decor, some cool blocks | Vision Lib, an all-purpose library.

User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: player on_step?

by rubenwardy » Post

PolySaken wrote:well, registering a globalstep in on_joinplayer seems to work...
Baaadddd idea

Just iterate through players with get_connected_players() in a global step
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: player on_step?

by Linuxdirk » Post

Code: Select all

minetest.register_globalstep(function(dtime)
    for _,player in ipairs(minetest.get_connected_players()) do
        local move = player:get_player_control()
        if move.up or move.down or move.left or move.right then
            -- do whatever you want if the player moves
        end
    end
end)

User avatar
PolySaken
Member
Posts: 817
Joined: Thu Nov 09, 2017 05:18
GitHub: PolySaken-I-Am
In-game: PolySaken
Location: Wānaka, Aotearoa
Contact:

Re: player on_step?

by PolySaken » Post

rubenwardy wrote:
PolySaken wrote:well, registering a globalstep in on_joinplayer seems to work...
Baaadddd idea

Just iterate through players with get_connected_players() in a global step
ok...
but why is that a bad idea?
Guidebook Lib, for in-game docs | Poly Decor, some cool blocks | Vision Lib, an all-purpose library.

User avatar
PolySaken
Member
Posts: 817
Joined: Thu Nov 09, 2017 05:18
GitHub: PolySaken-I-Am
In-game: PolySaken
Location: Wānaka, Aotearoa
Contact:

Re: player on_step?

by PolySaken » Post

Linuxdirk wrote:

Code: Select all

minetest.register_globalstep(function(dtime)
    for _,player in ipairs(minetest.get_connected_players()) do
        local move = player:get_player_control()
        if move.up or move.down or move.left or move.right then
            -- do whatever you want if the player moves
        end
    end
end)
oh thx!
Guidebook Lib, for in-game docs | Poly Decor, some cool blocks | Vision Lib, an all-purpose library.

User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: player on_step?

by rubenwardy » Post

PolySaken wrote:
rubenwardy wrote:
PolySaken wrote:well, registering a globalstep in on_joinplayer seems to work...
Baaadddd idea

Just iterate through players with get_connected_players() in a global step
ok...
but why is that a bad idea?
Because the size of the callback table will increase everytime a player joins, causing the server to gradually slow down
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
PolySaken
Member
Posts: 817
Joined: Thu Nov 09, 2017 05:18
GitHub: PolySaken-I-Am
In-game: PolySaken
Location: Wānaka, Aotearoa
Contact:

Re: player on_step?

by PolySaken » Post

rubenwardy wrote:Because the size of the callback table will increase everytime a player joins, causing the server to gradually slow down
oh alright
but the other method also gets all the players...?
so i imagine it can't be that different on a fast computer
Guidebook Lib, for in-game docs | Poly Decor, some cool blocks | Vision Lib, an all-purpose library.

User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: player on_step?

by rubenwardy » Post

It's massively different, just use the way I suggested and Linux Dirk showed.

It only registers the callback once and iterates through. It's not hacky and won't cause slowdowns after hours of run time
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
PolySaken
Member
Posts: 817
Joined: Thu Nov 09, 2017 05:18
GitHub: PolySaken-I-Am
In-game: PolySaken
Location: Wānaka, Aotearoa
Contact:

Re: player on_step?

by PolySaken » Post

ok
Guidebook Lib, for in-game docs | Poly Decor, some cool blocks | Vision Lib, an all-purpose library.

Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests