Paste #71723: Untitled Paste

Date: 2020/07/01 10:07:54 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


# +--------------------
# |
# | H i d e   a n d   S e e k
# |
# | A script for the Hide and Seek minigame!
# |
# +----------------------
#
# @author Spirion
# @date 2020/07/01
# @denizen-build REL-1712
#
# Installation:
# Just put the script in your scripts folder and reload.
#
# Usage:
# First of all you will need to configurate the stage for the game.
# When the players join the game, they will appear on the stage inside an area where
# they can't move far away. This area should have blocks surrounding it
# When they start the game, this area will be replaced to another one without blocks.
#
# It is needed a LOBBY POINT where players will appear in the world,
# also a WAIT AREA where players will stay when joining the game, and
# a WAIT POINT inside this area.
#
# Type '/has lobby' and '/has wait' to set the lobby point and the wait point in your position.
# Type '/has pos1' and '/has pos2' to set the corners of the area you are going to create.
# Then, type '/has create normal|blocked' to set the area of the stage with and withouth obstacles
#
# ---------------------------- END HEADER ----------------------------
hideAndSeekCommand:
    type: command
    name: hideAndSeek
    usage: /hideAndSeek [join|leave|start]
    description: Play hide and seek.
    script:
        # We check por players permissions. Change 'permission.node' to a real permission
        # If everyone will be able to use this command, just comment the lines.
        - if !<player.has_permission[permission.node]>:
            - narrate "<&c>You don't have permission to use this command.."
            - stop
        # We check what have written the player
        - define size <context.args.size>
        - choose <[size]>:
            - case 1:
                - define arg1 <context.args.get[1]>
                - choose <[arg1]>:
                    - case join:
                        # We check that there isn't a game already going on
                        - if <server.has_flag[hideAndSeek_Running]>:
                            - narrate "<&c>There's already a game going on. It ends in <server.flag[hideAndSeek_Running].expiration.formatted>."
                            - stop
                        # The player joins the game
                        - teleport <player> <server.flag[hideAndSeek_loc]>
                        - flag player hideAndSeek
                        - flag server hideAndSeek:->:<player>
                        - narrate "<&e>You have joined the game. When you're all ready, write <&a>/hideAndSeek start<&e>. No one else will be able to join."
                        # We load the schematic to open the game
                        - if <server.flag[hideAndSeek].size> < 2:
                            - ~schematic load name:hideAndSeek_schemAir
                    - case leave:
                        - if !<server.has_flag[hideAndSeek_Running]>:
                            - narrate "<&e>You have left the game."
                            - teleport <player> <server.flag[hideAndSeek_lobbyLoc]>
                            - schematic unload name:hideAndSeek_schemAir
                            - sidebar remove
                            - stop
                        # The player leaves the game
                        - narrate "<&e>You have left the game."
                        - inject hideAndSeek_Leave
                        - teleport <player> <server.flag[hideAndSeek_lobbyLoc]>
                        - if <server.has_flag[hideAndSeek_Running]>:
                            # We check how is going on the game
                            - if <server.flag[hideAndSeek_Seeker].size> >= <server.flag[hideAndSeek].size>:
                                - narrate "<&e>There aren't Hiddens in the game. Seekers win!" targets:<server.flag[hideAndSeek]>
                                - inject hideAndSeek_GlobalEnd
                            # Check if there are Hiddens
                            - else if !<server.has_flag[hideAndSeek_Seeker]>:
                                - narrate "<&e>There aren't Seekers in the game. Hiddens win!" targets:<server.flag[hideAndSeek]>
                                - inject hideAndSeek_GlobalEnd
                    - case start:
                        - if <server.has_flag[hideAndSeek_Running]>:
                            - narrate "<&c>The game has already started."
                            - stop
                        - if <server.flag[hideAndSeek].size> < 2:
                            - narrate "<&c>You can't start the game with just one player."
                            - stop
                        - flag server hideAndSeek_Counter:++
                        # The game starts
                        - narrate "<&a><player.name> <&e>starts the game. There are <server.flag[hideAndSeek].size> players." targets:<server.flag[hideAndSeek]>
                        # It's choosen randomly a Seeker
                        - define seeker <server.flag[hideAndSeek].random>
                        # Before he can start looking for Hiddens, we apply on him some parameters with delay
                        - run hideAndSeek_EffectSeeker def:<[seeker]>
                        # We establish a 30 seconds timer
                        - run hideAndSeek_TimerSeeker def:<[seeker]>
                        # This parameters are for the Hiddens
                        - foreach <server.flag[hideAndSeek].exclude[<[seeker]>]>:
                            - team name:hideAndSeek add:<[value].name>
                            - team name:hideAndSeek option:name_tag_visibility status:never
                            - adjust <[value]> food_level:20
                        - narrate "<&e>You are a <&a>Hidden<&e>! You have 30 seconds to hide." targets:<server.flag[hideAndSeek].exclude[<[seeker]>]>
                        # Timer
                        - define counter <server.flag[hideAndSeek_Counter]>
                        - run hideAndSeek_TimerGlobal def:<[counter]>
                        - flag server hideAndSeek_Running duration:10m
                        # Scoreboard for the players
                        - run hideAndSeek_Scoreboard
                        # We paste the schematic opening the scene
                        - ~schematic paste name:hideAndSeek_schemAir <server.flag[hideAndSeek_loc]>
                        - schematic unload name:hideAndSeek_schemAir
                        - ~schematic load name:hideAndSeek_schemBlock
                    - default:
                        - narrate "<&c>Unknown command. Try:"
                        - narrate "<&c>/hideAndSeek [join|leave|start]"
                        - stop
            - default:
                - narrate <empty>
                - narrate "<&e>----- Hide and Seek commands -----"
                - narrate "<&6>/hideAndSeek join<&r> - Join the game if is not already started."
                - narrate "<&6>/hideAndSeek leave<&r> - Quit the game."
                - narrate "<&6>/hideAndSeek start<&r> - Start the game with the available players."
                - stop

hideAndSeekConfig:
    type: command
    name: has
    usage: /has [pos1|pos2|create|lobby|wait] [normal|blocked]
    description: To configurate the scene for the game.
    script:
        # Only admins should have permission to run this commands
        - if !<player.has_permission[permission.node]>:
            - narrate "<&c>You don't have permission to use this command."
            - stop
        # We check what have written the player
        - define size <context.args.size>
        - choose <[size]>:
            - case 1:
                - define arg1 <context.args.get[1]>
                - choose <[arg1]>:
                    # Corner 1
                    - case pos1:
                        - narrate "<&e>Corner 1 selected in your position."
                        - flag player hideAndSeek_pos1:<player.location>
                    # Corner 2
                    - case pos2:
                        - narrate "<&e>Corner 2 selected in your position."
                        - flag player hideAndSeek_pos2:<player.location>
                    # Set the lobby location
                    - case lobby:
                        - narrate "<&e>You've set the spawn point on the lobby on your position."
                        - flag server hideAndSeek_lobbyLoc:<player.location>
                    # Set the waiting point on the stage
                    - case wait:
                        - narrate "<&e>You've set the waiting point on the stage at your position."
                        - flag server hideAndSeek_loc:<player.location>
                    - default:
                        - narrate "<&c>Unknown command. Try:"
                        - narrate "<&c>/has [pos1|pos2|create|lobby|wait] [normal|blocked]"
                        - stop
            - case 2:
                - define arg1 <context.args.get[1]>
                - choose <[arg1]>:
                    # Creation
                    - case create:
                        - define arg2 <context.args.get[2]>
                        - choose <[arg2]>:
                            # Schematica without blocks on the way
                            - case normal:
                                - if !<player.has_flag[hideAndSeek_pos1]> && !<player.has_flag[hideAndSeek_pos2]> && !<server.has_flag[hideAndSeek_loc]>:
                                    - narrate "<&c>You have to set the corners and a wait point on the stage first."
                                    - stop
                                - schematic unload name:hideAndSeek_schemAir
                                - narrate "<&e>You've set the stage <&a>without obstacles<&e> and your corner selections have been removed."
                                - schematic create name:hideAndSeek_schemAir <cuboid[<player.flag[hideAndSeek_pos1]>|<player.flag[hideAndSeek_pos2]>]> <server.flag[hideAndSeek_loc]>
                                - ~schematic save name:hideAndSeek_schemAir
                                - schematic unload name:hideAndSeek_schemAir
                                - flag player hideAndSeek_pos1:!
                                - flag player hideAndSeek_pos2:!
                            # Schematica with blocks on the way
                            - case blocked:
                                - if !<player.has_flag[hideAndSeek_pos1]> && !<player.has_flag[hideAndSeek_pos2]> && !<server.has_flag[hideAndSeek_loc]>:
                                    - narrate "<&c>You have to set the corners and a wait point on the stage first."
                                    - stop
                                - schematic unload name:hideAndSeek_schemBlock
                                - narrate "<&e>You've set the stage <&a>with obstacles<&e> and your corner selections have been removed."
                                - schematic create name:hideAndSeek_schemBlock <cuboid[<player.flag[hideAndSeek_pos1]>|<player.flag[hideAndSeek_pos2]>]> <server.flag[hideAndSeek_loc]>
                                - ~schematic save name:hideAndSeek_schemBlock
                                - schematic unload name:hideAndSeek_schemBlock
                                - flag player hideAndSeek_pos1:!
                                - flag player hideAndSeek_pos2:!
                            - default:
                                - narrate "<&c>Unknown command. Try:"
                                - narrate "<&c>/has [pos1|pos2|create|lobby|wait] [normal|blocked]"
                                - stop
                    - default:
                        - narrate "<&c>Unknown command. Try:"
                        - narrate "<&c>/has [pos1|pos2|create|lobby|wait] [normal|blocked]"
                        - stop
            - default:
                - narrate <empty>
                - narrate "<&e>----- Configure the scen for <&a>Hide and Seek <&e>-----"
                - narrate "<&6>/has lobby<&r> - Set the spawn point on the lobby."
                - narrate "<&6>/has wait<&r> - Set the wait point on the stage."
                - narrate "<&6>/has pos1<&r> - Set corner 1."
                - narrate "<&6>/has pos2<&r> - Set corner 2."
                - narrate "<&6>/has create [normal|blocked]<&r> - Creates the region of the stage with or withouth obstacles on the wait point. It is needed both."
                - stop

hideAndSeekDelflag:
    type: command
    name: hasdelflag
    usage: /hasdelflag [player]
    description: Removes a player's flag.
    script:
        # This command it is not needed for playing the game. If an error occurs, you can reset players' params with this.
        # You sholdn't don't need this. If any problem, please report on Denizen Forum.
        # Only an admin should have acces to this command
        - if !<player.has_permission[permission.node]>:
            - narrate "<&c>You don't have permission to use this command."
            - stop
        # Check that the command is written properly
        - if <context.args.size> != 1:
            - narrate "<red>/hasdelflag [player]"
            - stop
        # Check that the name written is a player
        - define target:<server.match_player[<context.args.get[1]>]||null>
        - if <[target]> == null:
            - narrate "<red>Unknown user '<yellow><context.args.get[1]><red>'."
            - stop
        # If everything is right
        - flag <[target]> hideAndSeek:!
        - flag server hideAndSeek:<-:<[target].name>
        - if <[target].has_flag[hideAndSeek_Seeker]>:
            - flag <[target]> hideAndSeek_Seeker:!
            - flag server hideAndSeek_Seeker:<-:<[target].name>
        - team name:hideAndSeek remove:<[target].name>
        - adjust <[target]> walk_speed:0.2
        - if <[target].has_effect[blindness]>:
            - cast blindness remove <[target]>
        - if <[target].inventory.contains.scriptname[hideAndSeekItem]>:
            - take scriptname:hideAndSeekItem

hideAndSeekEvents:
    type: world
    events:
        # We keep them from getting hungry when they sprint
        on player changes food level flagged:hideAndSeek:
            - determine cancelled
        # This event records when a Hidden is hit by the Seeker's item
        on player damaged with:hideAndSeekItem:
            - if !<context.entity.has_flag[hideAndSeek_Seeker]>:
                - narrate "<&e>You've been caught by a Seeker!" targets:<context.entity>
                # It converts to Seeker
                - define seeker <context.entity>
                - teleport <[seeker]> <server.flag[hideAndSeek_loc]>
                - flag <[seeker]> hideAndSeek_Seeker
                - flag server hideAndSeek_Seeker:->:<[seeker]>
                - team name:hideAndSeek remove:<[seeker].name>
                - give hideAndSeekItem to:<[seeker].inventory> slot:1
                - wait 1t
                - narrate "<&e>A new Seeker appears. <&a><server.flag[hideAndSeek_Seeker].size><&f> seekers <&e>/ <&a><server.flag[hideAndSeek].size.sub[<server.flag[hideAndSeek_Seeker].size>]> <&f>hiddens." targets:<server.flag[hideAndSeek].exclude[<[seeker]>]>
                - narrate "<&e>Find the Hiddens and punch them with the fish!" targets:<[seeker]>
                # We check how is going on the game
                - if <server.flag[hideAndSeek_Seeker].size> >= <server.flag[hideAndSeek].size>:
                    - narrate "<&e>There aren't Hiddens in the game. Seekers win!" targets:<server.flag[hideAndSeek]>
                    - inject hideAndSeek_GlobalEnd
                # Check if there are any seekers left
                - else if !<server.has_flag[hideAndSeek_Seeker]>:
                    - narrate "<&e>There aren't Seekers in the game. Hiddens win!" targets:<server.flag[hideAndSeek]>
                    - inject hideAndSeek_GlobalEnd
        # Prevent throwing away the Seeker item
        on player drops hideAndSeekItem:
            - determine cancelled
        # Prevent eating the Seeker item
        on player consumes hideAndSeekItem:
            - determine cancelled
        # Prevent from moving the Seeker Item in the inventory
        on player clicks in inventory with:hideAndSeekItem flagged:hideAndSeek:
            - determine cancelled
        # If the player quits the server, we force on the to leave the game.
        on player quits flagged:hideAndSeek:
            - inject hideAndSeek_Leave
            # We check how is going on the game
            - if <server.flag[hideAndSeek_Seeker].size> >= <server.flag[hideAndSeek].size>:
                - narrate "<&e>There aren't Hiddens in the game. Seekers win!" targets:<server.flag[hideAndSeek]>
                - inject hideAndSeek_GlobalEnd
            # Check if there are any seekers left
            - else if !<server.has_flag[hideAndSeek_Seeker]>:
                - narrate "<&e>There aren't Seekers in the game. Hiddens win!" targets:<server.flag[hideAndSeek]>
                - inject hideAndSeek_GlobalEnd

hideAndSeekItem:
    type: item
    material: tropical_fish
    display name: <&6>The Salmonazo
    lore:
    - "<&9>The Hiddens you must seek"
    - "<&9>and with the salmonazo you must punch"
    - "<&9>Go get'em!"

hideAndSeek_TimerSeeker:
    type: task
    definitions: seeker
    script:
        - wait 30s
        # Check that the player has not left the server.
        - if <[seeker].has_flag[hideAndSeek]>:
            # We check how is going on the game
            - if <server.flag[hideAndSeek_Seeker].size> >= <server.flag[hideAndSeek].size>:
                - narrate "<&e>There aren't Hiddens in the game. Seekers win!" targets:<server.flag[hideAndSeek]>
                - inject hideAndSeek_GlobalEnd
            # We enable the search
            - else:
                - adjust <[seeker]> walk_speed:0.2
                - cast blindness remove <[seeker]>
                - give hideAndSeekItem to:<[seeker].inventory> slot:1
                - narrate "<&e>A new Seeker appears. <&a><server.flag[hideAndSeek_Seeker].size><&f> seekers <&e>/ <&a><server.flag[hideAndSeek].size.sub[<server.flag[hideAndSeek_Seeker].size>]> <&f>hiddens." targets:<server.flag[hideAndSeek].exclude[<[seeker]>]>
                - narrate "<&e>Find the Hiddens and punch them with the fish!" targets:<[seeker]>
        # Comprobamos si quedan buscadores en la partida
        - else if !<server.has_flag[hideAndSeek_Seeker]>:
            - narrate "<&e>There aren't Seekers in the game. Hiddens win!" targets:<server.flag[hideAndSeek]>
            - inject hideAndSeek_GlobalEnd

hideAndSeek_TimerGlobal:
    type: task
    definitions: counter
    script:
        - wait 10m
        # We check that the game isn't already finished
        - if <server.has_flag[hideAndSeek_Running]> && <[counter]> == <server.flag[hideAndSeek_Counter]>:
            - narrate "<&e>Time out, Hiddens wins!" targets:<server.flag[hideAndSeek]>
            - inject hideAndSeek_GlobalEnd

hideAndSeek_GlobalEnd:
    type: task
    script:
        # We reset all the flags and values from the players
        - flag server hideAndSeek_Running:!
        - foreach <server.online_players_flagged[hideAndSeek_Seeker]>:
            - flag <[value]> hideAndSeek_Seeker:!
        - flag server hideAndSeek_Seeker:!
        - foreach <server.flag[hideAndSeek]>:
            - team name:hideAndSeek remove:<[value].name>
            - adjust <[value]> walk_speed:0.2
            - if <[value].has_effect[blindness]>:
                - cast blindness remove <[value]>
            - if <[value].inventory.contains.scriptname[hideAndSeekItem]>:
                - take scriptname:hideAndSeekItem player:<[value]>
            - sidebar remove players:<[value]>
            - flag <[value]> hideAndSeek:!
            # We took them out of the game
            - teleport <[value]> <server.flag[hideAndSeek_lobbyLoc]>
        - flag server hideAndSeek:!
        # We return the stage to its original state
        - ~schematic paste name:hideAndSeek_schemBlock <server.flag[hideAndSeek_loc]>
        - schematic unload name:hideAndSeek_schemBlock

hideAndSeek_EffectSeeker:
    type: task
    definitions: seeker
    script:
        - narrate "<&e>You are now a <&a>Seeker<&e>! You must wait 30 seconds before starting." targets:<[seeker]>
        - teleport <[seeker]> <server.flag[hideAndSeek_loc]>
        - flag <[seeker]> hideAndSeek_Seeker
        - flag server hideAndSeek_Seeker:->:<[seeker]>
        - team name:hideAndSeek remove:<[seeker].name>
        - adjust <[seeker]> walk_speed:0.0
        - cast blindness amplifier:1 <[seeker]>

hideAndSeek_Leave:
    type: task
    script:
        - flag player hideAndSeek:!
        - flag server hideAndSeek:<-:<player>
        - if <player.has_flag[hideAndSeek_Seeker]>:
            - flag player hideAndSeek_Seeker:!
            - flag server hideAndSeek_Seeker:<-:<player>
        - team name:hideAndSeek remove:<player.name>
        - adjust <player> walk_speed:0.2
        - if <player.has_effect[blindness]>:
            - cast blindness remove <player>
        - if <player.inventory.contains.scriptname[hideAndSeekItem]>:
            - take scriptname:hideAndSeekItem
        - sidebar remove

hideAndSeek_Scoreboard:
    type: task
    script:
        - while <server.has_flag[hideAndSeek_Running]>:
            - sidebar set title:<&e>Hide and Seek "values:Game ends in:" players:<server.flag[hideAndSeek]>
            - sidebar add "values:<&6>           <server.flag[hideAndSeek_Running].expiration.formatted>" players:<server.flag[hideAndSeek]>
            - sidebar add "values:<&a>      <server.flag[hideAndSeek_Seeker].size> <&f>seekers" players:<server.flag[hideAndSeek]>
            - sidebar add "values:<&a>      <server.flag[hideAndSeek].size.sub[<server.flag[hideAndSeek_Seeker].size>]> <&f>hiddens" players:<server.flag[hideAndSeek]>
            - wait 5s