#How can I add custom death message?

1 messages · Page 1 of 1 (latest)

wise grail
#

I want to receive a custom death message after death from my entity. Is there way to do it?

toxic sage
#

You can use entityDie event

#
world.afterEvents.entityDie.subscribe(({deadEntity}) => {

if(deadEntity.typeId == "minecraft:player"){
deadEntity.sendMessage("its work")
});```
wise grail
#

ok, but how do I make the message appear when player dies from a certain entity (in my case, it's mv:zombie_pig)?

#

i don't understand scripts, but I want to get this functionality

fickle hill
#
world.afterEvents.entityDie.subscribe(({deadEntity}) => {

if(deadEntity.typeId === "mv:zombie_pig"){
deadEntity.sendMessage("its work")
});
wise grail
#

I created "scripts" folder in the BP folder, pasted this script into "z_pig_message.js" file and nothing happens. What did I forget to do?

fickle hill
wise grail
#

manifest.js or manifest.json?

#

I only have manifest.json

fickle hill
wise grail
#

Behavior Pack manifest.json:

  "format_version": 2,
  "header": {
    "description": "zombie pig addon",
    "name": "Zpig",
    "uuid": "7fbab47b-082a-4e7d-85e6-1fdc117513ba",
    "version": [
      0,
      0,
      1
    ],
    "min_engine_version": [
      1,
      17,
      0
    ]
  },
  "modules": [
    {
      "description": "zombie pig addon",
      "type": "data",
      "uuid": "7a26ccc9-29c0-40cf-8500-66bb67d9cfb3",
      "version": [
        0,
        0,
        1
      ],
      "type": "script",
            "language": "javascript",
            "entry": "scripts/main.js"
    }
  ],
  "dependencies": [
    {
      "uuid": "7452a2ed-f11d-48be-9d3b-8f5db3f68d49",
      "version": [
        0,
        0,
        1
      ]
    }
  ]
}```
#

main.js: import 'scripts/z_pig_message.js'

fickle hill
#

i wouldnt use _ in the file names

#

just maybe could cause some issues

#

also enable content log and content debug in creator in settings minecraft

#

when /reload or upon loading into world it should display code errors

#

main.js must be a file

#

and have imported the file you wanted like i showed above

wise grail
#

[Scripting][Error]-Plugin [Zpig - 0.0.1] - [main.js] ran with error: [SyntaxError: unexpected token in expression: ')' at zpigmessage.js:7]

#

this error appears when entering the world

toxic sage
#

@wise grail you want to send the message to the player When he is killed by that mv:zombie_pig??

toxic sage
# wise grail

You can't do this name change the file name to main.js

wise grail
#

for example: "<player's nickname> was bitten by wolf"

#

like "<player's nickname> was slain by Zombie" or "was blown up by Creeper"

#

I want to change this to "Player was brutally oinked"

hot swallow
#

lang in rp

#

other way is disable player death message

#

and make a custom death message via script

wise grail
#

I think lang in rp would be easier

#

but idk how to do this

#

this doesn't work, but I think it's because it's written incorrectly

patent aspen
#

Try with this

        if(eventData.deadEntity.typeId === "minecraft:player" && eventData.damageSource.damagingEntity?.typeId === "mv:zombie_pig"){
             world.sendMessage("text");
        }
    })```

I'm wrong
@wise grail
wise grail
#

[Scripting][error]-Plugin [Zpig - 0.0.1] - [main.js] ran with error: [ReferenceError: Module [@minecraft/server] not found. Native module error or file not found.]

wise grail
mental moat
patent aspen
#

What's your zpigmessage.js code?

#

show me it plz

wise grail
# patent aspen What's your zpigmessage.js code?
world.afterEvents.entityDie.subscribe(eventData=> {
        if(eventData.deadEntity.typeId === "minecraft:player" && eventData.damageSource.damagingEntity?.typeId === "mv:zombie_pig"){
             world.getDimension("overworld").sendMessage("text");
        }
    })```
patent aspen
#

I already understood

#

You must import the server-module

wise grail
#

in manifest?

patent aspen
#

I would want to confirm one thing

patent aspen
patent aspen
#

Look at this

wise grail
#

I rewrited manifest like this: { "format_version": 2, "header": { "name": "Zpig", "description": "Zombie pig BP", "uuid": "7fbab47b-082a-4e7d-85e6-1fdc117513ba", "version": [ 0, 0, 1 ], "min_engine_version": [ 1, 17, 0 ] }, "modules": [ { "type": "data", "description": "Data module", "uuid": "7a26ccc9-29c0-40cf-8500-66bb67d9cfb3", "version": [ 1, 0, 0 ] }, { "type": "script", "language": "javascript", "uuid": "01c8b905-d38c-424a-8bdd-bc0d2592354a", "description": "mojang-minecraft module, required to use the mojang-minecraft module", "entry": "scripts/main.js", "version": [1, 0, 0] } ], "dependencies": [ { "module_name": "@minecraft/server-ui", "version": "1.2.0-beta" }, { "module_name": "@minecraft/server", "version": "1.7.0-beta" } ], "capabilities": [ "script_eval" ] }

patent aspen
#

I think it would should work

#

But I don't use "capabilities"

#

Honestly, I don't what's that 😅. But try that

wise grail
#

when this entity kills me - nothing happens

#

even error doesn't appear

patent aspen
#

Mmmm

#

You have a main file?

wise grail
#

yes, i have

#

import './zpigmessage.js'

wise grail
patent aspen
#

Try with this

        if(eventData.deadEntity.typeId === "minecraft:player" && eventData.damageSource.damagingEntity?.typeId === "mv:zombie_pig"){
             world.sendMessage("text");
        }
    })```

I'm wrong
@wise grail
#

It isn't world.get....

#

It's just world.sendMessage

patent aspen
#

No

#

It's the message

wise grail
#

zpigmessage.js

patent aspen
#

Yes

wise grail
#

[Scripting][error]-Plugin [Zpig - 1.0.0] - [main.js] ran with error: [ReferenceError: 'world' is not defined at <anonymous> (zpigmessage.js:1)
]

#

now that error displays

patent aspen
#

Do you import world in zpig?

#

Like this @wise grail
{ world, system, ItemStack, Player } from "@minecraft/server";

#

And why don't use one file?

#

I mean, just use one file

wise grail
#

without main.js?

#

uh

#

scripting is too difficult

#

especially on js

patent aspen
#

Really no

#

I thought that, but learning is too easy

#

Let me try something

wise grail
#

something what?

patent aspen
#

In this zip, there is a main file

#

Change the typeId to your killer id

#

And let me know if it works

wise grail
patent aspen
#

Yeyyyy

wise grail
#

now I need to remove common death message and make sure that instead of "player" there is a player's nickname

patent aspen
#

Mmmmm

patent aspen
#

world.sendMessage(`${eventData.deadEntity.nameTag} text`);

#

@wise grail use this to player name

hot swallow
#

priviledge error...

#

nvm

patent aspen
#

What did you mean?

hot swallow
#

i thought this event was in beforeEvents, but its in after

patent aspen
#

Ummm ok, but @hot swallow , is there a way to cancel death message?

hot swallow
#

gamerule

patent aspen
#

Another way?

hot swallow
#

nope

patent aspen
#

F

#

It's so bad

wise grail
#

at least nickname works

patent aspen
wise grail
patent aspen
#

So, @wise grail, I think that you must run gamerule showdeathmessages false, then gamerule showdeathmessages true

patent aspen
#

I'm happy for help you

#

And gamerule sendcommandfeedback false

wise grail
#

ok

#

maybe someday they will add ability to remove message not only through /gamerule