Anyway to enchant an item that "cannot be enchanted"?

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

  1. MPKingJulian

    MPKingJulian New Member


    I'm trying to enchant an item that isn't supposed to be enchanted (a cake). With other plugins I can enchant it just fine although when using this:

    Code (Text):
    enchant_inv(player(), 0, KNOCKBACK, 2)

    When I try to use this I get thrownback with this exception:


    Is there anyway to bypass this restriction?

  2. PseudoKnight

    PseudoKnight Well-Known Member Developer

    To anyone searching the forums, the error says "KNOCKBACK cannot be applied to this item". Yes, you can bypass this restriction. Enchant_inv(), you could say, is designed to be within the vanilla restrictions. All other methods do not use them. This includes using set_pinv(), pgive_item(), and even enchant_inv_unsafe(), which is the same as enchant_inv() but uncapped.
    MPKingJulian likes this.
  3. MPKingJulian

    MPKingJulian New Member

    Ok cool and is there anyway to use runas() so it runs an alias? When I use an alias it will show an unknown command error (vanilla error). Got a way to fix this? :/

  4. PseudoKnight

    PseudoKnight Well-Known Member Developer

    Typically you can use call_alias() or run_cmd() which supports both commands and aliases. However, those don't have a function equivalent of runas(). So when you need to change the player context, you can wrap it in scriptas().
    scriptas(@player, run_cmd(@command))
    This is actually the only instance I've found scriptas() useful -- running a command that runs a command for another player.

    Another alternative, I suppose, is using chatas(). I believe this should run a command as the player, and will trickle down through the normal command handling, so CH will pick it up and check for aliases too. However, beware of running an alias that has chatas() that could run the same alias, as you could get an infinite loop. (unlikely, but possible)
    MPKingJulian likes this.