Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

LiquidBounce Forum

  1. Home
  2. ScriptAPI
  3. [Help Needed] Get player slot

[Help Needed] Get player slot

Scheduled Pinned Locked Moved Solved ScriptAPI
5 Posts 2 Posters 524 Views 1 Watching
  • 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 ManP Offline
    Plumer ManP Offline
    Plumer Man
    wrote on last edited by Plumer Man
    #1
    /// 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 ManP 1 Reply Last reply
    0
    • Ali00035A Ali00035

      @plumer-man Does the script show up?

      Plumer ManP Offline
      Plumer ManP Offline
      Plumer Man
      wrote on last edited by Plumer Man
      #4

      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
      0
      • Plumer ManP 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 ManP Offline
        Plumer ManP Offline
        Plumer Man
        wrote on last edited by
        #2

        please help 😭

        Ali00035A 1 Reply Last reply
        0
        • Plumer ManP Plumer Man

          please help 😭

          Ali00035A Offline
          Ali00035A Offline
          Ali00035
          wrote on last edited by
          #3

          @plumer-man Does the script show up?

          Plumer ManP 2 Replies Last reply
          0
          • Ali00035A Ali00035

            @plumer-man Does the script show up?

            Plumer ManP Offline
            Plumer ManP Offline
            Plumer Man
            wrote on last edited by Plumer Man
            #4

            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
            0
            • Ali00035A Ali00035

              @plumer-man Does the script show up?

              Plumer ManP Offline
              Plumer ManP Offline
              Plumer Man
              wrote on last edited by
              #5
              This post is deleted!
              1 Reply Last reply
              0
              • Plumer ManP Plumer Man has marked this topic as solved on
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              About
              • Terms of Service
              • Privacy Policy
              • Status
              • Contact Us
              Downloads
              • Releases
              • Source code
              • License
              Docs
              • Tutorials
              • CustomHUD
              • AutoSettings
              • ScriptAPI
              Community
              • Forum
              • Guilded
              • YouTube
              • Twitter
              • D.Tube
              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups