How to check that a player is in liquid?

How to check that a player is in liquid?

Postby TillCoyote » Wed Mar 20, 2019 6:32 am

I want to deny sprinting in water because of variable running speed. How to do so in maximally light way?
TillCoyote
Member
 
Posts: 43
Joined: Sat Jan 26, 2019 8:05 am

Re: How to check that a player is in liquid?

Postby disconnected » Wed Mar 27, 2019 2:18 am

Perhaps with an ABM? Every second get players within a radius of 1. Store player in mod storage for 1 second then remove & replace every second while they are in liquid. Check mod storage for player entry when sprinting.

Not sure if this is the most efficient method but ABMs only fire when the player is near the block AFAIK.
disconnected
Member
 
Posts: 16
Joined: Mon Mar 11, 2019 3:45 am
GitHub: discon-nected
In-game: disconnected

Re: How to check that a player is in liquid?

Postby TenPlus1 » Wed Mar 27, 2019 6:25 am

You could check out my PlayerPlus mod which adds new player effects and has a global table for checking what the player is standing on, standing in and at head level:

https://notabug.org/tenplus1/playerplus
TenPlus1
Member
 
Posts: 2534
Joined: Mon Jul 29, 2013 1:38 pm
GitHub: tenplus1

Re: How to check that a player is in liquid?

Postby disconnected » Wed Mar 27, 2019 6:31 am

TenPlus1 wrote:You could check out my PlayerPlus mod

But your mod scans nodes around every player every second.
Which method do you think would be the most efficient?
I suppose it depends on where the players are most likely to be. If in or near water often, your mod would be and vice versa.
disconnected
Member
 
Posts: 16
Joined: Mon Mar 11, 2019 3:45 am
GitHub: discon-nected
In-game: disconnected

Re: How to check that a player is in liquid?

Postby TenPlus1 » Wed Mar 27, 2019 12:38 pm

The only real way to see if a player is standing in water is to get the nodes they are standing on/in, and with playerplus each second is more than enough, doesnt lag, introduces many more features to the player and has a global table that can be accessed by many other mods so they dont need to get the nodes a 2nd time :)

I use it on Xanadu server if you wanna peek :P
TenPlus1
Member
 
Posts: 2534
Joined: Mon Jul 29, 2013 1:38 pm
GitHub: tenplus1

Re: How to check that a player is in liquid?

Postby sorcerykid » Sat Mar 30, 2019 3:07 am

It's too bad such functionality isn't provided directly by the Minetest API, since the engine already tracks the surrounding nodes of all physical objects at every server step.

Of even better yet, I wish Minetest supported a full-fledged event propagation system like the one invented by Looking Glass Studios for The Dark Engine. Then water source nodes could send a stimulus event to all objects that are immersed within the nodebox. Something like this would be cool :)

Code: Select all
minetest.override_node( "default:water_source", {
     sources = {
          {
               stimulus = "water_stim",
               propagator = "flow",
               intensity = 1.0,
               interval = 0.5,
          }
     }
}

minetest.register_stimulus( "water_stim", {
     on_flow = function ( pos, object, intensity )
          if object:is_player( ) then
               print( "Player is standing in water!" )
          end
     end
} )
sorcerykid
Member
 
Posts: 1026
Joined: Fri Aug 26, 2016 3:36 pm
GitHub: sorcerykid
In-game: Nemo

Re: How to check that a player is in liquid?

Postby TenPlus1 » Sat Mar 30, 2019 6:32 am

sorcerykid: I asked for such a think in github, since nodes around player are used to check collision then why not store inside a table for modders to access already.
TenPlus1
Member
 
Posts: 2534
Joined: Mon Jul 29, 2013 1:38 pm
GitHub: tenplus1



Return to Modding Discussion



Who is online

Users browsing this forum: Bing Bot [Bot] and 0 guests