Solved How to search for players, as well as mobs?

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

Status
Not open for further replies.

Funtime

Active Member
Apr 24, 2017
54
0
0
22
command /safe:
trigger:
loop players in radius 10 of player:
add 1 to {_n}
loop monsters in radius 10 of player:
add 1 to {_n}
if {_n} is more than or equal to 1:
send "&cThis is not a safe area!"
else:
send "&aThis is a safe area!"

Searching for players works but when I copied and pasted it and replaced players to monsters, it states that 'player' is not an item stack (safe.sk, line 5: loop monster in radius 10 of player:'. How do I fix this?
 
You can create a variable to store the list of mobs you want to check.

example:

code_language.skript:
command /setupvariable <text>:
  trigger:
    if arg 1 is set:
      add arg 1 to {monsterlist::*}
      stop
    broadcast "%{monsterlist::*}%"

command /safe:
  trigger:
    loop players in radius 10 of player:
      add 1 to {_n}
    loop entities in radius 10 of player:
      loop {monsterlist::*}:
        if loop-entity = loop-value-2:
          add 1 to {_n}
    if {_n} is more than or equal to 1:
      send "&cThis is not a safe area!"
    else:
      send "&aThis is a safe area!"
 
You can create a variable to store the list of mobs you want to check.

example:

code_language.skript:
command /setupvariable <text>:
  trigger:
    if arg 1 is set:
      add arg 1 to {monsterlist::*}
      stop
    broadcast "%{monsterlist::*}%"

command /safe:
  trigger:
    loop players in radius 10 of player:
      add 1 to {_n}
    loop entities in radius 10 of player:
      loop {monsterlist::*}:
        if loop-entity = loop-value-2:
          add 1 to {_n}
    if {_n} is more than or equal to 1:
      send "&cThis is not a safe area!"
    else:
      send "&aThis is a safe area!"
Although this is a good way around the problem, It won't work if you're including it inside a Skript. The Skript I hope to make is when a player does "/spawn" and there're players/mobs nearby, there will be a countdown to go to spawn.
 
Edit it?

You need to use the first command just to setup the variable, after that you never touch it again, you can even delete the command.
 
Edit it?

You need to use the first command just to setup the variable, after that you never touch it again, you can even delete the command.
I understand what you mean, but I'm planning on making this a public Skript, which having to set the mobs is not going to be popular.
 
I understand what you mean, but I'm planning on making this a public Skript, which having to set the mobs is not going to be popular.
My god, YOU set the mob list ONE time that will be used for ALL players commands. You set the variable {monsterlist::*} and later later you use the variable "{monsterlist::*}".

Can't you understand that?

WIth the first command you set the variable, this variable will hold the mob types that should be checked. Then, you run the check for your tp plugin, or any other plugin you want to make.

Variables are global (instead of the variables starting with _ "underline"). You set them and use them as you want.

Just do this loop inside your tp plugin check:
code_language.skript:
    loop players in radius 10 of player:
      add 1 to {_n}
    loop entities in radius 10 of player:
      loop {monsterlist::*}:
        if loop-entity = loop-value-2:
          add 1 to {_n}

But you need to first set the monsters you want to detect with the command I gave you:

code_language.skript:
command /setupvariable <text>:
  trigger:
    if arg 1 is set:
      add arg 1 to {monsterlist::*}
      stop
    broadcast "%{monsterlist::*}%"
 
Last edited by a moderator:
Status
Not open for further replies.