How to activate player fly mode by a lua code?

Post Reply
drkwv
Member
Posts: 102
Joined: Thu Jun 28, 2012 13:48
GitHub: aa6

How to activate player fly mode by a lua code?

by drkwv » Post

I want when a player hits a specific block, put (and even force) him into a fly+noclip mode. Is this possible?

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: How to activate player fly mode by a lua code?

by texmex » Post

IIRC the player can be granted usage of the modes programmatically in such a case, but the player still has to manually activate the modes.

User avatar
Yvanhoe
Member
Posts: 140
Joined: Fri Jul 05, 2019 03:18
Location: Japan

Re: How to activate player fly mode by a lua code?

by Yvanhoe » Post

You can set gravity individually for a player: player:set_physics_override({jump=0}). I am less sure for the noclip mode. Have you tried changing the player's collision box?

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: How to activate player fly mode by a lua code?

by texmex » Post

Player gravity isn't the same as fly mode though.

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: How to activate player fly mode by a lua code?

by Krock » Post

A) The server does neither know about the player's free_move, noclip nor fast move settings. There's no way to control either of these using a Lua mod.
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

drkwv
Member
Posts: 102
Joined: Thu Jun 28, 2012 13:48
GitHub: aa6

Re: How to activate player fly mode by a lua code?

by drkwv » Post

Yvanhoe wrote:You can set gravity individually for a player: player:set_physics_override({jump=0}). I am less sure for the noclip mode. Have you tried changing the player's collision box?
Although I've managed to simulate the derised using this code:

Code: Select all

local players = {}
-- Create a block.
minetest.register_node(minetest.get_current_modname()..":ghost_block",
{
  description = "A ghost block.",
  tiles = {"default_dirt.png^[colorize:#FFFFFFFF"}, 
  on_rightclick = function(pos, node, player, pointed_thing)
    players[player:get_player_name()] = player
    minetest.chat_send_all(player:get_player_name().." is a ghost.")
    player:set_physics_override({gravity=0,jump=0})
    player:set_properties({collisionbox={0,0,0,0,0,0}})
  end
})
-- Scan the controls.
minetest.register_globalstep(function(seconds_since_last_global_step)
  local controls
  for player_name,player in pairs(players) do
    controls = player:get_player_control()
    if controls.jump then
      player:set_physics_override({gravity=-1})
    elseif controls.sneak then
      player:set_physics_override({gravity=1})
    else
      player:set_physics_override({gravity=0})
    end
  end
end)
It's not the same as a fly mode as texmex has mentioned. And noclip is also not the same. Player is not moving in the direction of sight and suffers fall damage being unable to go through the floor blocks.
Krock wrote:There's no way to control either of these using a Lua mod.
Since switching into a fly/noclip mode is not a server responsibility, would it be possible then with the client-side mods when an API for them will be finished?

drkwv
Member
Posts: 102
Joined: Thu Jun 28, 2012 13:48
GitHub: aa6

Re: How to activate player fly mode by a lua code?

by drkwv » Post

I have found out it is possible to do by attaching a player to an object. So I created a small mod library that provides an interface for it. Although it's working, I still believe that it would've been better to make it by manipulating fly+noclip modes since this mod just duplicates a feature that Minetest already has built-in by default.

https://github.com/aa6/minetest_mod_lib_astral_body

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests