Execute a command if 2 players are in a worldguard region

  • 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 comminuty!

    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!

Radoco

New Member
Jun 14, 2024
9
0
1
24
I am trying to make a skript

if 2 players are in the worldguard region "test1"
trigger:
send "succes" to all players



does anyone know how to detect if 2 players are in a worldguard region and I SAID 2 not 1
 
I am trying to make a skript

if 2 players are in the worldguard region "test1"
trigger:
send "succes" to all players



does anyone know how to detect if 2 players are in a worldguard region and I SAID 2 not 1
The code you attempted to write for that functionality has major issues. I'll address them and give you links to the Docs which would help tremendously. It would also help to learn more basic Skript functionalities before attempting something more complicated. Firstly, you cannot check right off the bat if two player's are in a specific reason, yes that would be convenient you could but there isn't an expression like that that exists. The second issue you have is that you're attempting to use 'trigger' on your second line. Trigger is only used for commands and since your code doesn't utilize custom commands, it's kinda pointless in your code.

To fix your code (I'm not going to give you exact code to solve your issue, just explanations, examples or links of what you need to fix it):
* First, check if a player enters your region (Link)
* Add 1 to total players in that region as a variable (Example)
* Check, in that same statement, when the player enters the region, if the value of the variable is two or more (Example) [The reason why we don't check if it's just equal to two is because if at least two players enter the region at the same time while one is already in it, that number goes instantly to threeand will not work how you want]
* After that, you'll want to add a different statement that checks if a player leaves the region (Link)
* In the same block of code for the above, remove 1 from the variable you defined on Example #1 to account for if a player leaves the region

After testing your new and improved code you should now have the ability to check if a player enters or leave a specific region, if that region has a specific number of players and to run an action if it does. Let me know if you have any issues or problems when trying to create the code yourself and I'll be more than happy to help out if needed!
 
Code:
set {_region1} to regions at player
set {_region2} to regions at player
if {_region1} contains {_region2}:
    send "true"

it has one problem with what you said. Which players? What does it depend on? So you need to separate your players in the code
 
The code you attempted to write for that functionality has major issues. I'll address them and give you links to the Docs which would help tremendously. It would also help to learn more basic Skript functionalities before attempting something more complicated. Firstly, you cannot check right off the bat if two player's are in a specific reason, yes that would be convenient you could but there isn't an expression like that that exists. The second issue you have is that you're attempting to use 'trigger' on your second line. Trigger is only used for commands and since your code doesn't utilize custom commands, it's kinda pointless in your code.

To fix your code (I'm not going to give you exact code to solve your issue, just explanations, examples or links of what you need to fix it):
* First, check if a player enters your region (Link)
* Add 1 to total players in that region as a variable (Example)
* Check, in that same statement, when the player enters the region, if the value of the variable is two or more (Example) [The reason why we don't check if it's just equal to two is because if at least two players enter the region at the same time while one is already in it, that number goes instantly to threeand will not work how you want]
* After that, you'll want to add a different statement that checks if a player leaves the region (Link)
* In the same block of code for the above, remove 1 from the variable you defined on Example #1 to account for if a player leaves the region

After testing your new and improved code you should now have the ability to check if a player enters or leave a specific region, if that region has a specific number of players and to run an action if it does. Let me know if you have any issues or problems when trying to create the code yourself and I'll be more than happy to help out if needed!
I made this and when the code is triggered a few times and only 1 player enters the region it still fills the area with glass

on region enter:
if region is "test1":
add player to {test1::*}
if size of {test1::*} >= 2:
execute console command "fill -1340 176 -209 -1340 183 -217 glass"

on region exit:
if region is "test1":
remove player from {test1::*}
if size of {test1::*} >= 1:
execute console command "fill -1340 176 -209 -1340 183 -217 air"


on death:
if victim is in region "test1":
remove player from {test1::*}
if size of {test1::*} >= 1:
wait 5 seconds
execute console command "fill -1412 176 -217 -1412 183 -209 air"

on quit:
if player is in region "test1":
remove player from {test1::*}
if size of {test1::*} >= 1:
execute console command "fill -1412 176 -217 -1412 183 -209 air"
 
I made this and when the code is triggered a few times and only 1 player enters the region it still fills the area with glass

on region enter:
if region is "test1":
add player to {test1::*}
if size of {test1::*} >= 2:
execute console command "fill -1340 176 -209 -1340 183 -217 glass"

on region exit:
if region is "test1":
remove player from {test1::*}
if size of {test1::*} >= 1:
execute console command "fill -1340 176 -209 -1340 183 -217 air"


on death:
if victim is in region "test1":
remove player from {test1::*}
if size of {test1::*} >= 1:
wait 5 seconds
execute console command "fill -1412 176 -217 -1412 183 -209 air"

on quit:
if player is in region "test1":
remove player from {test1::*}
if size of {test1::*} >= 1:
execute console command "fill -1412 176 -217 -1412 183 -209 air"
Java:
options:
    region: "test1"

on region enter:
    if region is {@region} parsed as region:
        manage(region)

on region exit:
    if region is {@region} parsed as region:
        manage(region)

on death:
    if region is {@region} parsed as region:
        manage(region)

on quit:
    if region is {@region} parsed as region:
        manage(region)

function manage(region : object):
    set {_amount} to size of region({_region})
    if {_amount} >= 2:
        execute console command "fill -1340 176 -209 -1340 183 -217 glass"
    if {_amount} < 2:
        execute console command "fill -1340 176 -209 -1340 183 -217 air"

function region(region : object) :: players:
    loop all players:
        if loop-player is in {_region}:
            add loop-player to {_result::*}
    return {_result::*}

let's try
 
Java:
options:
    region: "test1"

on region enter:
    if region is {@region} parsed as region:
        manage(region)

on region exit:
    if region is {@region} parsed as region:
        manage(region)

on death:
    if region is {@region} parsed as region:
        manage(region)

on quit:
    if region is {@region} parsed as region:
        manage(region)

function manage(region : object):
    set {_amount} to size of region({_region})
    if {_amount} >= 2:
        execute console command "fill -1340 176 -209 -1340 183 -217 glass"
    if {_amount} < 2:
        execute console command "fill -1340 176 -209 -1340 183 -217 air"

function region(region : object) :: players:
    loop all players:
        if loop-player is in {_region}:
            add loop-player to {_result::*}
    return {_result::*}

let's try
tried it doesnt work