Solved Sentry

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

Status
Not open for further replies.

PatoFrango

Active Member
Jul 12, 2017
240
14
18
Hi,
So I’m trying to code some kind of sentry that shoots one pig at a time in a radius of 5.
The thing is, I have multiple sentries set up and each one of them should work individually. The problem here is when one of them detects a pig, the other ones start shooting at it too, even if it’s not inside a radius of 5.
Keep in mind that every sentry is an amor stand as has the name “sentry” on it.
code_language.skript:
every 0.5 second in "world":
    loop all armor stands in "world":
        if name of loop-entity-1 is "sentry":
            loop all pigs in radius 5 of loop-entity-1:
                damage loop-entity-2 by 1 heart
                loop all players in "world":
                    console command "/jukebox sound %loop-player% sound.mp3"
                stop loop
EDIT: Also, forgot to say that if it’s just one pig that’s in one of the sentry’s radius the other ones won’t detect it, being this what was supposed to happen. If more than one pig steps on the sentrys radius, all of them start shooting at it.
 
Last edited:
Im am so confused as to what you are talking about "shooting at it"
There is nothing in your code regarding shooting
 
Im am so confused as to what you are talking about "shooting at it"
There is nothing in your code regarding shooting
It's supposed to be a sentry. Sentries shoot at targets, but here I decided to use the "damage" effect and not the "shoot an arrow" one.
Either way, this was indeed a Skript bug. I solved it. I had to separate 3/4 of the code and put it on a function for it to work. It's the exact same thing, except part of it is inside a function.
code_language.skript:
every 0.5 second in "world":
    loop all armor stands in "world":
        someFunc(loop-entity)
      
function someFunc(e: entity):
    if name of {_e} is "sentry":
        loop all entities in radius 5 of {_e}:
            loop-entity is pig
            damage loop-entity by 1.5 hearts
            loop all players in "world":
                console command "/jukebox sound %loop-player% sound.mp3"
            stop loop
 
  • Like
Reactions: Deleted member 5254
Status
Not open for further replies.