Item retrieval for player death

Discussion in 'CommandHelper Scripts' started by switorik, Mar 19, 2016.

  1. switorik

    switorik New Member

    I'm somewhat new to this so I'll gladly take any criticism.

    I made this script because I run a survival server and every once in a while, we would have a hiccup where someone would die and lose their items due to a bug or admin abuse. This script has saved me from receiving many complaints due to the fact that I can return a player their long lost items if they unfairly lost them.

    Place this in the main.ms
    You have to modify okworlds to the worlds where you want to save a players items if they die. I use this in case I have creative worlds or worlds with keepinventory on.
    Code (Text):
    bind(player_death, null, null, @event,
    @id = puuid(@event[player], true)
    @okworlds = array('world', 'world_nether', 'world_the_end')
    if(array_contains_ic(@okworlds, @event[location][world])) {
        if(@event[drops] == array('')) { die() } else { store_value('deathitems.'.@id, @event[drops]) }
    }
    )
    The command:
    This is an admin command, you can dupe items if a player wants to keep retrieving items.
    This command will replace the entire inventory with the items lost upon death. It is encouraged for the target to have a clear inventory when using this command.
    Requires permission ' deathitems.use'
    Code (Text):

    /di [$cmd] [$player] = >>>
    if(has_permission(player(), 'deathitems.use')) {
        switch($cmd) {
            case '':
                #displays an array of a players death items. Same as view.
                if($player == '') { @id = puuid(player(), true) }
                    else { try(@id = puuid(player($player), true), die(color(4).'A player by that name could not be found.')) }
                @items = get_value('deathitems.'.@id)
                msg(@items)
            case 'view':
                #displays an array of a players death items.
                if($player == '') { @id = puuid(player(), true) }
                    else { try(@id = puuid(player($player), true), die(color(4).'A player by that name could not be found.')) }
                @items = get_value('deathitems.'.@id)
                msg(@items)
            case 'return':
                #Replaces a players inventory with their death items.
                if($player == '') { die(color(4).'You must enter an online players name.') }
                try(@pid = player($player), die(color(4).'A player by that name is not on line.'))
               
                @id = puuid(@pid, true)
                @items = get_value('deathitems.'.@id)
               
                set_pinv(@pid, @items)
                for(@i = 36, @i < 60, @i++) {
                try(if( nequals(@items[@i], null)) { drop_item(ploc(@pid), @items[@i], true ) }, die())
                }
                msg(color(e).player($player).'s inventory has been restored.')
            case 'retrieve':
                #Replaces your inventory with a players death items.
                if($player == '') { die(color(4).'You must enter an online players name.') }
                try(@id = puuid($player, true), die(color(4).'A player by that name is not online.'))
               
                @items = get_value('deathitems.'.@id)
               
                set_pinv(player(), @items)
                if(array_size(@items) > 36) {
                    for(@i = 36, @i < 60, @i++) {
                        try(if( nequals(@items[@i], null)) { drop_item(ploc(player()), @items[@i], true ) }, die())
                    }
                }
                msg(color(e).$player.'s inventory has been restored to you.')
            case 'help':
                #Displays possible sub commands.
                die(colorize('&eYou can use &5return&e, &5retrieve&e, and &5view&e &eas options.'))
            default:
                #Displays possible sub commands.
                die(colorize('&eYou can use &5return&e, &5retrieve&e, and &5view&e &eas options.'))
        }
    }
    <<<
     
    I would like to hear some feedback/suggestions if you use it or modify it.

    Thanks
    Last edited: Mar 19, 2016
  2. PseudoKnight

    PseudoKnight Well-Known Member

    Needs more tabs. It's harder to read otherwise.
  3. switorik

    switorik New Member

    Thanks for the feedback, I tried adding some more tabs and lines to help clarify a little more.