Paste #24116: Untitled Paste

Date: 2015/12/19 17:27:54 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


# Zombie Survival

ZS_DefaultData:
    type: yaml data
    config: 
        help:
        - "&a/zs help &8- &9shows this help information."
        - "&a/zs check (arena) &8- &9Checks if the arena is ready."
        - "&a/zs addspawn (arena)"
        - "&a/zs delspawn (arena) (number)"
        - "&a/zs resetspawn (arena)"
        npcid:
            Squad1: 41
            Squad2: 39
            Squad3: 40
            Squad4: 38

# Call: <s@ZS_DefaultData.yaml_key[config.help]>

### Arena Flags:
## MapName - (Already defined when calling) (Default)
## Map Status - Status:Standby/Running/Closed
## Map Lobby - Lobby:<player.location>
## Spawn locations for mobs - SpawnLocs:<dList>
## Start Positions for players - StartLocs:<dList>
## Wave counter - WaveCounter:21
## Players left in arena - PlayersInArena:<dList>
## Players Spectating - PlayersSpec:<dList>
## Arena Cuboid - ArenaCuboid:<dCuboid>

### Player Flags:
## If they are in a Arena - Survivor:Default
## If they are a spectator - Spec:Default
## Their Coins - Coins:1257
## Highest Record - Highest_Wave:28
## Zombies Total Killed - Zombies_Killed:328

### Main Flags:
## Lobby/Hub - Main_Lobby:<player.location>
## Total_Mobs_Slain:3215
## All Arenas - List_Arenas:<dList>

ZS_Events:
    type: world
    events:
        on player join:
        - if <server.has_file[/ZS/players/<player.uuid>.yml].not> {
            - yaml create id:<player>
            # Setup Basics
            - yaml id:<player> set Coins:0
            - yaml id:<player> set Highest_Wave:0
            - yaml id:<player> set Zombies_Killed:0
            - yaml id:<player> "savefile:/ZS/players/<player.uuid>.yml"
        }
        else {
            - yaml "load:/ZS/players/<player.uuid>.yml" id:<player>
        }

        on player quit:
        - yaml id:<player> "savefile:/ZS/players/<player.uuid>.yml"
        - yaml unload id:<player>

        on server start:
        - if <server.has_file[/ZS/config.yml].not> {
            - yaml create id:ZS_config
            # Setup Basics
            - yaml id:ZS_config set Main_Lobby:l@0,70,0,world
            - yaml id:ZS_config set Total_Mobs_Slain:0

            # Add Arena and its template
            - yaml id:ZS_config set List_Arenas:->:Test
            - define ArenaName <yaml[ZS_config].read[List_Arenas].get[0]>
            # Status
            - define path Arenas.<def[ArenaName]>.Status
            - yaml id:ZS_config set <def[path]>:Closed
            # Cuboid cu@<position_1>|<position_2>
            - define path Arenas.<def[ArenaName]>.ArenaCuboid
            - yaml id:ZS_config set <def[path]>:cu@l@10,62,10,world|l@-10,68,-10,world
            # Lobby Location
            - define path Arenas.<def[ArenaName]>.Lobby
            - yaml id:ZS_config set <def[path]>:l@0,68,0,world
            # SpawnLocs
            - define path Arenas.<def[ArenaName]>.SpawnLocs
            - yaml id:ZS_config set <def[path]>:->:l@5,64,0,world
            - yaml id:ZS_config set <def[path]>:->:l@0,64,0,world
            - yaml id:ZS_config set <def[path]>:->:l@-5,64,0,world
            # StartLocs
            - define path Arenas.<def[ArenaName]>.StartLocs
            - yaml id:ZS_config set <def[path]>:->:l@5,64,5,world
            - yaml id:ZS_config set <def[path]>:->:l@0,64,5,world
            - yaml id:ZS_config set <def[path]>:->:l@-5,64,5,world
            # CurrentWave
            - define path Arenas.<def[ArenaName]>.CurrentWave
            - yaml id:ZS_config set <def[path]>:0
            # PlayersInArena
            - define path Arenas.<def[ArenaName]>.PlayersInArena
            - yaml id:ZS_config set <def[path]>:->:p@User_Name
            - yaml id:ZS_config set <def[path]>:<-:p@User_Name
            # PlayersSpec
            - define path Arenas.<def[ArenaName]>.PlayersSpec
            - yaml id:ZS_config set <def[path]>:->:p@User_Name
            - yaml id:ZS_config set <def[path]>:<-:p@User_Name
            # Save Template
            - yaml id:ZS_config "savefile:/ZS/config.yml"
        }
        else {
            - yaml "load:/ZS/config.yml" id:ZS_config
        }

        on shutdown:
        - yaml unload id:ZS_config

        on resource pack status:
            - if <context.status> == SUCCESSFULLY_LOADED {
                - narrate "<&a>Your resource pack was loaded succesfully!"
                - playsound <player> sound:QuestDone volume:0.5 pitch:1.0 custom
            }
            # else if <context.status> == ACCEPTED {
                # - narrate "<&a>Thank you for using our resource pack!"
                # - narrate "<&7>Your download should begin shortly..."
            # }
            else if <context.status> == DECLINED {
                - wait 5t
                - execute as_server "kick <player.name> Zombie Survival requires Server Resource Pack!"
            }
            else if <context.status> == FAILED_DOWNLOAD {
                - wait 5t
                - execute as_server "kick <player.name> Your resource pack failed to download... try again."
            }

        on entity targets:
        - if <context.target||null> == null || <context.reason> == FORGOT_TARGET {
            - flag <context.entity> Targeting:!
        }
        - flag <context.entity> Targeting:<context.target>

        # - spawn e@zombie[max_health=2;health=2;speed=0.5] <context.location>
        on zombie death:
        - if <context.damager.is_player||false>  {
            - define player "<context.damager>"
        }
        else if <context.damager.shooter.is_player||false> {
            - define player "<context.damager.shooter>"
        }
        - if <server.has_flag[Zombie_Call]> queue clear
        - define Players <context.entity.location.find.players.within[50].random||null>
        - if <def[Players]> == null queue clear
        - flag server Zombie_Call:True duration:15s
        - foreach <context.entity.location.find.entities[ZOMBIE|SKELETON].within[50]> {
            - if <def[value].has_flag[Targeting].not> {
                - attack <def[value]> target:<def[Players].as_list.random>
            }
        }

ZS_Command:
    type: command
    name: zs
    description: Zombie Survival setup admin commands
    usage: /zs
    aliases:
    - zombiesurvival
    permission: zs.admin
    permission message: Sorry, <player.name>, you don't have the permission '<permission>'! 
    script:
    # - if !<player.is_op> queue clear
    - if <context.args.size> > 0 {
        - if <context.args.get[1]> == "help" {
            - foreach <s@ZS_DefaultData.yaml_key[config.help]> {
                - narrate "<def[value].parse_color>"
            }
        }
        else if <context.args.get[1]> == "check" {
            - if <context.args.size> != 2 {
                - narrate "<&c>Wrong arguments! <&b>/zs help"
                - queue clear
            }
            ## Should check
            - define check <proc[ZS_CheckArena].context[<context.args.get[2]>]>
            - if <def[check]> == "true" {
                - narrate "<&a><context.args.get[2]> seems to be setup correctly."
            }
            else {
                - narrate "<&c><def[check]> is missing in <context.args.get[2]>!"
            }
        }
        else if <context.args.get[1]> == "AddSpawn" {
            - if <context.args.size> != 2 {
                - narrate "<&c>Wrong arguments! <&b>/zs help"
                - queue clear
            }
            ## Should add Position
            - define ArenaName <context.args.get[2]>
            - define SpawnLocs <yaml[ZS_config].read[<path>]>
            - define path Arenas.<def[ArenaName]>.SpawnLocs
            - yaml id:ZS_config set <def[path]>:->:<player.location>
            - yaml id:ZS_config "savefile:/ZS/config.yml"
            - narrate "<&a>Successfully added spawn location for <def[ArenaName]> (<def[SpawnLocs].size>)"
        }
        else if <context.args.get[1]> == "DelSpawn" {
            - define ArenaName <context.args.get[2]>
            - define path Arenas.<def[ArenaName]>.SpawnLocs
            - if <context.args.size> != 3 {
                - narrate "<&c>Wrong arguments! <&b>/zs help"
                - queue clear
            }
            - if <context.args.get[3].is[matches].to[integer].not> {
                - narrate "<&c>Wrong integer! <&b>/zs help"
                - queue clear
            }
            - define SpawnLocs <yaml[ZS_config].read[<def[path]>]>
            - announce "<yaml[ZS_config].read[<def[path]>]>"
            - announce "<def[SpawnLocs].size>"
            - if <context.args.get[3]> >= <def[SpawnLocs].size> || <context.args.get[3]> < 0 {
                - narrate "<&c>Out of index integer! <&b>/zs help"
                - queue clear
            }
            ## Should delete Position
            - define path "Arenas.<def[ArenaName]>.SpawnLocs[<context.args.get[3]>]"
            - announce "Arenas.<def[ArenaName]>.SpawnLocs[<context.args.get[3]>]"

            ### This right here deletes the whole list ###
            - yaml id:ZS_config set <def[path]>:!

            - yaml id:ZS_config "savefile:/ZS/config.yml"
            - narrate "<&a>Successfully deleted spawn location <context.args.get[3]> for <def[ArenaName]> (<def[SpawnLocs].size>)"
        }
        else {
            - narrate "<&c>Wrong arguments! <&b>/zs help"
        }
    }
    else {
        - foreach <s@ZS_DefaultData.yaml_key[config.help]> {
            - narrate "<def[value].parse_color>"
        }
    }

    ## Add new arena (name)
    ## Add Lobby position to arena
    ## Add Spawn Position to arena
    ## Add Start position to arena
    ## Check arena
    ## Force-end arena
    ## Close/Open arena

ZS_CheckArena:
    type: procedure
    definitions: ArenaName
    script:
    - define path Arenas.<def[ArenaName]>.Lobby
    - if <yaml[ZS_config].contains[<def[path]>].not> {
        - determine "Lobby"
    }
    - define path Arenas.<def[ArenaName]>.SpawnLocs
    - if <yaml[ZS_config].contains[<def[path]>].not> {
        - determine "Spawn locations"
    }
    - define path Arenas.<def[ArenaName]>.StartLocs
    - if <yaml[ZS_config].contains[<def[path]>].not> {
        - determine "Start locations"
    }
    - define path Arenas.<def[ArenaName]>.ArenaCuboid
    - if <yaml[ZS_config].contains[<def[path]>].not> {
        - determine "Cuboid"
    }
    - determine "true"

ZS_SpawnZombies:
    type: task
    script:
    - define Amount 5
    - define ArenaName Test
    - define locs <yaml[ZS_config].read[Arenas.<def[ArenaName]>.StartLocs]>
    - repeat <def[Amount]> {
        - while <proc[ZS_SpawnZombie].context[<def[locs].random>]> {
            - wait 2t
            - if <yaml[ZS_config].read[Arenas.<def[ArenaName]>.Status]> != Running {
                - queue clear
            }
        }
    }

ZS_SpawnZombie:
    type: procedure
    definitions: Randomloc
    script:
    - define Players <def[Randomloc].as_location.find.players.within[8].filter[has_flag[Survivor]]||null>
    - define Nearby <def[Randomloc].as_location.find.players.within[30].filter[has_flag[Survivor]].random||null>
    - if <def[Players]> == null || <def[Players].is_empty> {
        - if <def[Nearby]> == null {
            - determine true
        }
        else {
            - spawn e@zombie[max_health=2;health=2;speed=0.3] <def[Randomloc]> target:<def[Nearby]>
            - determine false
        }
    }
    - determine true



    # - define cuboid cu@<def[loc].as_location.add[l@-20,0,-20,world]>|<def[loc].as_location.add[l@20,0,20,world]>
    # - define list <def[cuboid].as_cuboid.outline>
    # - repeat <def[Amount]> {
        # - define randomPos <def[list].as_list.random.highest>
        # #- if <def[randomPos].as_location.light> <= 7 {
        # - define Players <def[randomPos].as_location.find.players.within[5].filter[<player.has_flag[Survivor]>]||null>
        # - if <def[Players]> == null {
            # - spawn e@zombie[max_health=2;health=2;speed=0.5] <def[randomPos]> target:<def[randomPos].as_location.find.players.within[30].filter[<player.has_flag[Survivor]>].random>
        # }
        # #}
    # }
    # <l@location.highest>
    # <el@element.mod[<#.#>]>

# <yaml[<id>].contains[<path>]>
# <yaml[<id>].read[<path>]>
#