1. 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!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Capturing Within 7 Block Radius

Discussion in 'Skript' started by Lanky, Mar 24, 2019.

Tags:
Thread Status:
Not open for further replies.
  1. Lanky

    Lanky Member

    Joined:
    Mar 24, 2018
    Messages:
    5
    Likes Received:
    0
    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 (Text):
    1. on click on sponge:
    2.     if block under is white concrete:  
    3.         if {joined.%player%} is true:
    4.             if {segestica_owner} is set:
    5.                 if {segestica_process} is false:
    6.                     if {segestica_cooldown} is false:
    7.                         if {team.%player%} is "Santiago":
    8.                             if {segestica_owner} is "Santiago":
    9.                                 send "{@Prefix} Your nation already owns Segestica!" to player
    10.                             else:  
    11.                                 broadcast "{@Prefix} &eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&a3 minutes&7)&a."
    12.                                 wait 1 minute
    13.                                 broadcast "{@Prefix} &eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&e2 minutes&7)&a."
    14.                                 wait 1 minute
    15.                                 broadcast "{@Prefix} &eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&1 minute&7)&a."
    16.                                 wait 30 seconds
    17.                                 broadcast "{@Prefix} &eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&430 seconds&7)&a."
    18.                                 wait 15 seconds
    19.                                 broadcast "{@Prefix} &eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&415 seconds&7)&a."
    20.                                 wait 15 seconds
    21.                                 broadcast "{@Prefix} &eSantiago &ahas captured &eSegestica &afrom <%{segestica_color}%>%{segestica_owner}%&a."
    22.                                 wait 1 tick
    23.                                 set {segestica_color} to yellow
    24.                                 set {segestica_owner} to "Santiago"
    Don't worry about the variables, I have those covered :emoji_slight_smile: Thanks for any help!
     
  2. Ouma Shu

    Ouma Shu Well-Known Member

    Joined:
    Dec 25, 2017
    Messages:
    45
    Likes Received:
    2
    This should work.
    Code (Text):
    1. on right click:
    2.     if clicked block is sponge:
    3.         if block under the clicked block is white concrete:
    4.             if {joined.%player%} is true:
    5.                 if {segestica_owner} is set:
    6.                     if {segestica_process} is false:
    7.                         if {segestica_cooldown} is false:
    8.                             if {team.%player%} is "Santiago":
    9.                                 if {segestica_owner} is "Santiago":
    10.                                     send "{@Prefix} Your nation already owns Segestica!" to player
    11.                                 else:
    12.                                     set {segestica_location} to location of event-block
    13.                                     set {segestica_capturing_player} to event-player
    14.                                     set {segestica_capturing_player_team} to "Santiago"                              
    15.                                     broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&a3 minutes&7)&a."
    16.                                     wait 1 minute
    17.                                     if {segestica_capturing_player} is set:
    18.                                         broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&e2 minutes&7)&a."
    19.                                     wait 1 minute
    20.                                     if {segestica_capturing_player} is set:
    21.                                         broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&1 minute&7)&a."
    22.                                     wait 30 seconds
    23.                                     if {segestica_capturing_player} is set:
    24.                                         broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&430 seconds&7)&a."
    25.                                     wait 15 seconds
    26.                                     if {segestica_capturing_player} is set:
    27.                                         broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&415 seconds&7)&a."
    28.                                     wait 15 seconds
    29.                                     if {segestica_capturing_player} is set:
    30.                                         broadcast "&eSantiago &ahas captured &eSegestica &afrom <%{segestica_color}%>%{segestica_owner}%&a."
    31.                                         wait 1 tick
    32.                                         set {segestica_color} to yellow
    33.                                         set {segestica_owner} to "Santiago"
    34.                                         delete {segestica_capturing_player_team}
    35.                                         delete {segestica_location}
    36.                                         delete {segestica_capturing_player}
    37. every 1 tick:
    38.     if {segestica_capturing_player} is set:
    39.         if distance between {segestica_location} and {segestica_capturing_player} is smaller than 7:
    40.             stop
    41.         else:
    42.             delete {segestica_capturing_player}
    43.             if {segestica_capturing_player_team} is "Santiago":
    44.                 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)
     
    #2 Ouma Shu, Mar 24, 2019
    Last edited: Mar 24, 2019
  3. Lanky

    Lanky Member

    Joined:
    Mar 24, 2018
    Messages:
    5
    Likes Received:
    0
    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.
     
    #3 Lanky, Mar 24, 2019
    Last edited: Mar 24, 2019
  4. Ouma Shu

    Ouma Shu Well-Known Member

    Joined:
    Dec 25, 2017
    Messages:
    45
    Likes Received:
    2
    I don't tested this, but I think that it works.
    Code (Text):
    1. on right click:
    2.     if clicked block is sponge:
    3.         if block under the clicked block is white concrete:
    4.             if {joined.%player%} is true:
    5.                 if {segestica_owner} is set:
    6.                     if {segestica_process} is false:
    7.                         if {segestica_cooldown} is false:
    8.                             if {team.%player%} is "Santiago":
    9.                                 if {segestica_owner} is "Santiago":
    10.                                     send "{@Prefix} Your nation already owns Segestica!" to player
    11.                                 else:
    12.                                     set {segestica_location} to location of event-block
    13.                                     set {segestica_capturing_player_team} to {team.%player%}                              
    14.                                     broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&a3 minutes&7)&a."
    15.                                     wait 1 minute
    16.                                     if {segestica_capturing_player_team} is set:
    17.                                         broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&e2 minutes&7)&a."
    18.                                     wait 1 minute
    19.                                     if {segestica_capturing_player_team} is set:
    20.                                         broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&1 minute&7)&a."
    21.                                     wait 30 seconds
    22.                                     if {segestica_capturing_player_team} is set:
    23.                                         broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&430 seconds&7)&a."
    24.                                     wait 15 seconds
    25.                                     if {segestica_capturing_player_team} is set:
    26.                                         broadcast "&eSantiago &ais capturing <%{segestica_color}%>Segestica &afrom <%{segestica_color}%>%{segestica_owner}% &7(&415 seconds&7)&a."
    27.                                     wait 15 seconds
    28.                                     if {segestica_capturing_player_team} is set:
    29.                                         broadcast "&eSantiago &ahas captured &eSegestica &afrom <%{segestica_color}%>%{segestica_owner}%&a."
    30.                                         wait 1 tick
    31.                                         set {segestica_color} to yellow
    32.                                         set {segestica_owner} to "Santiago"
    33.                                         delete {segestica_capturing_player_team}
    34.                                         delete {segestica_location}
    35.                                         delete {segestica_capturing_player}
    36. every 1 tick:
    37.     if {segestica_capturing_player_team} is set:
    38.         loop all players in radius 7 of {segestica_location}:
    39.             if {team.%loop-player%} = {segestica_capturing_player_team}:
    40.                 add 1 to {_playersofthesameteam}
    41.                 if {_playersofthesameteam} > 1:
    42.                     stop
    43.                 else:
    44.                     delete {segestica_capturing_player_team}
    45.                     broadcast "&6%{segestica_capturing_player_team}% is not capturing Segestica anymore."
    46.                 wait a tick
    47.                 delete {_playersofthesameteam}
    Btw, if you need to make a "count" of players in a location, use lists and not singular variables.
     
  5. Lanky

    Lanky Member

    Joined:
    Mar 24, 2018
    Messages:
    5
    Likes Received:
    0
    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 (Text):
    1. every 1 tick:
    2.     if {segestica_capturing_player_team} is set:
    3.         loop all players in radius 7 of {segestica_location}:
    4.             if {team.%loop-player%} = {segestica_capturing_player_team}:
    5.                 add 1 to {_playersofthesameteam}
    6.                 if {_playersofthesameteam} >= 1:
    7.                     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.
     

    Attached Files:

    #5 Lanky, Mar 24, 2019
    Last edited: Mar 24, 2019
  6. Ouma Shu

    Ouma Shu Well-Known Member

    Joined:
    Dec 25, 2017
    Messages:
    45
    Likes Received:
    2
    Uhm.. If it doesn't work, I don't know how to. Ask for help to @ShaneBee
     
  7. Lanky

    Lanky Member

    Joined:
    Mar 24, 2018
    Messages:
    5
    Likes Received:
    0
Thread Status:
Not open for further replies.
Loading...