-
I have a target game that uses target blocks. I currently have a ticking component set to detect an arrow and run some commands. I would like to integrate the new getRedstonePower() function. My thinking is I could set the block to only run commands if the player gets a bullseye. I don't know where to start.
-
I'm going to try and make the script and change it so any target block will work as long as player has the proper tag (to keep players from standing in front of it I have a block to stand on that gives the player the tag)
#how to use new .getRedstonePower() query
1 messages · Page 1 of 1 (latest)
Heres what ive come up with,
function getRedstonePower() {
return level
}
{
if (player.has_tag == "gamer" && level == 14);
player.runCommandAsync(`event entity @p[tag=gamer,c=1] prize`)
}```
Learn Javascript!
As the Script API is a framework built on JavaScript code, having an understanding of JavaScript is key.
If you are being shown this, then you most likely are a beginner with JS and could use a little guidance.
📺 Videos on Learning JavaScript
Javascript in 1 hour
Javascript Classes in 1 hour
Web Guide:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide
Reference Sites:
https://www.w3schools.com/jsref/default.asp
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference
https://javascript.info
getRedstonePower is method on blocks u cant use it like that
I can't use it to detect if a block is powered?
u can
but ur code is not for that
plus you would need to use 2 events from what i understood
u would need to detect projectile hit then get block at its hit position then we use .getRedstonePower() on it
its fine if u dont know js or how to code, as your code is totally invalid in terms of JS and API aswell
how to use new .getRedstonePower() query
i think this title makes more sense to have
Thanks. Yeah I'm trying g to learn js but I don't have much time with work and family.
It's a slow process right now.
build ideas is great way to learn 🙂
Is their a way to detect the position of the hit position? I yried when I first made it but couldn't find anything
I learn better by studying a code and seeing how it works.
But then I don't learn all the slang and what they mean. Like boolean, object or string. I know basically what they are bit not enough to know what the code is looking for.
I thought if I just used a vanilla target I could detect the redstone power for a bullseye and run the event.
this is what u will use https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server/projectilehitevent#blockhit
import { world } from "@minecraft/server"
world.events.projectileHit.subscribe( eventData => {
const {
source,
projectile,
blockHit
} = eventData
if ( ! source.hasTag( "myTag" ) ) return;
if ( ! blockHit ) return;
const { block } = blockHit
let power = block.getRedstonePower()
if ( power != 14 ) return;
// code here when player has tag and power is 14
} )
No errors
No errors in [code](#1073257408266244156 message)
That is awesome. That makes sense to me. I really appreciate it. I think k I'm just gonna cleanup my current addon. I have alot all mixed up. Then study some js before I get to far.
But that will help out so much.
😁
I have some games I made, some weapons and items, a gui(gametest) and "legendary" mobs I made. But all of it is on one addon. I need to take the time to separate them into there own.
nice
My main hold up is learning the Scripting stuff. Im pretty good at designing and texturing custom stuff. And not to shabby at gametest (my gui is pretty extensive). But even my wife said I should learn to code.
@slate plover you have no idea how awesome that is. This was the very first thing I wanted to make. I could never get it just right. It is exactly how I intended. So freaking cool. Thanks so much. Sorry for the ping. I just wanted to thank you one more time after testing.

It will reduce my pack size since I can delete the custom target block I made and not have the function running constantly.