#detecting double sneak while on 8th hotbar slot✅

1 messages · Page 1 of 1 (latest)

shy dome
#

My goal is to give the tag maxed to the player when they're on the 8th hotbar slot and double-sneak(double-sneak meaning crouching 2 times in a row very fast). Is this possible with script?

chilly iron
#
import {
    system,
    world
} from "@minecraft/server";

const playerMemory = {};

system.runInterval(() => {
    world.getPlayers().forEach((player) => {

        const SlotIndex = player.selectedSlotIndex;

        const {
            isSneaking
        } = player;
        playerMemory[player.id] ??= {};
        if (isSneaking) {
            if (!playerMemory[player.id].wasSneaking) {
                playerMemory[player.id].wasSneaking = true;
                playerMemory[player.id].sneaks ??= 0;
                playerMemory[player.id].ticks = 0;
                playerMemory[player.id].sneaks++;
            }
        } else {
            playerMemory[player.id].wasSneaking = false;
            playerMemory[player.id].ticks ??= 0;
            // change the detection speed here
            if (playerMemory[player.id].ticks++ > 4) {

                // here executes when double sneak && 8 slot
                if (playerMemory[player.id].sneaks === 2 && SlotIndex === 7) {
                    playerMemory[player.id].sneaks = 0;
                    console.warn(`You Double Sneak and won the "maxed" tag!`);
                    player.addTag("maxed");
                }
                playerMemory[player.id].ticks = 0;
                playerMemory[player.id].sneaks = 0;
            }
        }
    });
});```
#

@shy dome

shy dome
shy dome
#

am i doing something wrong?

chilly iron
#

What are you doing? Have you correctly defined the classes? How did you put the script together? What's your version? Console log errors? Did you put it in the right folder?

#

oh, and also make sure you are in the right slot when you run it lol, I made it so that the code would only run if you were in the penultimate slot (8th)

#

@shy dome

shy dome
chilly iron
#

anyway, are your scripts defined in your manifest?

shy dome
#

my min engine version:
"min_engine_version": [
1,
21,
0

],
"capabilities": [
    "script_eval"
],
"dependencies": [
    {
        "uuid": "6b49b646-4ad6-4337-988a-3ef6c6dfb92c",
        "version": [
            1,
            0,
            0
        ]
    },
    {
        "module_name": "@minecraft/server",
        "version": "1.14.0-beta"
    },
    {
        "module_name": "@minecraft/server-ui",
        "version": "1.3.0-beta"
    }
]

}

this is in my manifest aswell
"description": "Script that implements basic starter tests.",
"type": "script",
"language": "javascript",
"uuid": "1A1B53FC-5653-4A75-91B7-9CDF027674AE",
"version": [
1,
0,
0
],
"entry": "scripts/StarterTests.js"
}
],

#

@chilly iron

#

scripts/StarterTests.js is also the script where i put your code in

oblique echoBOT
#

Latest NPM Types

npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]

Beta APIs NPM Types

npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]

Preview Latest NPM Types

npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]

Preview Beta APIs NPM Types

npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
chilly iron
#

This version is in beta preview, unless you are in the beta version

chilly iron
shy dome
#

still doesn't work for me

chilly iron
#

Can you send me your manifest file and the file where you put my code?

#

@shy dome

shy dome
#

heres my manifest:

#

{
"format_version": 2,
"metadata": {
"authors": [
"Me"
],
"generated_with": {
"bridge": [
"2.7.24"
],
"dash": [
"github:bridge-core/dash-compiler#8fa35c73292f6382747d0f411fca26431a6d2c8e"
]
}
},
"header": {
"name": "MyAddon",
"description": "Addon",
"min_engine_version": [
1,
21,
0
],
"uuid": " some code ",
"version": [
1,
0,
0
]
},
"modules": [
{
"type": "data",
"uuid": " some code ",
"version": [
1,
0,
0
]
},
{
"description": "Script that implements basic starter tests.",
"type": "script",
"language": "javascript",
"uuid": "1A1B53FC-5653-4A75-91B7-9CDF027674AE",
"version": [
1,
0,
0
],
"entry": "scripts/StarterTests.js"
}
],
"capabilities": [
"script_eval"
],
"dependencies": [
{
"uuid": "6b49b646-4ad6-4337-988a-3ef6c6dfb92c",
"version": [
1,
0,
0
]
},
{
"module_name": "@minecraft/server",
"version": "1.12.0-beta"
},
{
"module_name": "@minecraft/server-ui",
"version": "1.2.0-beta"
}
]
}

#

edited some stuff out

#

and inside my scripts folder inside my bridge is:

#

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

const playerMemory = {};

system.runInterval(() => {
world.getPlayers().forEach((player) => {

    const SlotIndex = player.selectedSlotIndex;

    const {
        isSneaking
    } = player;
    playerMemory[player.id] ??= {};
    if (isSneaking) {
        if (!playerMemory[player.id].wasSneaking) {
            playerMemory[player.id].wasSneaking = true;
            playerMemory[player.id].sneaks ??= 0;
            playerMemory[player.id].ticks = 0;
            playerMemory[player.id].sneaks++;
        }
    } else {
        playerMemory[player.id].wasSneaking = false;
        playerMemory[player.id].ticks ??= 0;
        // change the detection speed here
        if (playerMemory[player.id].ticks++ > 4) {

            // here executes when double sneak && 8 slot
            if (playerMemory[player.id].sneaks === 2 && SlotIndex === 7) {
                playerMemory[player.id].sneaks = 0;
                console.warn(`You Double Sneak and won the "maxed" tag!`);
                player.addTag("maxed");
            }
            playerMemory[player.id].ticks = 0;
            playerMemory[player.id].sneaks = 0;
        }
    }
});

});

shy dome
#

@chilly iron ik not a file but what is inside the files

chilly iron
chilly iron
#

try adding

console.warn(`Test`);```
 at the begin, if this message appears then the problem is my code
shy dome
#

pls excuse if this sounds ridiculous

chilly iron
#

You activate it in the settings, in the creator option

#

theres a command block as a icon

shy dome
#

K

#

bc I haven‘t seen anything before

#

In-Game

lime oriole
shy dome
lime oriole
#

Dang

shy dome
#

wait wtf

#

for some reason now it still worked

#

but for some reason it only worked once

#

@chilly iron

#

yeah seems like it only worked for that one single time,

#

which is really really weird

chilly iron
#

idk, maybe you need a new manifest or it's something i'm not realizing

shy dome
#

what the f does this mean ? @chilly iron

chilly iron
#

cuz it means that the script is slow

#

anyways ill make a new manifest for ya

#

@shy dome

{
    "format_version": 2,
    "header": {
        "name": "§lAddon",
        "description": "try this with the scripts",
        "uuid": "0ae2622b-ba91-472a-999c-eb56f7c26a81",
        "version": [1, 0, 0],
        "min_engine_version": [1, 21, 0]
    },
    "modules": [
        {
            "type": "data",
            "uuid": "8a1a4c02-5a62-4a3a-b13e-437a06745b79",
            "version": [1, 0, 0]
        },
        {
            "type": "script",
            "language": "javascript",
            "uuid": "032ebfac-6030-408d-bd3e-9c8fcc15d6ba",
            "version": [1, 0, 0],
            "entry": "StarterTests.js"
        }
    ],
    "dependencies": [
        {
            "module_name": "@minecraft/server",
            "version": "1.12.0-beta"
        },
        {
            "module_name": "@minecraft/server-ui",
            "version": "1.2.0-beta"
        }
    ]
}```
shy dome
chilly iron
#

and wrote more directly

shy dome
#

and nothing bad will happen if i change it right?

chilly iron
chilly iron
#

if so, you'll just change it

chilly iron
shy dome
#

well tbh, it wasn't even my own manifest in the first place, just copy pasted it from someones addon bc i didn't know how to make one, lmao

shy dome
#

@chilly iron

#

okay, okay

#

no

#

something is severely wrong here

#

"this pack is missing 1 or more dependencies"

chilly iron
#

why youre in initial screen

#

😭

shy dome
#

and the Test came up again 😃

chilly iron
shy dome
#

yeah

#

nothing happened

chilly iron
#

I even forgot to say, it has to be very quick

chilly iron
shy dome
shy dome
chilly iron
chilly iron
shy dome
shy dome
#

?

#

@chilly iron

#

still doesn't work

chilly iron
#

hold on

#

@shy dome im getting crazy

chilly iron
#

btw i got jumpscared by an armor stand

shy dome
#

wtf

#

hmmm, maybe your script only works on PE?

#

@chilly iron

#

i tested on pc

chilly iron
#

but maybe, who knows

shy dome
#

So, I also tested it in PE and again only worked once for some reason

timid zephyr
#

then it must be a maniferst issue?

#

PC and PE is same

#

no way it would show different results

shy dome
#

what the actual f.,..

#

earlier today i reverted my manifest to the old one and now the script works?!

#

have tested multiple times in multiple worlds and it seems to work..

#

the only thing i need now really is to set the scoreboard hotbar to whichever hotbar slot i'm on and a script that removes maxed when dsneaking while having maxed tag

#

but thank you really much @chilly iron , even if it hadn't worked the fact that you gave so much of your time and attention to this makes me really greatful and i hope i can help you someday too

#

🥹

chilly iron
chilly iron
shy dome
#

Really, thanks a lot!

chilly iron
shy dome
#

I already had a few ideas but can’t really code

chilly iron
#

but dm me, this forum is already full of messages and the main problem has already been resolved

chilly iron
shy dome
#

detecting double sneak while on 8th hotbar slot✅

lime oriole