player on_step?
- 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?
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.
- 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?
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.
- 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?
Baaadddd ideaPolySaken wrote:well, registering a globalstep in on_joinplayer seems to work...
Just iterate through players with get_connected_players() in a global step
- Linuxdirk
- Member
- Posts: 3219
- Joined: Wed Sep 17, 2014 11:21
- In-game: Linuxdirk
- Location: Germany
- Contact:
Re: player on_step?
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)
- 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?
ok...rubenwardy wrote:Baaadddd ideaPolySaken wrote:well, registering a globalstep in on_joinplayer seems to work...
Just iterate through players with get_connected_players() in a global step
but why is that a bad idea?
Guidebook Lib, for in-game docs | Poly Decor, some cool blocks | Vision Lib, an all-purpose library.
- 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?
oh thx!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)
Guidebook Lib, for in-game docs | Poly Decor, some cool blocks | Vision Lib, an all-purpose library.
- 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?
Because the size of the callback table will increase everytime a player joins, causing the server to gradually slow downPolySaken wrote:ok...rubenwardy wrote:Baaadddd ideaPolySaken wrote:well, registering a globalstep in on_joinplayer seems to work...
Just iterate through players with get_connected_players() in a global step
but why is that a bad idea?
- 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?
oh alrightrubenwardy wrote:Because the size of the callback table will increase everytime a player joins, causing the server to gradually slow down
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.
- 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?
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
It only registers the callback once and iterates through. It's not hacky and won't cause slowdowns after hours of run time
- 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?
ok
Guidebook Lib, for in-game docs | Poly Decor, some cool blocks | Vision Lib, an all-purpose library.
Who is online
Users browsing this forum: No registered users and 17 guests