Navigation

    CCBlueX Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Solved [Help Needed] Get player slot

    ScriptAPI
    2
    5
    51
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Plumer Man
      Plumer Man last edited by Plumer Man

      /// 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.

      https://emalm.com/?v=kdTa7

      Plumer Man 1 Reply Last reply Reply Quote 0
      • Plumer Man
        Plumer Man @stolen nft last edited by Plumer Man

        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

        1 Reply Last reply Reply Quote 0
        • Plumer Man
          Plumer Man @Plumer Man last edited by

          please help 😭

          stolen nft 1 Reply Last reply Reply Quote 0
          • stolen nft
            stolen nft @Plumer Man last edited by

            @plumer-man Does the script show up?

            Plumer Man 2 Replies Last reply Reply Quote 0
            • Plumer Man
              Plumer Man @stolen nft last edited by Plumer Man

              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

              1 Reply Last reply Reply Quote 0
              • Plumer Man
                Plumer Man @stolen nft last edited by

                This post is deleted!
                1 Reply Last reply Reply Quote 0
                • Topic has been marked as solved  Plumer Man Plumer Man 
                • First post
                  Last post