Hello.
I am working on a mod for a larger game that I'm also working on. This mod is a sort of "magic barrier". I want the player to be able to pass through it only if they hold a certain item, and impassible if they do not. This magic-barrier node needs to work in multi-player mode and block _all_ players that do not hold the "key" (ring, doodad, mccguffin, etc...) that allows passage. I am fine with the "key" being a wielded item, or simply something held in inventory.
Currently I just have a simple node that has a semi-transparent texture and has "walkable = true". I am not sure how to proceed. I wonder if I should set "walkable = false" and block ineligible players from passing through via some other means.
Is there an existing mod or node in some mod that implements similar functionality so that I can study how that one works?
Thank you for your time.
Implementing a node that is walkable for some players, not walkable for others
-
- New member
- Posts: 6
- Joined: Wed May 13, 2020 03:37
- GitHub: dennisjenkins75
- IRC: dennisjenkins
Re: Implementing a node that is walkable for some players, not walkable for others
Have a 1-2s timer on that node. In the timer's callback, scan for entities in a short radius. If the node detects its owner (set as node metadata when the player places the node), then turn your solid node into a walkable node (so you need 2 nodes - you'll probably want that they look exactly the same). The walkable has to also have a timer, with an similar process but to turn in back into the solid version.
You can add extra checks that there's nobody else around if you want to make sure only the owner can walk through.
The period of the timer and the size of the radius depend on the walking speed of your players.
PS: just in case, if you can accept that the player has to do something with an item to be able to go through, it makes things a lot easier, because your barrier can work basically like a common door - perhaps with auto-closing.
You can add extra checks that there's nobody else around if you want to make sure only the owner can walk through.
The period of the timer and the size of the radius depend on the walking speed of your players.
PS: just in case, if you can accept that the player has to do something with an item to be able to go through, it makes things a lot easier, because your barrier can work basically like a common door - perhaps with auto-closing.
-
- New member
- Posts: 6
- Joined: Wed May 13, 2020 03:37
- GitHub: dennisjenkins75
- IRC: dennisjenkins
Re: Implementing a node that is walkable for some players, not walkable for others
I think that if "walkable" would accept a boolean or a function (that took the node's position and player's name) returning a boolean, I could solve this the way that I'd like to. Existing boolean walkables would behave as they currently do, but if walkable was a function, then it would be called by the game engine and the return value would determine walkability.
But another solution just occurred to me. If the player attempts to "interact" with the barrier node, the magic key item's interaction code could teleport the player to the other side of the barrier.
btw, in my game these "barriers" are not owned by any player and are not craftable. They are immutable nodes spawned inside some special dungeons. To enter the dungeon, the player must first find/craft the magic key to that allows passage (probably a ring, staff or some other "magic" thingy, not an actual key for a mechanical lock).
But another solution just occurred to me. If the player attempts to "interact" with the barrier node, the magic key item's interaction code could teleport the player to the other side of the barrier.
btw, in my game these "barriers" are not owned by any player and are not craftable. They are immutable nodes spawned inside some special dungeons. To enter the dungeon, the player must first find/craft the magic key to that allows passage (probably a ring, staff or some other "magic" thingy, not an actual key for a mechanical lock).
- GreenXenith
- Member
- Posts: 1335
- Joined: Wed Oct 28, 2015 01:26
- GitHub: GreenXenith
- IRC: GreenXenith
- In-game: GreenXenith
- Location: The singularity
- Contact:
Re: Implementing a node that is walkable for some players, not walkable for others
Your teleport solution is better, regardless.
The reason you cannot arbitrarily change the solidity of a node at runtime is because nodes can only be registered on load. So to toggle the walkable key in a node would require two nodes, swapping based on some external input. This would not be very effective though, because if you have 2 players occupying the same space, the nodes would either swap rapidly, allow all players through, or lock all players out. Regardless of the implementation (live property editing or node swapping), this issue would remain.
Your solution to teleport to the other side of the barrier removes those edge cases, and is cleaner, in my opinion.
The reason you cannot arbitrarily change the solidity of a node at runtime is because nodes can only be registered on load. So to toggle the walkable key in a node would require two nodes, swapping based on some external input. This would not be very effective though, because if you have 2 players occupying the same space, the nodes would either swap rapidly, allow all players through, or lock all players out. Regardless of the implementation (live property editing or node swapping), this issue would remain.
Your solution to teleport to the other side of the barrier removes those edge cases, and is cleaner, in my opinion.
Y▹uTube | Mods | Patre●n | Twitter | Minetest Discord | GreenXenith#3232
Hey, you. You're finally awake.
You were trying to view their profile, right? Found the rest of their signature, same as us, and that guest over there.
Hey, you. You're finally awake.
You were trying to view their profile, right? Found the rest of their signature, same as us, and that guest over there.
Who is online
Users browsing this forum: No registered users and 5 guests