How to activate player fly mode by a lua code?

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

How to activate player fly mode by a lua code?

by drkwv » Sun Sep 01, 2019 17:56

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: 1536
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: texmex

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

by texmex » Mon Sep 02, 2019 07:59

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: 121
Joined: Fri Jul 05, 2019 03:18
Location: Japan

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

by Yvanhoe » Mon Sep 02, 2019 08:49

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: 1536
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: texmex
 

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

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

by Krock » Mon Sep 02, 2019 16:07

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.
>> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
 

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

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

by drkwv » Sat Sep 07, 2019 14:13

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: 87
Joined: Thu Jun 28, 2012 13:48
GitHub: aa6

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

by drkwv » Sun Sep 08, 2019 13:12

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
 


Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 6 guests