Paste #3884: Corpse

Date: 2014/04/30 17:31:07 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


# When a player dies there is a corpse created in their place. In order for this to work
# Gamerule KeepInventory must be set to true. Also armour is not put into the inventory of
# the corpse.
clean:
    type: world
    events:
        on player quit:
        - if <n@<player.flag[body]>.inventory.stacks> == 0 remove n@<player.flag[body]>
death:
    type: world
    events:
        on player dies:
# If there is an old body it will drop everything.
        - foreach <n@<player.flag[body]>.inventory.list_contents> { - drop %value% <n@<player.flag[body]>.location> }
# Removes an old body if there is one
        - remove n@<player.flag[body]>
# Create body at the players death location 
        - create player <player.name> <player.location>
# Flag dead player to the created npc for latter/earlier reference
        - flag player body:<n@<player.name>.id>
# give script to body to retrieve items 
        - assignment set script:corpse npc:<player.name>
# Move inventory from dead player, to new body
        - inventory move d:in@npc[n@<player.flag[body]>] o:<p@<player.name>.inventory>
# Does not work as expected.
#        - animate n@<player.flag[body]> a:sleep
corpse:
    type: assignment
    interact scripts:
    - 10 body
body:
    type: interact
    Steps:
        'retrive':
            click trigger:
                script:
                - inventory open d:<npc.inventory>
            damage trigger:
                script:
                - ^inventory add o:in@npc[n@<player.flag[body]>] d:<p@<player.name>.inventory>
                - ^remove n@<npc.id>