#Dynamic Properties;

1 messages · Page 1 of 1 (latest)

half shale
#

making a system that will set a dynamic property for a specific entity;
after the player places a block, there's an entity that will spawn with the block, that entity will get a dynamic property number { 0 } but when the player places another block it will spawn another entity and it will get a dynamic property number { 1 };
so each time the player places a block it will set a dynamic property number to that entity, like theres 5 entities each one will have a different property number { 0, 1, 2, 3, 4 };
and when one of those entities died the property number of it will disappear;
for example, there are 6 entities and one of them despawned or has been killed, the number will go from { 0, 1, 2, 3, 4, 5 } to { 0, 1, 2, 3, 4 };

bitter frigate
half shale
#

how exactly?

bitter frigate
half shale
bitter frigate
#

getEntities() returns an array

bitter frigate
#

without using dynamic properties

#

you dont need to track for entities death or anything

#

just getEntities() and length check

half shale
#

alright, but im lost

#

idk how to track the entities tho

bitter frigate
#

whats the filter option did you use for getEntities

half shale
bitter frigate
#

thatd get EVERY entities

#

the entirety of entities

half shale
#

getEntities().filter(arrawThing)?

bitter frigate
#

no

half shale
#

im so stupid

bitter frigate
#

you can do filter by types or tags

#

its in EntityQueryOptions

#

if you want to make it track per player, you can give the entities a tag with player's id

bitter frigate
bitter frigate
half shale
bitter frigate
#

bookmark that website

#

also check that

half shale
#

first time enjoying while seeing a docs link

half shale
#

also for some reason bridge telling me it's wrong

bitter frigate
half shale
#

im literally lost, especially with a random chest pain

night pendant
#

What are you trying to do? Tracking how many specific entities are there?

half shale
#

the script will spawn an entity after placing a specific block

#

that entity will get a dynamic property of 0
after placing another block and spawning another entity, the entity will get a dynamic property of 1

#

similar to this;

playerPlaceBlock.sub(({ block }) => {
block.dimension.spawnEntity('my:entity', block.center())
const entity = block.dimension.getEntities({ type: 'my:entity' }).?```but idk how to complete it
bitter frigate
#
playerPlaceBlock.sub(({ block }) => {
    const entity = block.dimension.getEntities({ type: 'my:entity' })
    if (entity.length < 50) block.dimension.spawnEntity('my:entity', block.center())
});```
half shale
bitter frigate
#

you dont need em if you only need the amount of entities in the dimension

#

if you do want to give em tags or dp, give me a second

half shale
#

i had to give them a property or a tag for making the block system,

#

pushing the block using a piston will move up the block but not the entity, i can mske the entity pushable but it will be kicked out of the block, so i had to make a syetem that will always teleporting the entity inside the block matter how far is it

#

even teleporting the entity somehow outside the block will make it disappear without breaking the block, i had to make a system that will give the entity a property or a tag so the entity will be attached to the block,

bitter frigate
#

do you need only one tag

half shale
bitter frigate
#

now i get it

half shale
#

i mean if u place 2 of the same block, both of those entities will get the same tag and start glitching up

bitter frigate
#

ill check something

half shale
#

so i have to make a syetem that will give a different tag or property for each entity, max entities 50.

#

the only problem is im new at tags or properties things, so im always lost

bitter frigate
#

i cant find it in jayly docs

#

oh wait nvm it was because of a typo

#

ok so

#

i just found a way, and youd need dynamic property instead of tags

bitter frigate
#

you can get the location of the block and then set that for the entity's dynamic property

#

since dynamic property accepts Vector3

half shale
#

but if the block has been pushed? is it will works the same
i think so

bitter frigate
#

oh yeah thats an issue

half shale
#

entity.setDynamicProperty(block.location)?

#

nvm

#

giving a dynamic property of the block location for the entity,
entity.setDynamicProperty(${block.location}) will give the entity a dynamic property of the block location right?

rich vine
#

@half shale does each entity do something different? Or do they have the same function other than the location?

half shale
#

u dont want to put ur stuff on one of them and they randomly disappear

bitter frigate
#

this will work perfectly

half shale
#

blocks have dynamic properties?

bitter frigate
#

it doesnt oml 💀

#

mandela hit me hard

rich vine
#

You can effectively store dynamic properties for blocks using world dynamic properties with a key derived from the block location ${dimension.id}_${x}_${y}_${z}

half shale
#

the only clear way to do it is by setting a dynamic property for the entity that will be different than other entities, by putting the block location as a property name

bitter frigate
#

unless you only make it to check for matching dp and nothing else

rich vine
#

You just need to not allow the blocks to be pushed by pistons. Not sure if there's a way to do that with custom blocks

half shale
#

guys if i give the entity a dynamic property, i can teleport it into the block

#

const prop = entity.getDynamicProperty('ash')
if (prop) entity.teleport(block.center())

#

idfk

bitter frigate
#

wait

#

do you teleport it only once

half shale
#

the entity will always be teleported inside the block

#

trying to teleport it outside the block will not be a thing,
pushing it with a piston will be completely fine

rich vine
rich vine
half shale
#

lemme try to explain

#

const arrays = ["0", "1"] // the property name
placing the block will set that property name to the entity

bitter frigate
#

oh wait

#

youre using onTick

half shale
#

and some mechanics for the blocks later on

half shale
#

and the onTick script will detect the entity by its property name and teleport it inside the block

#

wait a minute

#

i should do something really really really really smart, making the block unpushablebao_foxxo_sunglasses

bitter frigate
#

java barrel moment

half shale
#

but wait

#

canceling the piston will not be a thing bec u still can push it by placing blocks in front of the piston

rich vine
#

It's an afterEvent so you can't cancel. But you can respond to it by adjusting the block location of the dynamic property.

bitter frigate
#

one thing is that its an afterevent, so it can be hard to track the world dp before the event

half shale
#

making a system that will break the block while pushing it
that sounds stupid

bitter frigate
#

you can just overwrite the world dp

half shale
#

hmm

#

making the block pushable, but the entity will die after pushing the block

#

i know thats a bug, but what else should i do?

bitter frigate
#

wait

#

cant you set permutation on block?

half shale
#

?

#

state blocks?

bitter frigate
#
    beforeOnPlayerPlace: e => {
            e.permutationToPlace = e.permutationToPlace.withState('pog:playerPlaced', true);
        },

took this from Poggy's leaves decay script

#
if (e.block.permutation.getState('pog:playerPlaced') === false) {
    e.block.setType('air');
    e.block.dimension.runCommand(`loot spawn ${loc.x} ${loc.y} ${loc.z} loot ${loottable}`);
}
bitter frigate
#

and if it isnt, allow leaves decay

bitter frigate
#

and inside the onTick, you can do a check for block permutation state's value instead of DP or tags

half shale
#

hmm

bitter frigate
#

for entities, you can use DP

half shale
#

screw it im so tired

#

for some reason i have some little pain in my chest

bitter frigate
#

get some rest first bao_bee

half shale
#

not that random hard chest pain,

#

it feels like i ate a set of mexican food

half shale
#

it feels like it is

bitter frigate
#

oof

half shale
#

dont worry, i will finish my addon even if i am dying, i am already dying thobao_ext_toldyouso

#

cya, I'll think about the script tomorrow

bitter frigate
#

rest well

half shale
#

@bitter frigate i got an idea about making block states
but that requires dynamic property for the entity

#

similar to this;
first entity will get 'E0' tag / property
second entity will get 'E1' tag / property