#Script API General
1 messages · Page 140 of 1
i guess its a slightly inconvenient way to do rawmessage 
I WEAR BIG ASS GLASSES
its a bit weird
Is there a way to summon fireworks? the ones that explode with colors
How can I detect when an armor stand loads with the world so I can run a function on it?
entityLoad?
i tried player.extinguishFire when lightning bolt strikes but seems like i have to delay it a little bit just to extinguish. i tried also to use entityHurt before event but still player kept burning when near the lightning bolt. is there a way to be completely immune by it
Lightning has its own damage type, so you can detect that with before Hurt and apply fire resistance for a few ticks
Or you can detect lightning spawning using entity Spawn and if the location is within the player's range, you just give the player fire res
ight thanks
Huh
Does that "for" method work again?
for (i in var) {
//Output
}
is there a way to list all dynamic properties/iterate through them?
"Work again" ?
As in, I forgot how the syntax goes
player.getDynamicPropertyIds().forEach((id) => {
const value = player.getDynamicProperty(id);
});```
I'm trying to apply some default values on world load
there isnt a direct way but you can get an array of DP ids with .getDynamicPropertyIds()
and then
oh efficient was faster
That's why they call me "efficient".
i also was about to make that joke too
lol.
you really are efficient
thanks
There are a few variants of for loops.
You have the C-style for loop, which executes a series of statements:
for (initialization; condition; per-update expression) {
// ... Loop body
}
for (let i = 0; i < 5; ++i) {
console.warn(i);
}
You have the for..in loop, which iterates over the enumerable properties in an object:
const foo = {
a: 1,
b: 2,
};
for (const key in foo) {
console.warn(key, foo[key]);
}
You have the for..of loop, which follows the iteration protocol and is generally far more flexible:
const data = new Map([
["hi", 1],
["there", 2],
]);
// data is a Map; Map implements the iterator protocol
// datum takes on a tuple of [key, value]
for (const datum of data) {
console.warn(datum[0], datum[1]);
}
Which do you think makes the most sense for assigning default values before they are used?
Can you provide an example of how that'd play into a for-loop?
Do you know Lua? Cause I can probably do direct translation
Kind of a vague question but as a vague answer: C style for loop. It gives you the most control.
I don't know Lua, but I can probably piece together what the effect is
for i,v in ipairs[#var] do
setDynamicProperty("v.property", defaultVal)
end
I'm quite a bit rusty
So apologies there
what is that
basic Lua
ew
I used it as an example as I don't know the js equivalent yet
what does it do
Loop through all of an array and assigns each a value
Trying to do a set default thing
trying to write this tells me im still a beginner lol
you can access any value at array[i] and you can increment i
Specific usecase here is giving very player a default value for several properties
oh i see so you want to set properties for every player
the array being a list of players
and you have a second array of objects to set properties and values?
Most of them will be the same
default attack bonus = 0
default parry limit = 2
Etc.
one sec
allPlayers.forEach(player => {
player.setdynamicproperty....
})```
this is what i use in a custom party system
Installation for @minecraft/server
Latest API module install:
npm i @minecraft/[email protected]
Beta API module install:
npm i @minecraft/[email protected]
Preview API module install:
npm i @minecraft/[email protected]
Preview Beta API module install:
npm i @minecraft/[email protected]
is the i the index, and v the corresponding value?
it'd be like
Yeah
can I access a furnace's inventory using scripts?
const container = getBlock(vector3).getComponent("inventory").container;
would this work?
You could always ✨ check to see if it works ✨
On a serious note, it should, but the point above still stands 🙃
yeah real
Relevant URL: https://tryitands.ee
Love seeing this
Gonna pin the link to my clipboard
Also, Is the velocity that projectiles are shot at with the projectile.shoot() method measured in seconds or ticks?
Pretty sure its the same as what entities use.
I checked one of the sites with the documentation, and it didn't even tell me 😭
I was originally going to ask this in #1067869022273667152 but came here since I was going to shoot it with scripts anyways
I suspect it is blocks/tick, like applyImpulse
Wait, applyImpulse is blocks per tick?
Been wondering for like, a year plus
I sure hope it is. Otherwise I have made some very incorrect assumptions
Loll
Anyone know of a plugin in vscode for bedrock scripting?
Do you mean autocompletions? If yes, you just need to install nodejs and then in your project install the modules with npm
my bad
It is blocks/tick. I couldn't find it in any documentation but a few experiments can easily tell you that.
Installation for @minecraft/server
Latest API module install:
npm i @minecraft/[email protected]
Beta API module install:
npm i @minecraft/[email protected]
Preview API module install:
npm i @minecraft/[email protected]
Preview Beta API module install:
npm i @minecraft/[email protected]
Anything cool made with custom dimensions? 👀
Isn't it only in preview
not much we can do yet but if you gave this more time it would generate a psudeo biome thing
The latest update added it to the current beta API
Noice
I'm still waiting for it to be stable
Can you not force typing with Js
I think what I was trying to do is a typescript thing but It would be nice to do in Js too
figured out why my former was broken but pretty sure I can't assign types strictly
No, JavaScript doesn't know about types - only TypeScript does.
Also, is there a reason why you're taking pictures instead of pasting it into a codeblock? I've had a look at your previous messages, and I did see that you were taking pictures because your PC doesn't have Wi-Fi - is that still the case?
Nice, Im just curious how people are gonna generate chunks
Still doesnt
Atp I don't see a reason to upgrade my PC until the release of the steam machine which will likely replace it for the most part anyways due to existence of desktop mode
How would I grab the product of all player's velocity?
because unless XYZ are all 0 that means players are moving
oh boi
I'm confused as to what you're asking here. By all players, do you mean all of the XYZ velocity components of one player, or every single player?
Of 1
the code is tempting me to edit, sadly it's a pic;-;
Trust me I wish I could send normally
But it's way too tedious
Can you pick out the error cause content log is going crazy.
Something about not a function at line 18
There isn't even a function at line 18
Slightly difficult to do when the line numbers are cut out of the picture. From what I do see, you have PLAYERS assigned to a function, not the function's output.
const PLAYERS = world.getAllPlayers --> const PLAYERS = world.getAllPlayers()
in script-api, never put the methods in variables```js
const getPlayers = world.getAllPlayers //bad habit with variables, unless advanced
const players = world.getAllPlayers() //practice this often
```
since most methods are bound to their instance, calling such methods would throw bound errors
Should I just change all instances of PLAYERS to the value and forgo defining it?
use it inside the function
I don't expect it to work instantly as I have a placeholder for something I don't know how works yet
i'd still suggest ```js
system.runInterval(() => {
for (const player of world.getAllPlayers()) {
}
});```
Can you not call functions inside a class?
can
Alternatively, if there isn't anything that needs to run immediately in that file, you could delay importing that file:
system.run(() => {
import './scriptFile.js'
})
u can call any function anywhere
oh, that
Would I be correct to assume that you can't install TypeScript, and the API typings, due to the PC not having Wi-Fi?
class RaceHandler {
static races = new Map()
constructor(name, stats) {}
rollRace(player) {}
}
const race = new RaceHandler("test", {});
race.rollRace(player)
RaceHandler.races
//@ts-check would be an option
the static part is where the class' properties are, while the non-static ones are in its instance
if u downloaded em, they should work regardless of internet
Im still tryna figure out why I can't grab the player's nametag
r u sure the players array has players?
There's player.name, and player.nameTag. nameTag is the more general one for entities, and name is the actual username.
o k, i need u to install this extension
Now I just need the product of the player's velocity to test if it's non-zero
It's also a string already. You don't need to call toString() on it.
I already have it
I like to be safe
I don't use that much
i use this with it
Also player.getVelocity() returns an object with 3 vectors right?
Is there a shorthand to multiply them all together?
other than custom functions or commons lib, no
The function signature is getVelocity(): Vector3
Vector3 is just a plain JavaScript object - there are no methods for it.
There is a helper library by the development team - you'll need to bundle it if you want to use it though: https://www.npmjs.com/package/@minecraft/math
Safe is one thing but unnecessary calls eventually becomes a performance problem as your code expands.
I'll clean through it later
I've ran into a problem
multiplying all the values together does nothing because as long as 1 is 0 that'll become 0
11 x 3 x 0 = 0
I can't divide because uh.. well you try telling a computer to divide by 0
What exactly is it that you're trying to do with the velocity? By product, do you mean magnitude?
Trying to check for the first instance of a player moving
I've noticed if I do stuff like player spawn that people won't get to see what race they got assigned because they're still loading in
Math hypot
👀
If there was a version that didn't rely on velocity I would use it
You basically are checking for afk status
😨 😨 I'll let you handle the maths! I don't want anymore nightmares!
I only need to do it once
Is there not an event for after the player spawned and loaded in?
dw, im just copy pasting stuff 
There is but they aren't always loaded.
It's just to say
"HEY! it seems this is your first time here, let's roll your race and see what you got!"
Could do a server.runTimeout(()=>{}, 600)
Im doing an origins-inspired addon
so it waits
What if they're really laggy?
For first time, the player spawn event might be pretty useful, as you can check if it's the first spawn: https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/playerspawnafterevent#initialspawn
Yeah, but someone said that it can still fire even when someone isn't fully loaded
Im aware of this but player spawn happens before you're fully loaded in iirc
Like their character could spawn in game, but they might be seeing the loading screen still
||spam 1 form show||
But, you should just be able to do a timeout
This is the exact issue I'm trying to combat
As characters finishing spawning usually occurs not long before the loading is complete, no?
1 thing I know can't happen before they get initialised is they gain velocity
When I had a server, I ended up going with the alternate route of having an NPC greet players. Plus this was more memorable.
Just gonna run on first move
Also, do this
Have a form show on their screen that they can just click away when they've read it
Just feels clunky
It seems like the simplest solution
And the best atm
It will remove away from your issue of players still loading
So would a vel check
I still don't know why my function is saying its not a function
should I just not use classes?
Which part is it?
I haven't returned anything yet cause I'm still trying to figure that part out but I'm just doing raceHandler.rollRace(player)
What line exactly is the error coming up on?
Not a function
Oh, it's because that's an instance method. You need to create the raceHandler first.
they’re probably going to need to add a built in generator, a way for us to modify it too
Can you translate to English?
This is literally my first time using classes
This message describes it well
I have to create a map now???
Honestly might just go back to basic functions
If the aesthetics of the code come at this level of tediousness
-# Perhaps not 😨
You just need to create the raceHandler before calling rollRace on it:
Something like
const race = new raceHandler("name", {})
race.rollRace(val)
Order issue?
imagine the class as a template
Same thing as running a Lua function before it's initialised in code
Dragging my class to the top means it'll be created first?
doesnt matter
class is available/reachable same as functions
I could put my import at the end of the file and it would still work
Not too sure about that, as I've never tried. Do tell me if it does work if you do end up testing that.
if ur not using any related properties (e.g. name, stats) in the rollrace, put```js
static rollRace(player)
then ur code should work as u want em
I think I'll go back to functions.. classes are confusing as hell
The tutorial I watched mentioned nothing about this
Besides are classes even needed for anything when nested functions exist?
Just seems like complexity for the sake of complexity
for shared properties, it is very usueful
OOP is useful in certain scenarios.
Good for saving data, and for bigger projects. I use them a lot for when data needs to persist. Have a look at my GitHub profile and go through some of the projects there if you're interested.
its a lot to take with such object specifics
I just don't understand why if I create a class I now have to call it in 7 different locations before I can use it, instead of just doing
class.function
class.function would need class{static function(){}}
Lua habits yet again I guess
?
You can instantiate the class then export it and use it in other places as needed. Just have to decide if you want one instance or multiple instances and make sure the class handles that accordingly.
You can make your constructor private
I guess classes just do something different than I originally thought
If it just hosts static methods
I thought they were just like bigger functions
Entities and players are considered classes in the API, as well as the events. There can be several instances of each.
Then you can see why I thought that
Classes
» vars
» methods / functions
hence why I thought you just went down the chain
class.method(args)
For objects they are properties and methods
That's typescript. In JavaScript you would have to simulate it which goes back to what I suggested.
I guess this works?????
It'll be 2040 before I fully get this tho
my current usecase doesn't use any of the class' data
It doesn't need a name or the stats of anything
If your current usecase doesn't need classes, then it might be better to just not use them. Classes are another layer of abstraction that are supposed to make things less confusing.
You'd want to use them when you end up having too many functions, and it doesn't seem like you're at that point yet.
And do you need a class for??
I wanted to understand them better so that when they do end up being needed that I would be ready
But are they really ever needed over nested functions?
Here are some classes in WorldEdit's code, as an example: https://github.com/SIsilicon/WorldEdit-BE/blob/master/src/library/classes/playerBuilder.ts
for specific instances, yes
sample would be for every group of players
they can have same stats, but of different levels
like why can't i?
function a() {
function aDerivative() {}
}
test = a.aDerivative()
another confusing stuff
Maybe this comment I made some time ago might be useful. If not then carry on. #off-topic message
It's wrong syntax I know. Im just trying to show a concept
I dont understand why you need to define a if its just one method
check the export const math on this
How is this valid? There's no constructor?
I was told every class NEEDED 1
Its not a class
Then why is it called class math {}
????????
const
optional for instantiation purposes
I was told it was mandatory
If you are referring to the export/import logic then it doesn't matter because the export logic is there if to be used in another script but since I implemented it in the same block, simulating the same script, then exporting wasn't needed there.
nop
So I can just remove my constructor then?
It only exists because I thought it needed 1
Tho I guess the usecase of the tutorial version was a lot different to what I'm trying to do here
all gud, was just pointing the "part" of ur message to be read
You still have to create an instance of the class anyway, it doesnt mather if you write constructor(){} or not
I wanna use classes as a collection of similar functions
Eg.
rollRace()
setRace()
removeRace()
getRaceInfo()
blacklistRace() // for the clearly racist
Oh god im commenting myself now....
You can do that by adding static before the function declaration.
So rollRace() would become static rollRace().
Don't worry I think I actually get it now
Classes can store variables right?
And I don't need to specify const outside a method because it would be essentially saying const race = const..
Ok I have like 2 more errors to fix but they're small syntax confusions
I want to be able to both access
RACES_T1 in and outside the method
Is that what extends does?
No
Thats an extension of a different class
It takes a class and extends it to another class. For example, Entity and Player. Player is an extended class of Entity.
Oh I forgot static
So it would be static var = []
I think?
Im understanding it more
I would avoid var. Use let or const. Var will potentially lead to problems if not used carefully.
But not fully yet
so inside a class but outside a method
I do
static const RACES_T1 = []
remove const
Oh
So inside a class I don't require these declarations?
What about for something like a luck value that needs to change each time I run a function?
static get luck(){ return Math...}
Do I embed into the function as a const?
When called: set this value and execute logic based on it
I think I'm getting closer
that works as well
And once I get 1 right I should be able to make more easier with every try
uhhh
races_t1 is not defined
so I do race.races_t1?
since my racehandler is being defined as a const called race
class raceHandler {
get luck() {
return Math.floor(Math.random() * 100)
}
rollRace(player){
const luck = this.luck;
///stuff
}
setRace(player){
const luck = this.luck;
//stuuf
}
}```
It's all working besides 1 thing
How do I grab a var from within the class but not the method into the method that is in the class
thats how instance works using this
Cannot read property x of undefined
I thought I just defined it
Wait did you mean in the method or the class?
static is different from the child instance
Wait im so confused lol
since its in static there, u can access it by raceHandler.RACES_T1
if u want em available using this in those methods
It did give the tag tho which means it returned successfully
sendMessage the luck
dw, that's part of the fun ;-;
I thought it was removeTags
as long as player is Entity, yes
It must be the fact I'm not looping through the array properly or that I'm messing with the format
"ps:races/" ->
"ps:races/human"
"ps:races/fishman"
Etc.
It's supposed to randomise it each time
Remove any potential existing ones and then roll
Ok so removeTag doesn't exist
That or my extension isn't showing me it
Wait no it's giving me all of them despite the luck thing
let race = "";
if (luck <= 70) {
race = "human";
} else if (luck <= 80) {
race = "fishman";
} else if (luck <= 90) {
race = "dunespirit";
} else {
race = "ghoul";
}
player.addTag(`ps:races/${race}`);
player.sendMessage(`Congratulations! You rolled ${race.toUpperCase()}.`);
else stuff, or it has to return after a successful addtag
Is that on jayly's?
just here
MS docs.
either via a bunch of feature rules or script based gen, or even a hybrid
will features work in custom dims?
It doesnt currently. We dont know the roadmap.
big sad
For what?
I might just do
"!ps rollRace"
Instead of dealing with command registery stuff
All the tutorials are in typescript
And there's enough differences to where I keep messing up
You would be relying on beta apis which can break and be dropped at any week.
Oh well
Theres also tons of ts to js online.
Its not that hard frankly. TS is just JS with types is all at its core.
And yet I'm still getting errors after omitting those types
Those being?
A random } that doesn't fit anywhere
Or why not just learn TS?
It's the telling me I need 1
Then you're likely omitting it incorrectly.
You just remove : + the following type
i mean, nothing is stopping you from manually placing features from scripts
true
Apparently im missing something
No errors tho
Smthn about line 65
Wanting me to close the bracket
Yeah you did it wrong.
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
Even tho it's already closed
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
Again, there are tons of TS to JS online. But at that point just learn TS.
Frankly, if you have to learn TS syntax then manually convert it in your head thats a waste.
Well I fixed half of it
And now apparently line 69 also needs a } somewhere
All this for some basic auto complete
Plus how often are they really gonna change the beforeEvents for chatSend?
I don't see why they would
How hard even is it to process chat input that it would still be in beta?
At the end of the day it's up to you whether you want to suffer now or suffer later.
This registry is going to triple my file length at the very least...
And Im not too confident with splitting my scripts into different folders yet
So suffer later then?
this is very easy i highly recommend
The funny part is I don't even know where to split it rn
Not enough content yet
i see
real i got a very basic version of what i want and i called it quits
Im making something similar to origins
But cooldown bars and all that is usually UI based
bleh
how else would you do it
I am a masochist so probably
i found it! i made this in json ui and its buggy and - it doesnt matter because it works and i love it
i wont ever touch it again JSON UI is hell
I've been wanting to redo my player UI for a long time
Going 6 years I think now
6 years for what
I custom resource pack with actual functionality
youve been thinking about making one for 6 years?
Also prob a Lua oppsie but why cannot store data like this
With multiple attempts
That ended prematurely
const RACES = {
human: 1,
fishman: 1...
}```
what are the ones for anyway
tier
I wanted to store
{ Name, tier }
yeah?
I would do this.
yeah object of arrays seems better than an array of objects
Well yeah but this is saying
human is 1
fishman is 1
...
Not
My name is human and my tier is 1
I guess you could be more verbose(at that point thats what TS is but you refuse to learn it). The code is saying there is a RACE human that has a value of 1. 1 of course being the tier.
This just outputs the entire object data rather than isolating the data I want
Are you planning on more data?
Not currently but i'd definitely prefer an easily expandable format just in case
I suppose that works
wait is this TS and JS
Wait is there even a difference?
Wait
I see it
Not sure why class test is just an empty object tho
"use strict";
class Test {}
Does ts just not have class data?
TS is the one on the left, JS is the one on the right.
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
Ah
Do I need to change what val grabs then?
Cause now it would grab the object and not the string
like can u get the names of the list entries as strings?
Yeah, it would. Though this syntax is not doing what you'd expect for assigning stuff to RACES
All I know is worked before I converted them from strings to objects
I guess I can just make an id part
{"id": value, "tier": value}
So you want an array mapping an ID to some metadata? You've got a couple of options; either a 2-length tuple or a Map object.
// Map
static RACES = new Map([
["human", {"tier": 1}],
["fishman", {"tier": 1}],
["dunespirit", {"tier": 1}],
["ghoul", {"tier": 1}],
]);
rollRace(player) {
const luck = Math.floor((Math.random() * 100));
// The callback for Map.forEach expects the first parameter to be the map value, then the map key
raceHandler.RACES.forEach((val, key) => {
world.sendMessage(`${key}: ${val}`);
}
// ...
}
Map object has other advantages, like you can use the get() method to acquire a mapped entry based on a key
Complex in what way?
A bit. Probably overkill in this scenario, since the major advantages of maps only come into play with large data sets, and here you have four entries.
But the semantics are still nice
Every Data Structure has its pros and cons.
If it builds good habits I'll try to get used to it
The other approach is an array of tuples, which is very similar:
// Tuple
static RACES = [
["human", {"tier": 1}],
["fishman", {"tier": 1}],
["dunespirit", {"tier": 1}],
["ghoul", {"tier": 1}],
];
rollRace(player) {
const luck = Math.floor((Math.random() * 100));
// The callback for Array.forEach expects the first parameter to be the array entry
// Here we're destructuring the tuple, first index into key, second index into value
raceHandler.RACES.forEach(([key, val]) => {
world.sendMessage(`${key}: ${val}`);
}
// ...
}
Now my remover isn't working
Fixed it
I assume I can't add components to entities via scripts?
Correct.
I'll need a custom breath meter then
The after/beforeEvents and such, that's detected from packets, right?
You could use properties on an entity, or dynamic properties
Are you looking for packet manipulation?
No, just remembered looking at the Debugger one time and seeing the different packet infos when doing something
I know I sound crazy but I'm trying to recreate the player attributes without player.json
What is your use-case?
does anyone know if it is possible to give individual items properties
The closest is dynamic properties.
Which only works on non stackable.
I think this is a kill system?
Why are you setting a property after the entity has been killed?
Iirc they dont reset on death?
They're removed on death because the entity no longer exists.
I thought players preserve them
Oh I missed the player check. You should still set it before killing.
It's hard to read screenshots.
And not even that, a picture of the monitor.
I wish I had a better method rn i truly do
Btw how do I read the value of a dynamic property again? Struggling with conversions
That's completely right. entity.getDynamicProperty('blah')
Here is something to consider: What is the value you receive for the first time when querying a property you have never set before?
Is it 20 or "20". How and when did you first set the property?
Well to get to show I had to toString() but the number is set
Here
It's called on an interval once and then locked once I get a certain tag
Which is also given by the interval
How do I check for a type of a value?
Im going to print it to find out whats happening
=== is the equality operator
= is for assignment
const v = 'hi';
console.log(typeof v); // 'string'

None but my property went from -1 to 16 to 17
Husks deal 3 damage
Once it went to 0 or below I should have died but didn't
Are you perchance in Creative mode?
It does not.
I think it might be due to dynamic properties not updating in real time. When you set the dynamic property, calling getDynamicProperty() won't return the same value as getDynamicProperty() - damage
That should only be for normal properties if I recall.
I never had issue with having to wait 1 tick.
It does update in real time I've got to wait 1 tick anyways due to being in beforeEvents
(I added that after cause I realized late)
Also w docs
Are you waiting a tick?
Ah, you are oki
I'll test tomorrow without the damage getting set to 0
I have a feeling it MIGHT be that
I'll fix that tomorrow but it shouldnt make a difference as they all have identical stats right now anyways
🍿 👀
btw, kill do trigger the event
import { world, system } from "@minecraft/server";
world.beforeEvents.entityHurt.subscribe(ev => {
const e = ev.hurtEntity;
if (e.typeId !== "minecraft:player" || e.getDynamicProperty("ps:pendingDeath")) return;
let max = e.getDynamicProperty("ps:healthMax") ?? 20;
let cur = (e.getDynamicProperty("ps:healthCurrent") ?? max) - ev.damage;
ev.damage = 0;
cur = Math.max(0, Math.min(cur, max));
system.run(() => e.onScreenDisplay.setActionBar(`HP ${cur}/${max}`));
if (cur === 0) {
e.setDynamicProperty("ps:pendingDeath", true);
e.setDynamicProperty("ps:healthCurrent", 0);
system.run(() => {
e.kill();
e.setDynamicProperty("ps:pendingDeath", false);
e.setDynamicProperty("ps:healthMax", 20);
e.setDynamicProperty("ps:healthCurrent", 20);
});
return;
}
e.setDynamicProperty("ps:healthCurrent", cur);
});
That's literally exactly what I was going for
Just with eventually better UI
Curious tho, why are you setting the max health?
Also does this actually work well with other health values?
I don't see a reason why it wouldn't but I also wanna see my system's flexibility in action
@distant tulip
I think I just found my replacement for modified move speed in water
I can't change the components but I can apply an impulse based on conditions
Just in case of a custom value, and to initialize it
I'm trying to figure out what is causing lag within a server I play on, so I'm debugging the add-ons that got added and recently updated
Can anbody tell me what GameDirectorEntityServer is?
Wait, is it an entity running a command?
I just don't know what type of command
Looking it up it says something about transitions?
Custom values are set when you obtain the race
please send code comments, not screenshots, my little heart is always a little hurt when I see screenshots thanku 
Sadly they cannot

This happens when a player enters the world, but I want it to only happen once, when the world is generated:
world.afterEvents.worldLoad.subscribe(() => {
})
set a dynamic property and make it return early if dynamic property is present
Installation for @minecraft/debug-utilities
Beta API module install:
npm i @minecraft/[email protected]
Preview Beta API module install:
npm i @minecraft/[email protected]
Is it possible to generate NPC dialogue? Or event to check whenever a button is clicked or dialogue skipped or anything related to the NPC menu
You can use /scriptevent in the dialogue buttons to handle them via system.afterEvents.scriptEventReceive
Also, i guess you can do something with EntityNpcComppnent, anything but generate a new scene :(
hello everyone is there anyway to bypass vanilla I-frame without using the damageSoruce as override or selfDestruct
whats your use case?
i was making for guns that have fast firing time or weapon skill that dealt damage faster than the 0.5s Iframe of the game
but since using the damageSource like those above just ignore mob armor so i want to know if there are anyway other than that
my workaround here would be to multiply the damage by 2 if it was dealt during iframes
How can you even test for if iframes are active?
although it probably doesnt go well if the final damage changes in any way, such as armor breaking
just make a script that loop damage you will clearly see that the mob not taking damage in about 0.5 sec
Ah.. forgot a timer exists
i store the current tick into a mob, and test if current tick - mob's last damaged tick is larger than (or same as) 10
i did remember some specific gun addon did somehow bypass that Iframe but i cant remember it name
also it will be much easier if i can get the armor value of the armor the mob wearing and do the damage calculation in it but there seem noway to get that kind of value for now at least
so i think i will stuck with the Iframe thingy for a while haizz
beforeEvents entityHurt could be fantastic for this, but theres a bug with iframes at this moment
yeah obviously but if only i can get the armor value that the entity is having
Temp properties & millisecond timing
10 ticks, then 🗿

You can make a file to create dialogues
Then call it using /dialogue without even interacting to the npc
As long as the entity is loaded
use system.currentTick as timestamp, not Date.now()
What happens when something both functions and errors?
You were setting it to false in same tick as you kill the player
The event will trigger while it is false
-# referring to the deleted message
Figure that out now
That make no sense, lol
But I am getting an error log of something being undefined but still applying correct logic
Share the error
Line 84
Cannot get toString() of undefined
Well it clearly can cause my actionbar is updating correctly
Well, the property is not defined, but i couldn't tell you why
Can you share the whole event
Which whole event?
nvm
Anyway the property is not defined, look into where are you settling it to undefined or not setting it at all
You mean this?
I really should make a const for this
Or I guess it would be let here
This is the first location they are set
Where are you initializing the value of the property
Right here in the above image
Make sure it actually triggers, the error shouldn't throw if it did
I did
write that line that errors in multiple lines so you know where is the error exactly
And?
I meant this
One oof the properties is throwing the error
You can't tell if they are both in the same lline
system.currentTick would sync with Iframes better since they're based on in-game tick (Both influenced by Lags or In-Game pause that reduce or halt the TPS). This way, it avoids desync when tracking iframes.
-# Since you mention "my ticks", I guess you got your own clock to measure ticks?
Date.now() would be better for tracking cooldown in real time regardless of TPS spike though.
@distant tulip so I kinda caved and took a hybrid approach with player Json + scripting
I'm trying to figure out why it sometimes doesnt apply the health boost
why
Too much stuff to keep track of
Also is there some magical restriction im missing on runCommand
It never seem to work on the first try
Always the 2nd
😂
Average JS user.
I cant seem to figure out to make this speed me up
uh
wouldnt that...
just make you go pwoosh underwater?
That's what trying to do
best to limit the speed cuz there isnt one there
But no speed seems to affect it rn
I don't know why my multiplier isn't multiplying
try printing out the values in actionbar for debugging
also, did EntityUnderwaterMovementComponent not work?
Trying to avoid hard coding a bunch of values if possible
So far I'm only using 2 health events to get anywhere between 1 and 512 hearts
uhhhhhhhhhh why
Because I plan to make programmable origins eventually
needs to be data driven
Or whatever the term is
Well yeah but I would need like 8 events and component groups which will probably already double the file length
Im not sifting though 3000 lines of code to fix 1 typo
you can divide files
I can't divide player.json
one file does this thing, one file does that thing

what
how many lines does your player.json have
Not much right now because I'm optimising
Adding that water move speed thing would double its size
. . . ?
why would it?
dude is overcomplicating everything
It's a script API thing...?
...yeah
I thought we couldn't use components??
hence this
these are what you can edit
there might be some entity components that arent attributes that you could edit, but i havent tested
Well that changes a few things now..
system.runInterval(() => {
world.getPlayers().forEach((player) => {
if(player.isSwimming){
player.getComponent('underwater_movement').setCurrentValue(0.1)
} else {
player.getComponent('underwater_movement').resetToDefaultValue()
}
})
})
I forgot I added this, thoughts on this?
I mean the source TS block, just for some people who want a quick overview of the class
ah yeah
This is all I need?
its neat but i keep overlooking it cuz of how small it is
i had to do a double take to find where the source block is at 😭
Odd, I pass number to my function and got a type conversion error?
I need to actually quit
relatable
i have a better idea actually
Interested to know
Using custom commands
You create a command that lets you handle dialogue buttons
And then run it using the dialogue buttons
I think it's good
Anybody know what this is 🥺
Maybe its from BP Animation Controller. Because that's what a can think of when the word "transition" came into my mind.
anyone know why "cannot read property 'Symbol.iterator' of undefined" is in content logs?
Can you send the code causing the error?
when Symbol.iterator appear, with my two braincells I usually associate them with something like an array. If you want to use it, you gota do for of loop, or deconstruct it [...data] so it become a proper array with its method.
-# I know there are more accurate explanation, but that's only for people who want to read the online documentations
I didn't know spread operator can be used in itirator
Since Map toArray() method doesn't exist on quick js
I used for of loop
where do you see this
Mojang's Debugger on VSC
Installation for @minecraft/server
Latest API module install:
npm i @minecraft/[email protected]
Beta API module install:
npm i @minecraft/[email protected]
Preview API module install:
npm i @minecraft/[email protected]
Preview Beta API module install:
npm i @minecraft/[email protected]
what's the best way to make a runTimeout function that repeat multiple times?
example:
system.runInterval(() => {}, 5);
system.runInterval(() => {}, 15);
I tried using a for loop, but that seems to crash the game
hmm
I wonder if runInterval is better for this?
use runInterval if you want to cancle the loop midway
yeah I'm trying it out
is there anything like that now?
yes
Guys what the min-minecraft version i must use in manifest to get detected by bridge
It should be able to support 1.26.20 but if not then try 1.26.10. If that fails then I couldn't tell you, other than that it sounds like it's outdated.
Hmmm
I am usig 1.26.0
Anyone know what could cause a triggerEvent error saying it is undefined on an entity when that entity event clearly exists?
const mimic = dimension.spawnEntity('runecraft:ore_mimic', {x: location.x + 0.5, y: location.y, z: location.z + 0.5})
.setProperty('runecraft:texture', mimicId.entityProperty)
.triggerEvent('become_hostile')```
not sure if it's some runtime issue of the enttiy just spawning or something else, but setProperty works immediately
mk, I guess chaining these together doesn't work as I thought
I think setProperty() was changing what the entity was
setProperty returns void
so dimension.spawnEntity returns Entity, setProperty is then being called on that entity wich returns undefined and then minecraft tries to call triggerEvent on undefined
Try setting property afterwards in a system.run so it happens in the next tick
Thats not the issue.
TS would solve this issue
:D
The API has tag fields in the entity; is this tag the family tag or something internal?
that's literally a tag, like tag from players
So it's not family?
I thought it was the tag that's in the mob's json file, in the case of Bedrock Sendono Family.
Not the nametags
It is
I don't understand, is it family or not?
Ah yes, I thought it might be some kind of internal tag, which would be strange because entities don't have a field called tags; the equivalent is family.
Ah wait, sorry.
I didn't test it on any entities with families
So that part I don't know
Sorry
Wait, does the player entity have a family?
If so, then it doesn't detect families
Yea
"minecraft:type_family": {
"family": [
"player"
]
}
Then ^
So, could it be something internal? I found that curious.
Is it possible to detect arrows with an effect using a script?
No its from /tag
Its nothing internal.
Does hasEffect not work?
Pretty sure getEffect works on arrows as well.
Arrow:1>
Oh you mean the items.
Translator, sorry.
So the item not the entity?
Unfortunately, no.
To my knowledge anyways. You could do it via runCommand and test every data value with hasitem.
Is it not possible to see the item's data?
That's a shame, I was creating an API that saves everything in the dynamicProperty.
I honestly don't know if it's worth doing this.
Ah yes, thank you, I was really confused, and apparently ikorbon had used it wrong. Well, thank you for the explanation.
Is it not possible to use minecraft:arrow:3?
No, because it will remain the normal arrow item.
Technically, this is the method Minecraft uses in various places to view data, but I don't know if it works in the script.
The 3 means data 3; if this happens, the script probably ignores it.
I actually did something like that, some issues of course, but I was able to save most of data from an item
Me too, I saved practically everything, except for the items that couldn't be saved, like the banner and arrows, beds, etc.
is there any difference between block.x and block.location.x ?
None at all in terms of the outcome
ah thanks
Np
Its better to use block.x as opposed to block.location, since using .location is slower
Is there a block.x?
Guys i know it is a weird question
Guys i know this is a question
You can use itemName.localizationKey
It gives the potion effect name indirectly, however, it does not include the amplifier.
Then, make a simple if (x) return y; chain.
The localization key is something like tipped_arrow.effect.{x}.
From the en_US.lang:
tipped_arrow.effect.empty=Tipped Arrow
tipped_arrow.effect.mundane=Tipped Arrow
tipped_arrow.effect.thick=Tipped Arrow
tipped_arrow.effect.awkward=Tipped Arrow
tipped_arrow.effect.nightVision=Arrow of Night Vision
tipped_arrow.effect.invisibility=Arrow of Invisibility
tipped_arrow.effect.jump=Arrow of Leaping
tipped_arrow.effect.fireResistance=Arrow of Fire Resistance
tipped_arrow.effect.moveSpeed=Arrow of Swiftness
tipped_arrow.effect.moveSlowdown=Arrow of Slowness
tipped_arrow.effect.water=Arrow of Splashing
tipped_arrow.effect.waterBreathing=Arrow of Water Breathing
tipped_arrow.effect.heal=Arrow of Healing
tipped_arrow.effect.harm=Arrow of Harming
tipped_arrow.effect.poison=Arrow of Poison
tipped_arrow.effect.regeneration=Arrow of Regeneration
tipped_arrow.effect.damageBoost=Arrow of Strength
tipped_arrow.effect.weakness=Arrow of Weakness
tipped_arrow.effect.levitation=Arrow of Levitation
tipped_arrow.effect.luck=Arrow of Luck
tipped_arrow.effect.wither=Arrow of Decay
tipped_arrow.effect.turtleMaster=Arrow of the Turtle Master
tipped_arrow.effect.slowFalling=Arrow of Slow Falling
tipped_arrow.effect.infested=Arrow of Infestation
tipped_arrow.effect.oozing=Arrow of Oozing
tipped_arrow.effect.weaving=Arrow of Weaving
tipped_arrow.effect.windCharged=Arrow of Wind Charging
So, if you want to check if an arrow is Strength:
if(itemStack.localizationKey.includes('damageBoost')) {
world.sendMessage('Strength effect');
}
Or if it is speed:
if(itemStack.localizationKey.includes('moveSpeed')) {
world.sendMessage('Speed effect');
}
why i dont see that in any docs xd when was it first released
If I wanted to make a skill tree menu would I model it via scripting?
Can i carry properties between items using “lore”?
Like holo scope for a gun
Label it in the lore and use that to carry between players using properties in player.json to be activated in rc
Unless there is another way to activate it in the rc
I hardcoded the positions in JSON UI
but it is possible to make one with dynamic positions with scripting.
it all depends if you need new skill trees and you want to code it (or commission someone)
(i thought it was json ui channel mb)
Is there a way for me to trigger the onEntity event of the customComponent block from the entity in any way I want? For example, if I interact with the entity, it triggers this event and the block receives an interact event.
Not that I know.
onEntity only triggers for entity components that have a block trigger. Such on_reach for move to block.
Maybe...the creaking/heart has a componeny that ties data, but not entirely sure. What you can do is tie a dynamic property to the entity.
The block would have to be set at as the entity's home
Then you could use execute_event_on_home_block
One message removed from a suspended account.
https://stirante.com/script/server/2.7.0/classes/WorldAfterEvents.html#playerhotbarselectedslotchange
@dense wraith
Documentation for @minecraft/server
One message removed from a suspended account.
Is there a way to forcefully close a gui that is active on a players screen?
you can close script forms https://jaylydev.github.io/scriptapi-docs/latest/classes/_minecraft_server-ui.UIManager.html#closeallforms
Is there any tool that can tell me what is the minimum API version required to run my code?
Is it possible to check if a mob has any families using a script? Or only through commands?
Documentation for @minecraft/server
Thanks
How should I go about detecting right-click and holding right-click separately, on the same item?
Have a use modifier to detect the use duration.
I think swing after event can also help
I'm currently using itemStartUse and itemStopUse to detect when right click is being held, to make a function to constantly fire
How does useDuration in itemStartUse actually work?
Does it return a value after you let go of the interact button, or does it work as the button is being held, since startUse only fires when the item is first held
Kind of? Does it still trigger for charging a bow?
That's for holding right-click
Use modifier component has a duration field (or whatevers its called). It will start counting down from there. Using that you can check if the item is being held or not.
while right-click while empty hand is detectable only by swing event in script ig
But the question is 1 item having right click and holding right click, not empty hand.
Wouldn't that only allow me to fire something after I've finished clicking
Or am I misconstruing something
What are you trying to achieve?
I want to be able to right click an item and it does something once, or hold right click and and start a runInterval that ends when I let go of interact
So:
- Right Click - Function A
- Hold Right Click - Funtion B
Bingo
I can't believe I used so many more words
Custom or Vanilla Item?
Custom
I would have itemUse to trigger A and have itemStartUse have an interval, save the run id and when itemStopUse is called, clear the run.
I've already got the itemStartUse with its interval and all
I've just been integrating a secondary function into it
Can I make itemUse not fire with itemStartUse simultaneously?
This is the ordereing, I dont think its entirely useful. In my opinion then, I would have a tick check, if the item hasnt stopped use after 2 ticks, trigger B, else trigger A.
Thank you for the help!
One question: is this list updated with each new version?
I can guess it is because the last commit was 5 days ago
if we apply a effect, like slowness to an flying arrow, will whoever who gets hit by it get the effect? Or no?
I don't think arrow can be inflicted with potion effects. Tipped arrow also doesn't really "affected" by their potion effect when shot, they only act as the "carrier" of the effect which is tied to their data itself
Is it possible to detect when a player makes a nether portal?
Item use on obsidian and detect a valid structure or wait for a nether portal block
Wasn’t itemUseOn after|before event deprecated?
Player interact with block
You could just get the block the player is looking at with regular item use in the range that the player can interact with an item
That's a better idea
But there's not just one way.
Some players make with flint steel. Others use fire charge.
Then some use speedrunning tricks like lava and wood, I'm talking about those cases.
That is true
Well
Unless you want to tick the whole world looking for a portal block, there is no way
Or just check block in player view
ngl a player.swing() would be cool
would love that
What would that do lol?
swing the player arm
Biggest use case I can think of rn is how a player either always swings their arm if a block is interactable, or never if it isnt
we need api to cover every use case tbh
if theres a thing that detects an action
there should be a thing that makes an action
like
entityHurt <-> applyDamage
are scripts ran in the same environment across multiple packs?
of course you would
need a heal method
yeah we dont have that...
maybe they forgor? or maybe they are considering it but polishing it first
Just edit the healt component.
i mean we can heal, but not in a way to detect it in entityHeal.
<->
You missed the clueless emoji.
didnt miss it
Ok. 👍
Its ass yeah, but realisticly theyre just waiting to stabilise it. They would need to add heal causes which is kind of weird.
@charred dune actually asked for that.

lol
Yes totem of undyings are a thing.
what if you cancel totem of undying from entityHeal
I dont see this in the docs, is this in beta?
i think its in preview
ah
as beta api

can we use rawtext in console.warn?
So previously totem of undying was triggering an entityHurt event with negative damage and damage type none. They changed it in recent versions to use another event but I forgot the name of it
during entityHealthChanged
-hp to 1hp
entityHeal triggers 1st
Is it possible to create a skyblock island system using custom dimensions?
player.applyDamage(3, { cause: "magic" });```
is there a better way to have the damage ignore armor?
i dont like how it says killed by magic when dead
Reduce the player's health
what is the doc for that?
Is this possible?
O i see prob wont be practical due to im making a medical mod
Ig stick with what i have atm works fine for now as a beta
yo how do dynamic properties work exactly?
i need to save objects from a custom class in a script that get created whenever a player places a block
im guessing i stringify it and store it in the world but idk if thats right
since im going to be generating these objects and multiple of them will be in the world, how would i be able to retrieve them? i cant auto generate values or something like that
like, how can i figure out the key for each object if i dont know what they are
setDynamicProperty(key, value)
