Paste #6069: Untitled Paste

Date: 2014/07/01 21:26:33 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


# Dueling
# Citizens 2 (build #1130)
# Denizen 0.9.4 (build #1474)
#
# This is a Denizen script that allows players to use commands to duel in a designated
# Arena. You will need your own protection plugin such as WorldGuard.
# 
# The Script uses simple commands which are /duel for help, /duel [player] to duel someone
# To accept or deny a duel, you type /deny or /accept. Typing partial player names is supported.
# 
# Plans: Add queue system / Add default constants for spawn locations
# Allow players to place wagers / Add Spectating / Add protection
#
# @author TheRealKeith
# @script version 1.0.0
# @last-updated July 1 2014
# @irc EsperNet IRC Network #denizen-dev
# @Minecraft Server - play.insomniacraft.com

# This is the initial duel command. It checks if you specified a player, if you dueled yourself, or if the player is online.

'DuelCommand':
  type: world
  debug: true
  events:
    on duel command:
    - if <context.args.size> != 1 {
      - narrate "<&6>[Duel] <&c>You did not specify a player. Type /Duel [Player]"
      - determine fulfilled
      }
    - if <global.flag[DuelInProgress]> {
      - narrate "<&6>[Duel] <&c>There is currently another Duel in progress. Please wait and try again shortly."
      - determine fulfilled
      }
    - define requested <server.match_player[<context.args.get[1]>]>
    - define requester <player.name>
    - if %requested% == null {
      - narrate "<&6>[Duel] <&c>This player is not online or doesn't exist."
      - determine fulfilled
      }
    - if %requested% == <player> {
      - narrate "<&6>[Duel] <&c>You cannot duel your self!"
      - determine fulfilled
      } else {
        - flag global DuelRequested:%requested%
        - flag global DuelRequester:%requester%
        - narrate "<&6>[Duel] <&a>You have sent a request to <global.flag[DuelRequested].as_player.name>" targets:%requester%
        - narrate "<&6>[Duel] <&a><global.flag[DuelRequester].as_player.name> has requested a duel" targets:%requested%
        - narrate "<&6>[Duel] <&a>You can type <WHITE>/Accept <&a>or <WHITE>/Deny" targets:%requested%
        - determine fulfilled
        }

# This checks to see if the player is in the "Arena" you made using world edit, and prevents dropping of items.

'DropItems':
  type: world
  debug: true
  events:
    on player drops item:
    - if <player.location.in_region[pits]> {
      - determine cancelled
      }

# This is when the player uses the /accept command. It flags both players, the requested and the requester. If those flags are null
# or otherwise if no one has challenged you, it will state such. Otherwise, if the player accepts the duel request, it sends narrations
# to both players, and runs the next task. The null check is if no duels are going on at all. The other check is to make sure they are valid.

'DuelAccept':
  type: world
  debug: true
  events:
    on accept command:
    - define requested <global.flag[DuelRequested]>
    - define requester <global.flag[DuelRequester]>
    - if %requested% == null || %requester% == null {
      - narrate "<&6>[Duel] <&c>You have no pending duel requests."
      - determine fulfilled
      } else
    - if <global.flag[DuelRequested]> == %requested% && <global.flag[DuelRequester]> == %requester% {
      - flag global DuelInProgress
      - narrate "<&6>[Duel] <&a><global.flag[DuelRequested].as_player.name> has accepted your duel request." targets:%requester%
      - narrate "<&6>[Duel] <&a>You have accepted <global.flag[DuelRequester].as_player.name>'s duel request." targets:%requested%
      - run DuelAccepted as:%requester% instantly
      - run DuelAccepted as:%requested% instantly
      - run TeleportRequester as:%requester% instantly
      - run TeleportRequested as:%requested% instantly
      - determine fulfilled
      } else {
        - narrate "<&6>[Duel] <&c>You have no pending duel requests."
        - determine fulfilled
        }

"TeleportRequester":
  type: task
  debug: true
  script:
    - teleport l@-2874,65,3241,world

"TeleportRequested":
  type: task
  debug: true
  script:
    - teleport %requested% l@-2917,65,3241,world

# This is when the requested player uses the /deny command. It works the same as the accept command, but drops
# the requested and requester flags to clear room for the next players, or otherwise removing them from queue.

'DuelDeny':
  type: world
  debug: true
  events:
    on deny command:
    - define requested <global.flag[DuelRequested]>
    - define requester <global.flag[DuelRequester]>
    - if %requested% == null || %requester% == null {
      - narrate "<&6>[Duel] <&c>You have no pending duel requests."
      - determine fulfilled
      } else
    - if <global.flag[DuelRequested]> == %requested% && <global.flag[DuelRequester]> == %requester% {
      - narrate "<&6>[Duel] <&c><global.flag[DuelRequested].as_player.name> has denied your duel request." targets:%requester%
      - narrate "<&6>[Duel] <&c>You have denied %requester%'s duel request." targets:%player%
      - flag global DuelRequested:!
      - flag global DuelRequester:!
      - flag global DuelInProgress:!
      - determine fulfilled
      } else {
        - narrate "<&6>[Duel] <&c>You have no pending duel requests."
        - determine fulfilled
        }

# This is the task the runs if a player accepts the duel. It runs for both players just as they are teleporting.
# As a safeguard, if they are not in the arena, the script stops. It clears any potion effects the players may have had.
# Then runs a script which freezes them for 4 seconds while it counts down to begin. This also stores the players inventory.

"DuelAccepted":
  type: task
  debug: true
  script:
    - heal 20.0
    - define requested <global.flag[DuelRequested]>
    - define requester <global.flag[DuelRequester]>
    - execute as_server 'effect <player.name> clear'
    - adjust <player> walk_speed:0
    - flag <player> BeforeDuelLoc:<player.location.simple>
    - flag <player> ItemsBeforeDuel:<player.inventory.list_contents>
    - flag <player> ItemsBeforeDuelHead:<player.equipment.helmet>
    - flag <player> ItemsBeforeDuelChest:<player.equipment.chestplate>
    - flag <player> ItemsBeforeDuelLegs:<player.equipment.leggings>
    - flag <player> ItemsBeforeDuelBoots:<player.equipment.boots>
    - inventory clear destination:<player.inventory>
    - equip <player> head:<i@Duel1>
    - equip <player> chest:<i@Duel2>
    - equip <player> legs:<i@Duel3>
    - equip <player> boots:<i@Duel4>
    - equip <player> hand:<i@Duel5>
    - inventory update destination:<player.inventory>
    - run DuelCountDown

# This is the count down. This is in its own container because it cannot be run instantly like the DuelAccepted task.

"DuelCountDown":
  type: task
  debug: true
  script:
    - narrate "<&6>[Duel] <&a>The duel will begin in 4..."
    - wait 1
    - narrate "<&6>[Duel] <&a>The duel will begin in 3..."
    - wait 1
    - narrate "<&6>[Duel] <&a>The duel will begin in 2..."
    - wait 1
    - narrate "<&6>[Duel] <&a>The duel will begin in 1..."
    - wait 1
    - adjust <player> walk_speed:0.2
    - narrate "<&a>Begin!"

# This is what happens when the duel is considered "Over", it flags a player as a winner and a loser and announces it to the server.

"DuelDeath":
  type: world
  debug: true
  events:
    on player kills player:
      - if <player.location.in_region[Pits]> {
        - determine passively CANCELLED
        - announce "<&6>[Duel] <&b><context.damager.as_player.name> <&a>has won the duel against <&b><context.entity.as_player.name>!"
        - run DuelDone as:<context.damager> instantly
        - run DuelDone as:<context.entity> instantly
        }

# This is what happens when the duel is over. The inventory is cleared out, the players are teleported back to their original locations
# Their inventories are restored, and all of the flags are cleared out to prepare the server for the next duelers.

"DuelDone":
  type: task
  debug: true
  script:
    - inventory clear destination:<player.inventory>
    - inventory update destination:<player.inventory>
    - teleport <player.flag[BeforeDuelLoc]>
    - equip <player> boots:<player.flag[ItemsBeforeDuelBoots]||i@air>
    - equip <player> leggings:<player.flag[ItemsBeforeDuelLegs]||i@air>
    - equip <player> chestplate:<player.flag[ItemsBeforeDuelChest]||i@air>
    - equip <player> helmet:<player.flag[ItemsBeforeDuelHead]||i@air>
    - foreach <player.flag[ItemsBeforeDuel].exclude[i@air]> {
      - give %value%
      }
    - flag global DuelRequested:!
    - flag global DuelRequester:!
    - flag global DuelInProgress:!
    - flag <player> BeforeDuelLoc:!

# These are the items that get equipped when the duel starts. Customize these to fit your servers needs.

Duel1:
    type: item
    no_id: true
    material: i@leather_helmet
    display name: '<&8>Test'
    color: c@075,066,045

Duel2:
    type: item
    no_id: true
    material: i@leather_chestplate
    display name: '<&8>Test'
    color: c@075,066,045

Duel3:
    type: item
    no_id: true
    material: i@leather_leggings
    display name: '<&8>Test'
    color: c@075,066,045

Duel4:
    type: item
    no_id: true
    material: i@leather_boots
    display name: '<&8>Test'
    color: c@075,066,045

Duel5:
    type: item
    no_id: true
    material: i@stone_sword
    display name: '<&8>Test'