Paste #123510: Unnamed Denizen Script Paste

Date: 2024/06/07 04:00:14 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


force_shield:
    type: task
    definitions: target|multiplier
    script:
        # Set the middle of the shield
        - define origin <player.location.add[0,1.2,0]>
        # Will define the position for the particles
        - define shield <ellipsoid[0,0,0,<[origin].world.name>,7,7,7].shell.parse[div[1.8].add[<[origin]>]]>
        - define outer_shield <ellipsoid[0,0,0,<[origin].world.name>,7,7,7].shell.parse[div[1.55].add[<[origin]>]]>
        - define inner_shield <ellipsoid[0,0,0,<[origin].world.name>,7,7,7].shell.parse[div[2.05].add[<[origin]>]]>
        # Save the location of the shield and remove it after x seconds
        - flag server shield<player.uuid>:<[origin].to_ellipsoid[3.8,3.8,3.8]> expire:20s
        # Defines the players originally INSIDE the shield
        - define safe_entities <[origin].find.living_entities[].within[3.9]>
        # Flag those players that they're in the shield.
        - foreach <[safe_entities]> as:ent:
            - flag <[ent]> in_shield<player.uuid>
        ## Radius of shield should be a variable. For now, Radius = 3.5
        ## Outer shield should be radius + 0.5
        ## Inner shield should be radius - 0.4
        - repeat 500 as:n:
            # Find the entities that try to get inside or outside
            - define ents <[origin].find.living_entities.within[4]>
            - narrate <[ents]>
            - define unalive_ents <[origin].find_entities.within[4].filter_tag[<[filter_value].is_living.not>]>
            - define ents:->:<[unalive_ents]>
            - foreach <[ents]> as:ent:
                - define distance_to_inner <[ent].location.distance[<[origin]>].sub[3.1].abs>
                - define distance_to_outer <[ent].location.distance[<[origin]>].sub[4].abs>
                # if the entity isnt far out enough, stop
                - if <[ent].location.distance[<[origin]>]> < 3.1:
                    - foreach next
                # if the entity is closer to the inner shield than the outer shield it's trying to get out: Push to origin
                - if <[distance_to_inner]> < <[distance_to_outer]>:
                    - push <[ent]> origin:<[ent].location> destination:<[origin]> no_rotate speed:0.5
                    - wait 0.1s
                # If the entity is closer to the outer shield than the inner shield, it's trying to get in: Push away
                - if <[distance_to_outer]> < <[distance_to_inner]>:
                    - adjust <[ent]> velocity:<[ent].location.sub[<[origin]>].normalize.div[1.5]>