Capturing Within 7 Block Radius

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

Lanky

New Member
Mar 24, 2018
5
0
0
24
Hello!

I am currently creating a game in which players right click a sponge in order to start "capturing" a "town". When they right click a sponge, how can I check for a player in a radius of 7 around the block every 0.5 seconds? If the player leaves the seven block radius, the capture stops.

I assume I need to use "loop-blocks in radius 7" but I am not sure exactly how to apply it to this situation. Here is what I have so far, although it probably won't be very helpful:

Code:
on click on sponge:
    if block under is white concrete:   
        if {joined.%player%} is true:
            if {segestica_owner} is set:
                if {segestica_process} is false:
                    if {segestica_cooldown} is false:
                        if {team.%player%} is "Santiago":
                            if {segestica_owner} is "Santiago":
                                send "{@Prefix} Your nation already owns Segestica!" to player
                            else:   
                                broadcast "{@Prefix} &eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&a3 minutes&7)&a."
                                wait 1 minute
                                broadcast "{@Prefix} &eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&e2 minutes&7)&a."
                                wait 1 minute
                                broadcast "{@Prefix} &eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&1 minute&7)&a."
                                wait 30 seconds
                                broadcast "{@Prefix} &eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&430 seconds&7)&a."
                                wait 15 seconds
                                broadcast "{@Prefix} &eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&415 seconds&7)&a."
                                wait 15 seconds
                                broadcast "{@Prefix} &eSantiago &ahas captured &eSegestica &afrom <%{segestica_color}%>%{segestica_owner}%&a."
                                wait 1 tick
                                set {segestica_color} to yellow
                                set {segestica_owner} to "Santiago"

Don't worry about the variables, I have those covered :emoji_slight_smile: Thanks for any help!
 
This should work.
Code:
on right click:
    if clicked block is sponge:
        if block under the clicked block is white concrete: 
            if {joined.%player%} is true:
                if {segestica_owner} is set:
                    if {segestica_process} is false:
                        if {segestica_cooldown} is false:
                            if {team.%player%} is "Santiago":
                                if {segestica_owner} is "Santiago":
                                    send "{@Prefix} Your nation already owns Segestica!" to player
                                else: 
                                    set {segestica_location} to location of event-block
                                    set {segestica_capturing_player} to event-player
                                    set {segestica_capturing_player_team} to "Santiago"                               
                                    broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&a3 minutes&7)&a."
                                    wait 1 minute
                                    if {segestica_capturing_player} is set:
                                        broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&e2 minutes&7)&a."
                                    wait 1 minute
                                    if {segestica_capturing_player} is set:
                                        broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&1 minute&7)&a."
                                    wait 30 seconds
                                    if {segestica_capturing_player} is set:
                                        broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&430 seconds&7)&a."
                                    wait 15 seconds
                                    if {segestica_capturing_player} is set:
                                        broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&415 seconds&7)&a."
                                    wait 15 seconds
                                    if {segestica_capturing_player} is set:
                                        broadcast "&eSantiago &ahas captured &eSegestica &afrom <%{segestica_color}%>%{segestica_owner}%&a."
                                        wait 1 tick
                                        set {segestica_color} to yellow
                                        set {segestica_owner} to "Santiago"
                                        delete {segestica_capturing_player_team}
                                        delete {segestica_location}
                                        delete {segestica_capturing_player}
every 1 tick:
    if {segestica_capturing_player} is set:
        if distance between {segestica_location} and {segestica_capturing_player} is smaller than 7:
            stop
        else:
            delete {segestica_capturing_player}
            if {segestica_capturing_player_team} is "Santiago":
                broadcast "&6Santiago is not capturing Segestica anymore."
(I don't formatted in the right way the prefix of the capturing process, but don't worry, it's only a message)
 
Last edited:
This should work.
Code:
on right click:
    if clicked block is sponge:
        if block under the clicked block is white concrete:
            if {joined.%player%} is true:
                if {segestica_owner} is set:
                    if {segestica_process} is false:
                        if {segestica_cooldown} is false:
                            if {team.%player%} is "Santiago":
                                if {segestica_owner} is "Santiago":
                                    send "{@Prefix} Your nation already owns Segestica!" to player
                                else:
                                    set {segestica_location} to location of event-block
                                    set {segestica_capturing_player} to event-player
                                    set {segestica_capturing_player_team} to "Santiago"                             
                                    broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&a3 minutes&7)&a."
                                    wait 1 minute
                                    if {segestica_capturing_player} is set:
                                        broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&e2 minutes&7)&a."
                                    wait 1 minute
                                    if {segestica_capturing_player} is set:
                                        broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&1 minute&7)&a."
                                    wait 30 seconds
                                    if {segestica_capturing_player} is set:
                                        broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&430 seconds&7)&a."
                                    wait 15 seconds
                                    if {segestica_capturing_player} is set:
                                        broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&415 seconds&7)&a."
                                    wait 15 seconds
                                    if {segestica_capturing_player} is set:
                                        broadcast "&eSantiago &ahas captured &eSegestica &afrom <%{segestica_color}%>%{segestica_owner}%&a."
                                        wait 1 tick
                                        set {segestica_color} to yellow
                                        set {segestica_owner} to "Santiago"
                                        delete {segestica_capturing_player_team}
                                        delete {segestica_location}
                                        delete {segestica_capturing_player}
every 1 tick:
    if {segestica_capturing_player} is set:
        if distance between {segestica_location} and {segestica_capturing_player} is smaller than 7:
            stop
        else:
            delete {segestica_capturing_player}
            if {segestica_capturing_player_team} is "Santiago":
                broadcast "&6Santiago is not capturing Segestica anymore."
(I don't formatted in the right way the prefix of the capturing process, but don't worry, it's only a message)

It works fine, but what if I wanted to make it so that any player on the team of the person who clicked the sponge can be in the 7 block radius and still capture the town, even if the player who originally clicked it has left the radius? What I'm getting at is, if the player on Santiago dies for example, if another member on their team is within the 7 block limit I want the capturing to continue until no one from Santiago is within 7 blocks or the town is captured.
 
Last edited:
I don't tested this, but I think that it works.
Code:
on right click:
    if clicked block is sponge:
        if block under the clicked block is white concrete: 
            if {joined.%player%} is true:
                if {segestica_owner} is set:
                    if {segestica_process} is false:
                        if {segestica_cooldown} is false:
                            if {team.%player%} is "Santiago":
                                if {segestica_owner} is "Santiago":
                                    send "{@Prefix} Your nation already owns Segestica!" to player
                                else:
                                    set {segestica_location} to location of event-block
                                    set {segestica_capturing_player_team} to {team.%player%}                               
                                    broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&a3 minutes&7)&a."
                                    wait 1 minute
                                    if {segestica_capturing_player_team} is set:
                                        broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&e2 minutes&7)&a."
                                    wait 1 minute
                                    if {segestica_capturing_player_team} is set:
                                        broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&1 minute&7)&a."
                                    wait 30 seconds
                                    if {segestica_capturing_player_team} is set:
                                        broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&430 seconds&7)&a."
                                    wait 15 seconds
                                    if {segestica_capturing_player_team} is set:
                                        broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&415 seconds&7)&a."
                                    wait 15 seconds
                                    if {segestica_capturing_player_team} is set:
                                        broadcast "&eSantiago &ahas captured &eSegestica &afrom <%{segestica_color}%>%{segestica_owner}%&a."
                                        wait 1 tick
                                        set {segestica_color} to yellow
                                        set {segestica_owner} to "Santiago"
                                        delete {segestica_capturing_player_team}
                                        delete {segestica_location}
                                        delete {segestica_capturing_player}
every 1 tick:
    if {segestica_capturing_player_team} is set:
        loop all players in radius 7 of {segestica_location}:
            if {team.%loop-player%} = {segestica_capturing_player_team}:
                add 1 to {_playersofthesameteam}
                if {_playersofthesameteam} > 1:
                    stop
                else:
                    delete {segestica_capturing_player_team}
                    broadcast "&6%{segestica_capturing_player_team}% is not capturing Segestica anymore."
                wait a tick
                delete {_playersofthesameteam}

Btw, if you need to make a "count" of players in a location, use lists and not singular variables.
 
I don't tested this, but I think that it works.
Code:
on right click:
    if clicked block is sponge:
        if block under the clicked block is white concrete:
            if {joined.%player%} is true:
                if {segestica_owner} is set:
                    if {segestica_process} is false:
                        if {segestica_cooldown} is false:
                            if {team.%player%} is "Santiago":
                                if {segestica_owner} is "Santiago":
                                    send "{@Prefix} Your nation already owns Segestica!" to player
                                else:
                                    set {segestica_location} to location of event-block
                                    set {segestica_capturing_player_team} to {team.%player%}                           
                                    broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&a3 minutes&7)&a."
                                    wait 1 minute
                                    if {segestica_capturing_player_team} is set:
                                        broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&e2 minutes&7)&a."
                                    wait 1 minute
                                    if {segestica_capturing_player_team} is set:
                                        broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&1 minute&7)&a."
                                    wait 30 seconds
                                    if {segestica_capturing_player_team} is set:
                                        broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&430 seconds&7)&a."
                                    wait 15 seconds
                                    if {segestica_capturing_player_team} is set:
                                        broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&415 seconds&7)&a."
                                    wait 15 seconds
                                    if {segestica_capturing_player_team} is set:
                                        broadcast "&eSantiago &ahas captured &eSegestica &afrom <%{segestica_color}%>%{segestica_owner}%&a."
                                        wait 1 tick
                                        set {segestica_color} to yellow
                                        set {segestica_owner} to "Santiago"
                                        delete {segestica_capturing_player_team}
                                        delete {segestica_location}
                                        delete {segestica_capturing_player}
every 1 tick:
    if {segestica_capturing_player_team} is set:
        loop all players in radius 7 of {segestica_location}:
            if {team.%loop-player%} = {segestica_capturing_player_team}:
                add 1 to {_playersofthesameteam}
                if {_playersofthesameteam} > 1:
                    stop
                else:
                    delete {segestica_capturing_player_team}
                    broadcast "&6%{segestica_capturing_player_team}% is not capturing Segestica anymore."
                wait a tick
                delete {_playersofthesameteam}

Btw, if you need to make a "count" of players in a location, use lists and not singular variables.

There's an error in the following. It's not an error that shows up in console, but rather an error in how it works:

Code:
every 1 tick:
    if {segestica_capturing_player_team} is set:
        loop all players in radius 7 of {segestica_location}:
            if {team.%loop-player%} = {segestica_capturing_player_team}:
                add 1 to {_playersofthesameteam}
                if {_playersofthesameteam} >= 1:
                    stop

There is nothing that removes 1 from {_playersofthesameteam} when a player leaves the 7 block radius. However, I'm still not sure how I can fix this problem.
 

Attachments

  • 2019-03-24_11.44.27.jpg
    2019-03-24_11.44.27.jpg
    25.6 KB · Views: 200
Last edited:
Status
Not open for further replies.