#Offhand?

1 messages · Page 1 of 1 (latest)

grim igloo
#

Is it possible to make all the items to get in offhand by like itemstack or so or not?

novel elk
grim igloo
novel elk
grim igloo
grim igloo
# novel elk ```js Player.getComponent("equippable").getEquipment("offhand"); ```
import { world, system, EquipmentSlot } from "@minecraft/server";

system.runInterval(() => {
    for (const player of world.getPlayers()) {
        player.getComponent("equippable").getEquipmentSlot("offhand");
    }
});```
Bro this is not working throwing error
[Scripting][error]-TypeError: Native type conversion failed. Function argument [0] expected type: EquipmentSlot    at <anonymous> (main.js:5)
#
// Gives the player some equipment
import { EquipmentSlot, ItemStack, Player, EntityComponentTypes } from '@minecraft/server';
import { MinecraftItemTypes } from '@minecraft/vanilla-data';

function giveEquipment(player: Player) {
    const equipmentCompPlayer = player.getComponent(EntityComponentTypes.Equippable);
    if (equipmentCompPlayer) {
        equipmentCompPlayer.setEquipment(EquipmentSlot.Head, new ItemStack(MinecraftItemTypes.GoldenHelmet));
        equipmentCompPlayer.setEquipment(EquipmentSlot.Chest, new ItemStack(MinecraftItemTypes.IronChestplate));
        equipmentCompPlayer.setEquipment(EquipmentSlot.Legs, new ItemStack(MinecraftItemTypes.DiamondLeggings));
        equipmentCompPlayer.setEquipment(EquipmentSlot.Feet, new ItemStack(MinecraftItemTypes.NetheriteBoots));
        equipmentCompPlayer.setEquipment(EquipmentSlot.Mainhand, new ItemStack(MinecraftItemTypes.WoodenSword));
        equipmentCompPlayer.setEquipment(EquipmentSlot.Offhand, new ItemStack(MinecraftItemTypes.Shield));
    } else {
        console.warn('No equipment component found on player');
    }
}```
Maybe this will help you it's documentaion of EntityEquippableComponent
ember moat
#
import { world, system, EquipmentSlot } from "@minecraft/server";

system.runInterval(() => {
    for (const player of world.getPlayers()) {
        player.getComponent("equippable").getEquipmentSlot(EquipmentSlot.Offhand);
    }
});```
#

Literally

grim igloo
#

Ok sir!

ember moat
#

It will work, also it can be undefined so make sure you have a check for it so it doesn't throw an error, and your welcome

grim igloo
ember moat
#

And bedrock doesn't allow you to put items in your offhand slot

#

You can either forcefully put the items there

#

Or make custom items that can be put in the offhand slot

grim igloo
grim igloo
#

but i was asking this that is it possible by script?

novel elk
#

/replaceitem entity @s slot.weapon.offhand 0 acacia_boat

#

you just have to use a command

ember moat
#

Forcefully

novel elk
#

or some script

ember moat
#

Either that command or setting it in the offhand slot using this

novel elk
#

yeah

grim igloo
ember moat
#
import { world, system, EquipmentSlot, ItemStack } from "@minecraft/server";

system.runInterval(() => {
    for (const player of world.getPlayers()) {
        player.getComponent("equippable").setEquipment(EquipmentSlot.Offhand, new ItemStack('minecraft:diamond'));
    }
});```
grim igloo
ember moat
#

Show me your code

burnt vortexBOT
#
Debug Result

There is an error in this [code](#1248363987121213490 message):

<repl>.js:5:43 - error TS2551: Property 'setEquipmentSlot' does not exist on type 'EntityEquippableComponent'. Did you mean 'getEquipmentSlot'?

5         player.getComponent("equippable").setEquipmentSlot(EquipmentSlot.Offhand, new ItemStack('minecraft:diamond'));
                                            ~~~~~~~~~~~~~~~~

  @minecraft/server.d.ts:6856:5
    6856     getEquipmentSlot(equipmentSlot: EquipmentSlot): ContainerSlot;
             ~~~~~~~~~~~~~~~~
    'getEquipmentSlot' is declared here.

grim igloo
#
import { world, system, EquipmentSlot, ItemStack } from "@minecraft/server";

system.runInterval(() => {
    for (const player of world.getPlayers()) {
        player.getComponent("equippable").setEquipmentSlot(EquipmentSlot.Offhand, new ItemStack('minecraft:diamond'));
    }
});```
ember moat
#

Ah

ember moat
#

I had an extra "Slot" at the setEquipment so it threw an error but now it should work fine

novel elk
#
import { world, system, EquipmentSlot, EntityComponentTypes, EntityEquippableComponent, Player, ChatSendBeforeEvent } from "@minecraft/server";

world.beforeEvents.chatSend.subscribe((eventData: ChatSendBeforeEvent): void => {
  const { sender: player, message } = eventData;

  if (message.toLowerCase().trimEnd() != "!swap") return;
  eventData.cancel = true;

  const equippableComponent: EntityEquippableComponent = player.getComponent(EntityComponentTypes.Equippable);

  system.run((): void => {
    equippableComponent.setEquipment(EquipmentSlot.Offhand, equippableComponent.getEquipment(EquipmentSlot.Mainhand);
  });
});
ember moat
#

I'm not sure bro uses typescript

novel elk
#

he is using

#

player: Player

ember moat
#

Right

#

Thing is

burnt vortexBOT
#
Debug Result

JavaScript/TypeScript code blocks not detected in [message](#1248363987121213490 message).
You can either send the script in code block highlighted in JS format:

​`​`​`js
world.sendMessage("Hello World");
​`​`​`

Or Send an attachment end in .js to debug the file.

ember moat
#

He probably copied the example on the docs which is ts

#

Yeah

grim igloo
#

Typescript?

ember moat
#

Told you, he isnt using ts

burnt vortexBOT
grim igloo
novel elk
#

lmao

grim igloo
ember moat
#

Use the command then

novel elk
#
import { world, system } from "@minecraft/server";

world.beforeEvents.chatSend.subscribe((eventData) => {
  const { sender: player, message } = eventData;

  if (message.toLowerCase().trimEnd() != "!swap") return;
  eventData.cancel = true;

  const equippableComponent Ent = player.getComponent("equippable");

  system.run(() => {
    equippableComponent.setEquipment("offhand", equippableComponent.getEquipment("mainhand");
  });
});
ember moat
#

Still ts in the equippable part

grim igloo
#

Yes

grave orchid
grim igloo
#

you finally arrived

#

lol

grave orchid
#

Equippable only sets items that can be put without commands.... Like Shields

ember moat
#
import { world, system } from "@minecraft/server";

system.runInterval(() => {
    for (const player of world.getPlayers()) {
       player.runCommandAsync('replaceitem entity @s slot.weapon.offhand 0 diamond');
    }
});```
grave orchid
grim igloo
#

lol

ember moat
grim igloo
grave orchid
ember moat
#

Why put it there?

grave orchid
ember moat
#

Yeah ik, but why put it there

#

It wont work?

#

Instead put the chestplate in the head

grim igloo
#

Minecraft should add it in update idk why they did not in bedrock

grave orchid
ember moat
#

And the elytra in the chestplate

grave orchid
ember moat
#

Ik, I'm just saying

grim igloo
ember moat
#

Cuz if u put the elytra in the head slot it wont let u glide but if u put chestplate there, it will protect you

#

Also something funny i found out

#

You can have 2 chestplates

grave orchid
ember moat
#

And it actually stacks the protection

grave orchid
grim igloo
#

I gtg thanks @grave orchid @ember moat@novel elk for help

ember moat
#

You're welcome

grave orchid
grim igloo
#

@grave orchid I had a question that popular servers how they can use / in their custom commands like same as minecraft original one

ember moat
#

Bds

#

Bedrock dedicated server

#

Scripts using it

grim igloo
ember moat
grim igloo
#

oh

ember moat
#

Anyway have fun ima go work on my scripts cya

grave orchid
#

Oof

#

Hive server use custom software lol