Putting armor on a user

Discussion in 'CommandHelper' started by MPKingJulian, Jul 30, 2017.

  1. MPKingJulian

    MPKingJulian New Member

    I looked through the API and I couldn't find a method to put armor on someone. Is this possible to do? Thanks!
  2. PseudoKnight

    PseudoKnight Well-Known Member

    Armor stands are under LivingEntity for some reason, so they can use set_mob_equipment().
  3. MPKingJulian

    MPKingJulian New Member

    I'm confused on how to do this with a user/player. How do I do this?
  4. PseudoKnight

    PseudoKnight Well-Known Member

    Oh, I misread your original post for some reason. I thought you were talking about armor stands, not players. Incidentally you can still use set_mob_equipment() for players too, if that makes more sense to you, but I'll show you how I typically do it.
    PHP:
    set_pinv(player(), array(
        100: array('name': 'DIAMOND_BOOTS'),
        101: array('name': 'DIAMOND_LEGGINGS'),
        102: array('name': 'DIAMOND_CHESTPLATE'),
        103: array('name': 'DIAMOND_HELMET'),
    ));
     
    There's a couple optional formatting things there, but as you can see, you need to provide set_pinv() an array with the keys 100-103 representing the armor slots. There's a couple other special slots: -106 is the off hand slot, and null is the main hand slot (whichever slot the player currently has selected).

    And here's how you might do it with set_mob_equipment() if that's your fancy.
    PHP:
    set_mob_equipment(puuid(), array(
        'boots': array('name': 'DIAMOND_BOOTS'),
        'leggings': array('name': 'DIAMOND_LEGGINGS'),
        'chestplate': array('name': 'DIAMOND_CHESTPLATE'),
        'helmet': array('name': 'DIAMOND_HELMET'),
    ));
  5. MPKingJulian

    MPKingJulian New Member

    Thanks. Also just another question lol.

    So what I'm looking for is for users to run methods when they're offline. For example, I have an alias where there is a set_timeout for every minute. I want to have it so if they log out that set_timeout for the next minute still runs because when you log off now you get this:

    Code (Text):

    [23:33:59 INFO]: InsufficientPermissionException: You do not have permission to use the all_players function.
            proc _givekitkotl:D:\Users\Noah\Desktop\Golem Heights Development\Test Servers\Golem Heights Hub\Arcade\plugins\CommandHelper\auto_include.ms:50
            <<closure>>:D:\Users\Noah\Desktop\Golem Heights Development\Test Servers\Golem Heights Hub\Arcade\plugins\CommandHelper\aliases.msa:81
    It works when you're logged in although when you run an alias and you log out while it's still running you get that.

    Sorry if that sounded confusion tried my best to word it.

    Thanks!
  6. PseudoKnight

    PseudoKnight Well-Known Member

    It sounds like you'r e saying the player logs out with a task that runs later. I'm not sure why it's giving an InsufficientPermissionException, though. It should give an PlayerOfflineException. You can't run (most) player functions on an offline player. My suggested solution would depend on what you're trying to do.
  7. MPKingJulian

    MPKingJulian New Member

    So basically I have an alias which basically has multiple set_timeout() functions with messages. When you're offline, it gives an insufficient permissions error which I'm not sure why.

    Thanks!
  8. MPKingJulian

    MPKingJulian New Member

    One thing I was thinking of doing is running an alias as console although when you introduced me to the scriptas() method I can't runas console so I get this exception:

    Code (Text):
    PlayerOfflineException: Expecting a player name, but "~console" was found.
  9. PseudoKnight

    PseudoKnight Well-Known Member

    The permission thing might just be your method of handling the alias permission. When a player leaves the server, they no longer have permissions. If you're not using player functions in the set_timeout() closure, then you can manually check for permissions instead of using a permission label for the alias.

    Example:
    PHP:
    # instead of this
    customperm:/alias = >>>
      # do stuff
    <<<

    # do this
    *:/alias = >>>
        if(!has_permission('customperm')) {
            die('No permission.')
        }
        # do stuff
    <<<
     
    This way it only checks permissions once before you get to your closure.

    Alternatively, if the closure if unimportant, you can check if the player is ponline() before running more code in the closure.