[Help Needed] Get player slot
-
/// api_version=2 var script = registerScript({ name: "BowDamage", version: "1.0.0", authors: ["PlumerMan"] }); var RotationUtils = Java.type('net.ccbluex.liquidbounce.utils.RotationUtils'); var Rotation = Java.type('net.ccbluex.liquidbounce.utils.Rotation'); var LiquidBounce = Java.type("net.ccbluex.liquidbounce.LiquidBounce"); var ItemStack = Java.type("net.minecraft.item.ItemStack"); var ItemBow = Java.type("net.minecraft.item.ItemBow"); var ItemFishingRod = Java.type("net.minecraft.item.ItemFishingRod"); var waitingForDMG = false; var ticksLeft = false; var prevSlot = -1; var sx, sz; script.registerModule({ name: "BowDamage", description: "Damages yourself", category: "Fun", settings: { mname: Setting.text({ name: "Module", default: "Fly" }), } }, function (module) { module.on("enable", function () { waitingForDMG = true; ticksLeft = 3; sx = mc.thePlayer.posX; sz = mc.thePlayer.posZ; for (x = 0; x < 9; ++x) { stack = mc.thePlayer.inventory.getStackInSlot(x); if(stack != null && stack.getItem() != null && stack.getItem() == mc.thePlayer.getHeldItem()) { prevSlot = x; Chat.print("Set slot"); } } }); module.on("disable", function () { var module = moduleManager.getModule(this.settings.mname.get()); module.state = this.state = false; prevSlot = -1; }); module.on("update", function() { Chat.print(prevSlot + " slot | " + mc.thePlayer.getHeldItem()); if(waitingForDMG) { mc.thePlayer.setPosition(sx, mc.thePlayer.posY, sz); mc.thePlayer.motionX = mc.thePlayer.motionZ = 0; } if(ticksLeft > 0) { for (x = 0; x < 9; ++x) { stack = mc.thePlayer.inventory.getStackInSlot(x); if(stack != null && stack.getItem() != null && (stack.getItem() instanceof ItemBow || stack.getItem() instanceof ItemFishingRod)) { mc.thePlayer.inventory.currentItem = x; } } mc.gameSettings.keyBindUseItem.pressed = true; RotationUtils.setTargetRotation(new Rotation(mc.thePlayer.rotationYaw, -90)) ticksLeft--; } else { RotationUtils.setTargetRotation(new Rotation(mc.thePlayer.rotationYaw, -90)) mc.gameSettings.keyBindUseItem.pressed = false; } if(waitingForDMG && mc.thePlayer.hurtTime == 9) { var module = moduleManager.getModule(this.settings.mname.get()); module.state = true; waitingForDMG = false; mc.thePlayer.currentItem = prevSlot; } }); });I tried getting the slot by using 'player.currentItem' but it returned null and the code on the onEnable event wasnt working either.
-
@plumer-man Does the script show up?
uh, this was a small brain moment. I found the issue.
mc.thePlayer.currentItem = prevSlot;this is what i did
mc.thePlayer.inventory.currentItem = prevSlot;this is what it was meant to be
-
/// api_version=2 var script = registerScript({ name: "BowDamage", version: "1.0.0", authors: ["PlumerMan"] }); var RotationUtils = Java.type('net.ccbluex.liquidbounce.utils.RotationUtils'); var Rotation = Java.type('net.ccbluex.liquidbounce.utils.Rotation'); var LiquidBounce = Java.type("net.ccbluex.liquidbounce.LiquidBounce"); var ItemStack = Java.type("net.minecraft.item.ItemStack"); var ItemBow = Java.type("net.minecraft.item.ItemBow"); var ItemFishingRod = Java.type("net.minecraft.item.ItemFishingRod"); var waitingForDMG = false; var ticksLeft = false; var prevSlot = -1; var sx, sz; script.registerModule({ name: "BowDamage", description: "Damages yourself", category: "Fun", settings: { mname: Setting.text({ name: "Module", default: "Fly" }), } }, function (module) { module.on("enable", function () { waitingForDMG = true; ticksLeft = 3; sx = mc.thePlayer.posX; sz = mc.thePlayer.posZ; for (x = 0; x < 9; ++x) { stack = mc.thePlayer.inventory.getStackInSlot(x); if(stack != null && stack.getItem() != null && stack.getItem() == mc.thePlayer.getHeldItem()) { prevSlot = x; Chat.print("Set slot"); } } }); module.on("disable", function () { var module = moduleManager.getModule(this.settings.mname.get()); module.state = this.state = false; prevSlot = -1; }); module.on("update", function() { Chat.print(prevSlot + " slot | " + mc.thePlayer.getHeldItem()); if(waitingForDMG) { mc.thePlayer.setPosition(sx, mc.thePlayer.posY, sz); mc.thePlayer.motionX = mc.thePlayer.motionZ = 0; } if(ticksLeft > 0) { for (x = 0; x < 9; ++x) { stack = mc.thePlayer.inventory.getStackInSlot(x); if(stack != null && stack.getItem() != null && (stack.getItem() instanceof ItemBow || stack.getItem() instanceof ItemFishingRod)) { mc.thePlayer.inventory.currentItem = x; } } mc.gameSettings.keyBindUseItem.pressed = true; RotationUtils.setTargetRotation(new Rotation(mc.thePlayer.rotationYaw, -90)) ticksLeft--; } else { RotationUtils.setTargetRotation(new Rotation(mc.thePlayer.rotationYaw, -90)) mc.gameSettings.keyBindUseItem.pressed = false; } if(waitingForDMG && mc.thePlayer.hurtTime == 9) { var module = moduleManager.getModule(this.settings.mname.get()); module.state = true; waitingForDMG = false; mc.thePlayer.currentItem = prevSlot; } }); });I tried getting the slot by using 'player.currentItem' but it returned null and the code on the onEnable event wasnt working either.
please help

-
please help

@plumer-man Does the script show up?
-
@plumer-man Does the script show up?
uh, this was a small brain moment. I found the issue.
mc.thePlayer.currentItem = prevSlot;this is what i did
mc.thePlayer.inventory.currentItem = prevSlot;this is what it was meant to be
-
@plumer-man Does the script show up?
This post is deleted! -
P Plumer Man has marked this topic as solved on
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login