Make rooms only being able to have one player in it at once

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the community!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Polar882

Member
Jul 12, 2023
3
0
1
Hello so I want to have shulker rooms on my server. Basically rooms that you enter by right clicking a black concrete. I have figured out the most of it but I cant get hands on how to make so only one player can be in the shulker room at once preventing players from stealing other shulkers. Anyways here is the skript!

on load:
loop 5 times:
if {spawn.shulker%loop-number%} is set:
add {spawn.shulker%loop-number%} to {shulkerlist::*}
on unload:
delete {shulkerlist::*}

on rightclick on black concrete:
set {_shulkertp} to a random element out of {shulkerlist::*}
send "test"
teleport player to {_shulkertp}
stop

command /setshulkerroom [<int>] [<text>]:
permission message: &cNo permissions.
permission: rank.admin
usage: /setshulkerroom <number>
aliases: ssr
executable by: players
trigger:
if arg-1 is set:
if arg-2 is not set:
set {spawn.shulker%arg-1%} to player's location
send "&aSpawn for dungeon %arg-1% set!"
stop
else:
stop
else:
send "&cUsage: /setshulker <number>"
 
To resolve this issue, you'll need to set a separate variable to check when a player enters a shulker room and when they leave. It would kind of like something like this:

Code:
function tp(p: player, loc: text): # Example of function you can use to handle if a room is/isn't occupied
   close {_p}'s inventory
   teleport {_p} to {_loc}
   send "&dTeleporting.." to {_p}
   set {room1} to "true"
   if loc is "fail":
      send "&cError&4! &cThis room is occupied&4!!" to {_p}

# Check if player leaves a room then:
   clear {room1}

on inventory click: # Example of code that you'd use for a teleportation GUI
   if name of player's inventory is "Teleport":
      if index of clicked-slot is 3:
         if {room1} isn't set:
            tp(player, "%{_room1}%")
         else:
             tp(player, "fail")
            


on rightclick on black concrete: # Keep in mind this is just an idea of how to get started & you'd need to add more code to get this to function properly!
   # I would change your previous line of code to a GUI to better configure handing teleports
   stop
 
Thank you for the respond. I will try changing it to a gui
By the way, I completely forgot to mention but for the function I provided as a part of the solution, you'll want to add another variable to it to change the variable provided as {room1}, so the same room wouldn't have the same variable (To prevent issues with not being able to teleport to any room after 1 player teleports to one you don't tp to).

The updated function would look like the following:

Code:
function tp(p: player, loc: text, room: text): # Example of function you can use to handle if a room is/isn't occupied
   close {_p}'s inventory
   teleport {_p} to {_loc}
   send "&dTeleporting.." to {_p}
   set {%{_room}%} to "true"
   if loc is "fail":
      send "&cError&4! &cThis room is occupied&4!!" to {_p}