#import player problem
1 messages Β· Page 1 of 1 (latest)
import * as mc from "@minecraft/server"
import * as lib from '../template'
mc.world.afterEvents.entitySpawn.subscribe(({entity}) => {
if (entity.typeId === "ssak:leopard_hibachi") {
const callback = mc.world.afterEvents.projectileHit.subscribe((arg) => {
const { source, projectile } = arg;
const hitInfo = arg.getEntityHit();
if (hitInfo?.entity instanceof Player && source instanceof Player && projectile === entity) {
hitInfo.runCommandAsync("damage @s " + (lib.scoreboard.get(source, "dmg") * lib.scoreboard.get(player, "dmg_multiply") * 2) + " entity_attack entity " + player.nameTag)
mc.world.afterEvents.projectileHit.unsubscribe(callback)
}
})
}
})
Line 11
Ok
But
The log says the problem is here:
if (hitInfo?.entity instanceof Player && source instanceof Player && projectile === entity) {
whats the error
Player is not definied
you did mc.Player rigth
Ok
did it work
still not working
What now
Same mistake
Player is not Defined
import * as mc from "@minecraft/server"
import * as lib from '../template'
mc.world.afterEvents.entitySpawn.subscribe(({entity}) => {
if (entity.typeId === "ssak:leopard_hibachi") {
const callback = mc.world.afterEvents.projectileHit.subscribe((arg) => {
const { source, projectile } = arg;
const hitInfo = arg.getEntityHit();
if (hitInfo?.entity instanceof Player && source instanceof mc.Player && projectile === entity) {
hitInfo.runCommandAsync("damage @s " + (lib.scoreboard.get(source, "dmg") * lib.scoreboard.get(source, "dmg_multiply") * 2) + " entity_attack entity " + source.nameTag)
mc.world.afterEvents.projectileHit.unsubscribe(callback)
}
})
}
})
Yea
import * as mc from "@minecraft/server"
import * as lib from '../template'
mc.world.afterEvents.entitySpawn.subscribe(({entity}) => {
if (entity.typeId === "ssak:leopard_hibachi") {
const callback = mc.world.afterEvents.projectileHit.subscribe((arg) => {
const { source, projectile } = arg;
const hitInfo = arg.getEntityHit();
if (hitInfo?.entity instanceof mc.Player && source instanceof mc.Player && projectile === entity) {
hitInfo.runCommandAsync("damage @s " + (lib.scoreboard.get(source, "dmg") * lib.scoreboard.get(source, "dmg_multiply") * 2) + " entity_attack entity " + source.nameTag)
mc.world.afterEvents.projectileHit.unsubscribe(callback)
}
})
}
}) ```
did it work
oh
I need help with something else
sure
I tried to make this code work with different TypeId
But testing now, I saw that I couldn't
what were you trying to do
This here is the original code that was working normally:
mc.world.afterEvents.entitySpawn.subscribe(({ entity }) => {
if (entity.typeId !== "minecraft:arrow") return;
const callback = world.afterEvents.projectileHit.subscribe((arg) => {
const { source, projectile } = arg;
const hitInfo = arg.getEntityHit();
if (hitInfo?.entity instanceof Player && source instanceof Player && projectile === entity) {
hitInfo.runCommandAsync("damage @s " + (lib.scoreboard.get(source, "dmg") * 1) + " entity_attack entity " + player.nameTag)
world.afterEvents.projectileHit.unsubscribe(callback);
};
});
});
Basically
The TypeId identifies the projectile
I wanted for more other funcutions identifying other projectiles
But I can not
oh if the player gets hit by a arrow he gets damage
oki give me a sec
why put projectileHit in entitySpawn?
projectileHit only fires if the entity is a projectile
Long story
Think out of the box
Is it possible to combine things
trying to get the entity instance since you can't get the projectile entity using projectileHit afterEvent?
More or less
Here's my stupid idea: make an array of possible projectile IDs.
( if it's stupid, but it works, it's not stupid )
const projectiles = [
"minecraft:arrow",
"minecraft:snowball",
"minecraft:thrown_trident",
"minecraft:potion",
"minecraft:fireball"
]
//if (projectiles.includes(entity.typeId))```
would not work
Each projectile needs a unique command
switch statement
switch (entity.typeId) {
case "minecraft:arrow":
//code for arrow
break;
case "minecraft:snowball":
//code for snowball
break;
}
They are different projectiles
Let's say there are more than 50
And you want each of them to run a different commands correct?
I think minecraft updated
The script seems to have stopped working and that was out of nowhere
data.getEntityHit().entity
What?
yo @thorn grove i never used projectileHit what did i do wrong ```js
import { world, Player } from '@minecraft/server';
const database = [
['arrow', 11],
];
world.afterEvents.projectileHit.subscribe((event) => {
const { projectile } = event;
const hitEntity = event.getEntityHit()?.entity;
if (typeof hitEntity === "undefined" || !(hitEntity instanceof Player)) return;
for (const [projectileName, damageValue] of database) {
const projectileType = projectile?.typeId?.replace('minecraft:', '');
if (projectileName === projectileType) {
hitEntity.applyDamage(damageValue);
break;
}
}
}); ```
Oh my
@thorn grove
Why did you make so many changes?
;-;
;-;
what?
cus hitEntity is in immunity state?...
Why are there so many changes? π
mm idk
oh
You even removed the essence of the system π π π
can you fix the code for me im working on something eles
;-;
That command was to identify the player's score to deal damage to the entity hit
bro you are a Scripting Leader be nice
The hit is according to the player's "dmg" score
M9 will help you now i allready made i code he can fix it
ya, i do have some preferences..
That I understand
But that command cannot be withdrawn because it is the essence of the system.
I will show you
You used a scoreboard to determine the damage done by the projectile?
thats what the projectile gona do?
I basically repeated this on the projectiles, so that they have the same strength as the player...
Exactly
The projectile replicates the player's strength
ProjectileHitAfterEvent
return both the source (player who shot it) and the entity that got hit.
I think both of these are enough to replicate what you are trying to do
Like this?
projectile event have source
If this is simpler and performs the same thing it will be much better
But I don't know how to do it
Can you help me with this?
It will be something that improves the quality of my addon
i think π«
Step 1: steal borrow a function that grabs the player's score from the specified scoreboard objective.
player.runCommandAsync("damage @s " + (lib.scoreboard.get(player, "dmg") * lib.scoreboard.get(player, "dmg_multiply")) + " entity_attack entity " + player.nameTag)```
The "dmg_multiply" score is no big deal
It's just to multiply the damage whenever I want
Step 2: code
- get the player who shot the projectile
- get the entity that got hit
- get the 'player' scoreboard 'dmg'
- <idk> I have no idea what you are trying to do
I don't know how to do this
I never messed with projectilehitevent
const projectiles = {
"minecraft:arrow"(projectile, hitEntity, source) {
hitEntity.applyDamage(lib.scoreboard.get(source, "dmg") * 1, {
cause: 'entity_attack',
damagingEntity: source
})
},
"minecraft:thrown_trident"(projectile, hitEntity, source) {
}
}
world.afterEvents.projectileHit.subscribe(arg => {
const { source, projectile } = arg;
const hitInfo = arg.getEntityHit();
if (projectile.typeId in projectiles && hitInfo && source instanceof Player) {
projectiles[projectile.typeId](projectile, hitInfo.entity, source);
};
})
have a little problem
dunno if that'd even work
Each projectile has a different damage
That's why I put a multiplication in front
Yeayea
But that's not a big problem
by entities
entity.typeId ?
yea
Each entity, in addition to adding damage, multiplies it in a different way
I would be using an array and do .find()
Turns out entities have some animations
/**@type {{[typeId:string]:(a:mc.Entity,b:mc.Entity,c:mc.Player)=>any}} */
const projectiles = {
"minecraft:arrow"(projectile, hitEntity, source) {
hitEntity.applyImpulse({x:0,y:0,z:100})
hitEntity.applyDamage(lib.scoreboard.get(source, "dmg") * 1, {
cause: 'entity_attack',
damagingEntity: source
})
},
"minecraft:thrown_trident"(projectile, hitEntity, source) {
hitEntity.applyDamage(lib.scoreboard.get(source, "dmg") * 255, {
cause: 'anvil',
damagingEntity: source
})
}
}
I think I'm understanding
does the 'cause' changes?
What is this "applyimpulse"?
or you just want to change the *multiplier?
custom knockback
kind of applyKnockback
Like this?
u can do whatever in those entities there
They are special attacks, it will always be the same entities
But each player will have a different strength, so the damage given by entities will be different...
ye...
I get what you are trying to do.
playerDmg * projectileDmg
each projectile.typeId have their own methods there
No
These projectiles do the same damage that the player can currently do
projectiles[projectile.typeId](projectile, hitInfo.entity, source);
But as they are special attacks, they have multiplications to increase their power.
Why?
So basically each projectile has a dmg multiplier
Yep
That's exactly what I'm trying to show.
Forget the formula, lets try and solve this issue.
Projectiles are a way to get attacks with more range
so projectile type is just for dmg multipliers?
from my observation of this conversation, yes.
Then what is this multiplier based on?
Thanks, that doesn't help at all.
so different methods/type
These projectiles should take the player's strength and multiply
Lol
I wanted to show that projectiles shouldn't just multiply
They are cast by the player
YES, each type of projectile has a different multiplier
thats why i made that const projectiles for different methods
And when they hit the entity, they add multiplied damage
It will work?
I haven't tested it yet
I'm trying to explain the system π
it uses the player 'dmg' (which is a scoreboard) and multiplies it using the corresponding projectile multiplier dmg (that's used)
That depend on the strength of the player
The player's strength is defined by the "dmg" score
Eita
Did you understand?
What are you talking about?
All I know is this system is crazy
Not yet
But that's because I don't know how to apply what Learn Why did
make the entity|player|projectile (teleport, explode, effect, knockback,etc)
But how do I apply it in the script?
Are they not const?
wdym?
Is that
the entities are passed in the function from the hitevent
How do I make it work?
Is that, from what I understood
are const
its an object of methods
const projectiles = {
"minecraft:arrow"(projectile, hitEntity, source) {
hitEntity.applyImpulse()
hitEntity.applyDamage(lib.scoreboard.get(source, "dmg") * 1, {
cause: 'entity_attack',
damagingEntity: source
})
},
"minecraft:thrown_trident"(projectile, hitEntity, source) {
//code
},
"custom:trident"(projectile, hitEntity, source) {
//code
},
"custom:arrow"(projectile, hitEntity, source) {
//code
}
}
I thought what you did was the script for projectiles to deal player damage
AAAAAAAAA
Now I understand
How cool in
you are really smart
Lol
the applydamage might be tricky
cannot apply damage when players have iframe?
ig so
I can turn on command, can't I?
why not just, set their current health? (ignore this - bad idea)
entity is there, yea
I just put the /damage thing one more time
So in this case, will the projectile execute the player's command when hitting an entity?
I'm dying
depending on projectile typeId, yes
But which event do I put this in?
Projectilhit?
HitEntity?
its already there
Tendi foi nada mermo, rapΓ‘
;-;
No! don't kill your self!
At Least do it with styles!
If the command is there in "//code"
Why do you have this outside?
ππ
You are right
cus putting it in the event means that it'd generate that same object repeatedly
And why are the rest outside?
so it's constant...
generating an object takes performace
so making it once should be fine
it's alr, as long as youre learning
I don't know anything about minecraft scripting actually
What I know, was tinkering with some scripts around
u can see it like /function projectiles/minecraft:arrow
But I didn't even understand how to import it
Because these const are outside
Is it just me putting the "impot * as mc..."?
just paste it in the same file, so no need to import
oh u need the whole file
import * as mc from '@minecraft/server';
import * as lib from '../template'
const projectiles = {
"ssak:leopard_hibachi"(projectile, hitEntity, source) {
hitEntity.applyImpulse
hitEntity.applyDamage(lib.scoreboard.get(source, "dmg") * 1, {
cause: 'entity_attack',
damagingEntity: source
})
},
"minecraft:thrown_trident"(projectile, hitEntity, source) {
source.runCommand('say hi')
},
"custom:trident"(projectile, hitEntity, source) {
hitEntity.runCommand('say hi')
},
"custom:arrow"(projectile, hitEntity, source) {
let location = hitEntity.location
projectile.runCommand('say hi')
}
}
mc.world.afterEvents.entitySpawn.subscribe(({ entity }) => {
const type = entity.typeId
if (type in projectiles) {
const callback = mc.world.afterEvents.projectileHit.subscribe((arg) => {
mc.world.afterEvents.projectileHit.unsubscribe(callback)
const { source, projectile } = arg
const hitInfo = arg.getEntityHit()
if (hitInfo?.entity instanceof mc.Player && source instanceof mc.Player && projectile === entity) {
projectiles[type](projectile, hitInfo.entity, source)
}
})
}
})
A complete file would be of great help, young Enderman
What a crazy thing
But there in "\code"
If I needed for a function
Wouldn't I need to import?
treat it likejs mc.world.afterEvents.projectileHit.subscribe(arg => { //code })
//code is js commant
So I would have to put it inside the const?
u can remove it
uh, no
I confused the languages
I can't understand bro
If I were to make a command
How would I put a command there using one of these const?
Does not make sense
If I put the function in projectilehit, how would it identify the const?
Does not make sense
there
That doesn't make sense
The command works, even outside of an event
I didn't know this was possible
prjectilehit event triggers it
I think I understand
source is the player
so the answer is yes
Take the player's score to add the damage
did u add the ```js
import * as lib from '../template'
the others worked
cant get entity(projectile) instance in projectileHit afterEvent?
Only the one that applies the damage according to the player's score did not work
I don't know
Yeah it's because the arrow disappeared when it hit the player
That's why it's undefined (I think)
But that's not the problem
Didn't you see it in the video?
yes typeId is undefined
Damage is not added
Damage must be added according to the player's "dmg" score
This is the problem
thats because there's an error?
because typeId is undefined, it stops the other script from running?
The only error that appears is the one from the entity
use this event
mc.world.afterEvents.entitySpawn.subscribe(({ entity }) => {
const type = entity.typeId
if (type in projectiles) {
const callback = mc.world.afterEvents.projectileHit.subscribe((arg) => {
mc.world.afterEvents.projectileHit.unsubscribe(callback)
const { source, projectile } = arg
const hitInfo = arg.getEntityHit()
if (hitInfo?.entity instanceof Player && source instanceof Player && projectile === entity) {
projectiles[type](projectile, hitInfo.entity, source)
}
})
}
})
yeah
Does that work? if it does, I'm gonna yoink it.
For some reason, even having everything added to "MC"
It says it has an error in the "Player" and needs to put the "MC." Before
yea, do that. that should fix it
I don't know
But the script I used worked
However, it stopped working out of nowhere
And there was no way for other entities
Confirmation please, does the new provided script work? Does it show any errors? I hope not.
It's working, the problem is the damage is not being added...
I don't understand how
But before
mc.world.afterEvents.entitySpawn.subscribe(({ entity }) => {
if (entity.typeId !== "minecraft:arrow") return;
const callback = world.afterEvents.projectileHit.subscribe((arg) => {
const { source, projectile } = arg;
const hitInfo = arg.getEntityHit();
if (hitInfo?.entity instanceof Player && source instanceof Player && projectile === entity) {
hitInfo.runCommandAsync("damage @s " + (lib.scoreboard.get(source, "dmg") * 1) + " entity_attack entity " + player.nameTag)
world.afterEvents.projectileHit.unsubscribe(callback);
};
});
});
it worked
Show me the script you're using
did u have this
he probably didn't change the runCommand
thats why
weird
It was this:
mc.world.afterEvents.entitySpawn.subscribe(({ entity }) => {
if (entity.typeId !== "ssak:leopard_hibachi") return;
const callback = world.afterEvents.projectileHit.subscribe((arg) => {
const { source, projectile } = arg;
const hitInfo = arg.getEntityHit();
if (hitInfo?.entity instanceof Player && source instanceof Player && projectile === entity) {
hitInfo.runCommandAsync("damage @s " + (lib.scoreboard.get(source, "dmg") * 1) + " entity_attack entity " + player.nameTag)
world.afterEvents.projectileHit.unsubscribe(callback);
};
});
});
As I said at the beginning
it worked
But it stopped out of nowhere
And besides, I can't do the commands with different entities
whats the whole file
That was the entire file
import * as mc from "@minecraft/server"
import * as lib from './template'
mc.world.afterEvents.entitySpawn.subscribe(({ entity }) => {
if (entity.typeId !== "ssak:leopard_hibachi") return;
const callback = mc.world.afterEvents.projectileHit.subscribe((arg) => {
const { source, projectile } = arg;
const hitInfo = arg.getEntityHit();
if (hitInfo?.entity instanceof mc.Player && source instanceof mc.Player && projectile === entity) {
hitInfo.runCommandAsync("damage @s " + (lib.scoreboard.get(source, "dmg") * 1) + " entity_attack entity " + player.nameTag)
mc.world.afterEvents.projectileHit.unsubscribe(callback);
};
});
});
this...
ok, i will test
still not working
But another bug appeared
π« π« π« π« π« π« π«
it works fine for me tho
The problem is that damage is not added
It's like it's not identifying the player's score
cus player is in immunity state
Entity hit that should take the damage ππππ
I went into survival mode and he didn't die
The add damage system doesn't work
That is the problem
@thorn grove @slim sable
I achieved
Now the projectile consults the score of its source and executes a command when reaching its target
mc.world.afterEvents.entityHurt.subscribe(data => {
const
hurt = data.hurtEntity,
damage = data.damage,
damaging = data.damageSource.damagingProjectile;
if (damaging?.typeId != "ssak:leopard_hibachi") return;
const player= data.damageSource.damagingEntity
hurt.runCommandAsync(`damage @s ${lib.score(player, "dmg") * 2} entity_attack entity "${player.nameTag}"`)
})
nesting projectileHit in entitySpawn makes it run more than once every time it fires. (for me)
So, I think this one is better
I'm not using it
I used only damageSource variables
ok
Thank you everyone
