Repository navigation
Player
Mrkwtkr edited this page Apr 17, 2018
·
5 revisions
function Player.addItemCreativeInv(id, count, damage);
- Adds the Item to creative inventory
function Player.addItemInventory(id, count, damage);
- Adds an item to the players inventory onto a free slot
function Player.clearInventorySlot(slot);
- Empties the given slot.
function Player.getArmorSlot(slot);
- Returns the id of the piece of Armor the player is wearing in the given slot. Parameters can be:
- ArmorType.helmet
- ArmorType.chestplate
- ArmorType.leggings
- ArmorType.boots
function Player.getArmorSlotDamage(slot);
- Returns the damage of the piece of Armor the player is wearing in the given slot. Parameters can be:
- ArmorType.helmet
- ArmorType.chestplate
- ArmorType.leggings
- ArmorType.boots
function Player.getCarriedItem();
- Returns the id of the Item the player is holding in his hand.
function Player.getCarriedItemCount();
- Returns the amount of items the player is holding in his hand.
function Player.getCarriedItemData();
- Returns the damage of the item the player is currently holding. For example the damage of a tool or the content of a bucket.
function Player.getEntity();
- Returns the entity id of the player. Can be used to target functions like Entity.setVelY() at the player.
function Player.getInventorySlot(slot);
- Returns the id of the item in the given slot. (remember to start counting from 0)
function Player.getInventorySlotCount(slot);
- Returns the count of the items in the given slot. (remember to start counting from 0)
function Player.getInventorySlotData(slot);
- Returns the damage of the item in the given slot. For example the damage of a tool or the content of a bucket. (remember to start counting from 0)
function Player.getName(playerName);
- Returns the username of the player.
function Player.getSelectedSlotId();
- Returns the id of the currently active slot. (The place the item the player is holding in his hand is)
function Player.getX();
- Returns the x coordinate of the player as a float. Use Math.floor(Player.getX()) if you want to set a block there.
function Player.getY();
- Returns the y coordinate of the player as a float. Use Math.floor(Player.getY()) if you want to set a block there.
function Player.getZ();
- Returns the z coordinate of the player as a float. Use Math.floor(Player.getZ()) if you want to set a block there.
function Player.isPlayer(entity);
- Returns a boolean of whether the players camera is currently inside the players entity or inside something else
function Player.setArmorSlot(slot, id, damage);
- Changes the armor the player is wearing in the given slot
- Accepted arguments for slot:
- ArmorType.boots;
- ArmorType.chestplate;
- ArmorType.helmet;
- ArmorType.leggings;
- Accepted arguments for slot:
function Player.setInventorySlot(slot, itemId, count, damage)
- Sets the contents of the player's specified inventory slot.
Example:
Player.setInventorySlot(Player.getSelectedSlotId(), 256 /* iron shovel */, 1, 0);
function Player.enchant(slot, enchantment, level)
- Tries to add an enchantment to the item held in
slot. Returns true if the enchantment is added; false if the enchantment is incompatible with the item in the slot.
Example:
if (Player.enchant(Player.getSelectedSlotId(), Enchantment.EFFICIENCY, 1)) {
clientMessage("Added Efficiency:1 enchantment to currently held item");
} else {
clientMessage("Failed to add Efficiency:1 enchantment. You can only apply Efficiency to shovels.");
}
List of enchantments:
- Enchantment.PROTECTION
- Enchantment.FIRE_PROTECTION
- Enchantment.FEATHER_FALLING
- Enchantment.BLAST_PROTECTION
- Enchantment.PROJECTILE_PROTECTION
- Enchantment.THORNS
- Enchantment.RESPIRATION
- Enchantment.AQUA_AFFINITY
- Enchantment.DEPTH_STRIDER
- Enchantment.SHARPNESS
- Enchantment.SMITE
- Enchantment.BANE_OF_ARTHROPODS
- Enchantment.KNOCKBACK
- Enchantment.FIRE_ASPECT
- Enchantment.LOOTING
- Enchantment.EFFICIENCY
- Enchantment.SILK_TOUCH
- Enchantment.UNBREAKING
- Enchantment.FORTUNE
- Enchantment.POWER
- Enchantment.PUNCH
- Enchantment.FLAME
- Enchantment.INFINITY
- Enchantment.LUCK_OF_THE_SEA
- Enchantment.LURE
function Player.getEnchantments(slot)
- Returns an array of the enchantments on the item in the slot, or null if there is no item in that slot.
- Each item contains two attributes: type (equal to one of the Enchantment.* constants) and level (the level of the enchantment)
Example:
var enchants = Player.getEnchantments(Player.getSelectedSlotId());
if (enchants == null) {
clientMessage("Hey, you're not holding anything!");
} else {
for (var i = 0; i < enchants.length; i++) {
if (enchants[i].type == Enchantment.FIRE_ASPECT && enchants[i].level == 1) {
clientMessage("You're holding something with fire aspect level 1");
}
}
}
function Player.setHealth(health);
- Changes the players health
- Set in half hearts
- 20 for full and 0 for death
- Accepts only integers
- Also accepts higher values than 20
function Player.getItemCustomName(slot)
- Returns the custom name of the item in the specified slot of the player's inventory, or null if there is no custom name set on the item.
Example:
clientMessage(Player.getItemCustomName(Player.getSelectedSlotId());
function Player.setItemCustomName(slot, name)
- Sets a custom name on the item in the specified slot of the player's inventory.
Example:
Player.setItemCustomItem(Player.getSelectedSlotId(), "Ultimate Sword of Ultimate Destiny");
Player.addItemCreativeInv(id, count, damage);
Player.addItemInventory(id, count, damage);
Player.clearInventorySlot(slot);
Player.getArmorSlot(slot);
Player.getArmorSlotDamage(slot);
Player.getCarriedItem();
Player.getCarriedItemCount();
Player.getCarriedItemData();
Player.getInventorySlot(slot);
Player.getInventorySlotCount(slot);
Player.getInventorySlotData(slot);
Player.getName(playerName);
Player.getSelectedSlotId();
Player.getX();
Player.getY();
Player.getZ();
Player.isPlayer(entity);
Player.setArmorSlot(slot, id, damage);