Paste #76784: SkillsHandler.dsc

Date: 2020/10/22 13:46:53 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


#
# Feel free to use it however you like :D
#
# version 0.2
# author: RoboChicken
#
# skill keys:
#    CLICK:
#     - triggers when player right clicks any block including air
#     - ideal for activating aoe or utility skills
#    ATTACK:
#     - triggers when attacking an entity
#     - for combat skills
#    BOW:
#     - triggers when an entity shoots a bow
#     - can be used to change the type of projectile
#     - or add effects when shooting the bow
#    ARROW:
#     - triggers when an arrow/projectile hits an entity or a block
#     - useful for making custom arrows
#    SHIELD:
#     - triggers when a player toggles his shield either hand
#
#   There are predefined tags that you can use directly in your task scripts
#   but make sure you add the tags that you are using in the "definitions" key
#   of your task script to prevent vscode from detecting it as an error
#
#   A little heads up for the spigot boys, you will have to change the code for the arrow
#   skill because the <context.item> tag for the bow shooting event only works on paper.
#   hint: use a tag that gets the first arrow item of the player's inventory
#
item_skills_handler:
  type: world
  debug: false
  events:
    on player right clicks block using:hand:
    - if <context.item.script.data_key[skills.click]||null> != null:
      - define player <player>
      - define item <context.item>
      - define location <context.location||<player.location>>
      - define relative <context.relative||null>
      - inject <[item].script.data_key[skills.click]>

    on player damages entity:
    - if <context.damager.item_in_hand.script.data_key[skills.attack]||null> != null:
      - define player <context.damager>
      - define item <context.damager.item_in_hand>
      - define entity <context.entity>
      - define finalDamage <context.final_damage>
      - inject <[player].item_in_hand.script.data_key[skills.attack]>

    on player shoots bow:
    - if <context.item.script.data_key[skills]||null> != null:
      - define player <context.entity>
      - define projectile <context.projectile>
      - define bow <context.bow>
      - define force <context.force>
      - define item <context.item>
      - if <[item].script.data_key[skills.bow]||null> != null:
        - inject <[item].script.data_key[skills.bow]>
      - if <[item].script.data_key[skills.arrow]||null> != null:
        - flag <[projectile]> shooter:<[player]>
        - flag <[projectile]> bow:<[bow]>
        - flag <[projectile]> force:<[force]>
        - flag <[projectile]> arrow:<[item]>
        - flag <[projectile]> skills.arrow:<context.item.script.data_key[skills.arrow]>

    on projectile hits block:
    - if <context.projectile.has_flag[skills.arrow]>:
      - define player <context.projectile.flag[shooter]>
      - define bow <context.projectile.flag[bow]>
      - define force <context.projectile.flag[force]>
      - define arrow <context.projectile.flag[item]>
      - define location <context.location>
      - inject <context.projectile.flag[skills.arrow].as_script>
    on projectile collides with entity:
    - if <context.projectile.has_flag[skills.arrow]>:
      - define player <context.projectile.flag[shooter]>
      - define bow <context.projectile.flag[bow]>
      - define force <context.projectile.flag[force]>
      - define arrow <context.projectile.flag[item]>
      - define projectile <context.projectile>
      - define entity <context.entity>
      - inject <[projectile].flag[skills.arrow].as_script>

    # doesnt have much tags but would be nice if
    # theres a tag for the shield item and whatever hand is using it
    on player toggles shield:
    - if <player.item_in_hand.script.data_key[skills.shield]||null> != null:
      - define player <player>
      - define item <player.item_in_hand>
      - define state <context.state>
      - define hand hand
      - inject <[item].script.data_key[skills.shield]>
    - if <player.item_in_offhand.script.data_key[skills.shield]||null> != null:
      - define player <player>
      - define item <player.item_in_offhand>
      - define state <context.state>
      - define hand off_hand
      - inject <[item].script.data_key[skills.shield]>