#tagging from one entity to another

1 messages · Page 1 of 1 (latest)

mild lintel
#

Hello, can someone help me with a script? I'm trying to write a script that does the following:

  1. Test for event
  2. Summon entity2 at entity1
  3. Take all tags from entity1 and give them to entity2
  4. Transform entity1 into entity3
  5. Take all tags from entity2 and give them to entity3
  6. Despawn entity 2.

Does anyone know how to do this? My friend and I have been trying for a while and we just can't figure it out.

slim sapphire
#

Test for event?

mild lintel
#

I'm wanting to run the script when an event happens but before the transformation occurs, if that makes sense.

blissful hazel
#

what kind of event?

mild lintel
#

I'm thinking I might have to do a second event for it to work.
But the original idea was to run the transformation event, then save the @s tag and summon an entity (we'll call it entity2) and give those tags to it, then allow the transformation from the event to occur on @s, then take the tags from entity2 and give them to @s now that the transformation had occurred.

#

Basically, I'm trying to save given tags across transformations.

mild lintel
#

After some thinking, I may keep this idea as an option, but I'm going to keep learning how to script it to where tags will just go from the previous entity to the new entity without any middleman.
If it doesn't work out, it's back to the drawing board.

#

Here's what I've got so far:

#
function EntityTransformer() {
    this.previousEntities = new Map();
    this.currentEntities = new Map();
}

EntityTransformer.prototype.updateEntities = function(entities) {
    this.currentEntities.clear();
    entities.forEach(entity => this.currentEntities.set(entity.id, { ...entity }));
    this.detectTransformations();
    this.previousEntities = new Map(this.currentEntities);
};

EntityTransformer.prototype.detectTransformations = function() {
    this.currentEntities.forEach((currentEntity, id) => {
        const previousEntity = this.previousEntities.get(id);
        if (previousEntity && previousEntity.type !== currentEntity.type) {
            this.transferTags(previousEntity, currentEntity);
        }
    });
};

EntityTransformer.prototype.transferTags = function(previousEntity, currentEntity) {
    const combinedTags = new Set([...previousEntity.tags, ...currentEntity.tags]);
    currentEntity.tags = [...combinedTags];
};

EntityTransformer.prototype.getCurrentEntities = function() {
    return this.currentEntities;
};

EntityTransformer.prototype.getPreviousEntities = function() {
    return this.previousEntities;
};
pliant dune
#

Use transform entity.json event