#Using player as damage source

41 messages · Page 1 of 1 (latest)

keen meadow
#
                                entity.attack(player,10)```
```[10:13:53] [ERROR] ! equipment.js#81: Error in 'ServerEvents.tick': Can't find method net.minecraft.world.entity.monster.Zombie.m_6469_(net.minecraft.server.level.ServerPlayer,number).
[10:13:53] [ERROR] ! …rhino.EvaluatorException: Can't find method net.minecraft.world.entity.monster.Zombie.m_6469_(net.minecraft.server.level.ServerPlayer,number). (server_scripts:equipment.js#81)```I want to damage the entity so the player gets the kill, because I am making a wand system right now. In 1.19.2 I was able to just use player, but now it doesn't work anymore
hushed quartzBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

tranquil hawk
#
entity.attack('player',10)
keen meadow
#

But then it doesn't know what player

tranquil hawk
#

that's kinda complex i think? maybe someone skilled can help

keen meadow
#

Ye, thats what I hope for

#

Thanks anyways

quaint plover
#

Would it be the player's entity ID?

(also I cannot contribute much to this conversation past this passing comment)

keen meadow
#

So you mean I should try to pass in the players id?

#

Or the uuid?

quaint plover
#

Either - is the attack function a KJS implementation, or native MC?

small inlet
#

console log this when you punch somethingjs EntityEvents.hurt(event => { console.log(event.source.getType()) })

keen meadow
#

Just [15:47:07] [INFO] equipment.js#108: player

small inlet
#

i mean i assume if its a player damage source it will automatically get the last damage source and display the message of "this player killed this"

#

maybe test 'player' out like rad suggested

#

and see if you get the player name in the death message

keen meadow
#

I mean a normal mob doesn't have a death message

small inlet
#

do a named mob then

#

or tamed

#

tamed it broadcasts

keen meadow
#
[15:49:33] [ERROR] ! equipment.js#89: Error in 'ServerEvents.tick': Can't find method net.minecraft.world.entity.monster.Zombie.m_6469_(string,number).```
small inlet
keen meadow
#

I always autopilote and format it as js

quaint plover
#

Well, so it doesn't like the method signature of (string, number) so that's cool

keen meadow
#

I mean its (Internal.DamageType,number)

small inlet
#

try this js function getDamageSource(/** @type {Internal.Level}*/ level, /** @type {Internal.DamageType_}*/ damageType) { const resourceKey = $ResourceKey.create(DAMAGE_TYPE, Utils.id(damageType)) const holder = level.registryAccess().registryOrThrow(DAMAGE_TYPE).getHolderOrThrow(resourceKey) return new DamageSource(holder) } const $ResourceKey = Java.loadClass("net.minecraft.resources.ResourceKey") const DAMAGE_TYPE = $ResourceKey.createRegistryKey("damage_type") ItemEvents.rightClicked(event => { const {player} = event // Create damage source const damageSource = getDamageSource(player.getLevel(), "player"); entity.attack(damageSource, 10) })

#

pulled from the 1.20 radiation script and dumbed down

#

i assume you dont need the lang file if we're using 'player' here

keen meadow
#
[15:54:47] [ERROR] ! equipment.js#96: Error in 'ServerEvents.tick': TypeError: Cannot call property level in object ServerPlayer['Dragonlord14545'/101, l='ServerLevel[Building world]', x=-20.44, y=0.66, z=-13.99]. It is not a function, it is "object".```
small inlet
#

do getLevel()

#

not sure why it works in the radiation script like that tbh lul

#

edited above

keen meadow
#
[15:56:01] [ERROR] ! Error in 'ServerEvents.tick': Missing key in ResourceKey[minecraft:root / minecraft:damage_type]: ResourceKey[minecraft:damage_type / minecraft:player]
[15:56:01] [ERROR] ! java.lang.IllegalStateException: Missing key in ResourceKey[minecraft:root / minecraft:damage_type]: ResourceKey[minecraft:damage_type / minecraft:player]```
small inlet
#

sec

small inlet
keen meadow
#

That works

#

Tysm

small inlet
#

??closeticket

plush heathBOT
# small inlet ??closeticket

Please close your ticket (with </ticket close:1054771505520717835> or the button atop this thread) once you resolved your issue! This also helps others that would like to help out, as they don't have to look into this thread to check if it has been resolved by now.

Do you have any other questions regarding your issue? Feel free to ask!
Note: You should generally create a new post for unrelated issues.

keen meadow
#

I am not that fast at typing