#Offhand?
1 messages · Page 1 of 1 (latest)
Player.getComponent("equippable").getEquipment("offhand");
I wanted to make that all items can be placed in offhand is it possible by this?
try replacing some weird items to offhand
Ok sir as you said
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
import { world, system, EquipmentSlot } from "@minecraft/server";
system.runInterval(() => {
for (const player of world.getPlayers()) {
player.getComponent("equippable").getEquipmentSlot(EquipmentSlot.Offhand);
}
});```
Literally
Use dat
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
I wanted that we can drop any item in offhand like java and after running your code it did not throw any error and I also can't put anything in my lefthand
It doesnt throw any error it works, you dont do anything with it tho
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
yes I know that
but i was asking this that is it possible by script?
/replaceitem entity @s slot.weapon.offhand 0 acacia_boat
you just have to use a command
or some script
Either that command or setting it in the offhand slot using this
yeah
Yes but I wanted that we can do like with script
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'));
}
});```
That works
Error not a function
Show me your code
There is an error in this [code](#1248363987121213490 message):
[36m<repl>.js[0m:[33m5[0m:[33m43[0m - [31merror[0m[30m TS2551: [0mProperty 'setEquipmentSlot' does not exist on type 'EntityEquippableComponent'. Did you mean 'getEquipmentSlot'?
[7m5[0m player.getComponent("equippable").setEquipmentSlot(EquipmentSlot.Offhand, new ItemStack('minecraft:diamond'));
[7m [0m [31m ~~~~~~~~~~~~~~~~[0m
[36m@minecraft/server.d.ts[0m:[33m6856[0m:[33m5[0m
[7m6856[0m getEquipmentSlot(equipmentSlot: EquipmentSlot): ContainerSlot;
[7m [0m [36m ~~~~~~~~~~~~~~~~[0m
'getEquipmentSlot' is declared here.
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'));
}
});```
Ah
I edited this
I had an extra "Slot" at the setEquipment so it threw an error but now it should work fine
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);
});
});
I'm not sure bro uses typescript
Typescript?
Told you, he isnt using ts
iM ON JS
lmao
Use this
I tired it does not allowed me to put anything in offhand
Use the command then
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");
});
});
Still ts in the equippable part
Yes
Command can only do that
Equippable only sets items that can be put without commands.... Like Shields
import { world, system } from "@minecraft/server";
system.runInterval(() => {
for (const player of world.getPlayers()) {
player.runCommandAsync('replaceitem entity @s slot.weapon.offhand 0 diamond');
}
});```
Did some rests lol
Ok I was waiting for you
lol
@grim igloo here:
Right didn't know that until now
Yes checking
Also same as putting elytra on head slot.... You can't do it... Need to use commans
Why put it there?
There's a funny bug
Minecraft should add it in update idk why they did not in bedrock
Using command you could place the elytra in head slot there but using scripts nah
And the elytra in the chestplate
Yeah ik
Obviously it would work command or scripts
Ik, I'm just saying
Ye it just putting diamond working but not as I wanted it means We cannot do it even by scripts need to create custom item and allow offhand=true sed
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
That's not what I'm trying to say tbh.... What I'm trying to say was you can't place things in armor slot and offhand like commands can
And it actually stacks the protection
That's why I said funny bug
Right.
I gtg thanks @grave orchid @ember moat@novel elk for help
You're welcome
Tbh, I didn't even help you lol....
If you ain't come we were still trying it Lol
@grave orchid I had a question that popular servers how they can use / in their custom commands like same as minecraft original one
Oh can we also create it for free or probably paid
You can use aternos or your own server if u have one
oh
Anyway have fun ima go work on my scripts cya
Cya
It's either bds as what unknown said or a custom software
Oof
Hive server use custom software lol