#How can I add custom death message?
1 messages · Page 1 of 1 (latest)
You can use entityDie event
world.afterEvents.entityDie.subscribe(({deadEntity}) => {
if(deadEntity.typeId == "minecraft:player"){
deadEntity.sendMessage("its work")
});```
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
you would chance the if deadEntity.typeId === example
world.afterEvents.entityDie.subscribe(({deadEntity}) => {
if(deadEntity.typeId === "mv:zombie_pig"){
deadEntity.sendMessage("its work")
});
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?
show your manifest.js
manifest.json i meant
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'
import "./pigmessage.js"
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
[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
@wise grail you want to send the message to the player When he is killed by that mv:zombie_pig??
You can't do this name change the file name to main.js
yes, i do
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"
lang in rp
other way is disable player death message
and make a custom death message via script
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
Try with this
if(eventData.deadEntity.typeId === "minecraft:player" && eventData.damageSource.damagingEntity?.typeId === "mv:zombie_pig"){
world.sendMessage("text");
}
})```
I'm wrong
@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.]
main.js: import './zpigmessage.js'
https://github.com/mrpatches123/patchy-api/blob/main/manifest.json
look at the dependencies
world.afterEvents.entityDie.subscribe(eventData=> {
if(eventData.deadEntity.typeId === "minecraft:player" && eventData.damageSource.damagingEntity?.typeId === "mv:zombie_pig"){
world.getDimension("overworld").sendMessage("text");
}
})```
in manifest?
I would want to confirm one thing
Yes
I don't see it here
Look at this
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" ] }
I think it would should work
But I don't use "capabilities"
Honestly, I don't what's that 😅. But try that
I saw it
main.js
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
it's main.js, right?
zpigmessage.js
[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
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
something what?
In this zip, there is a main file
Change the typeId to your killer id
And let me know if it works
Yeyyyy
now I need to remove common death message and make sure that instead of "player" there is a player's nickname
Mmmmm
world.sendMessage(`${eventData.deadEntity.nameTag} text`);
@wise grail use this to player name
i thought this event was in beforeEvents, but its in after
Ummm ok, but @hot swallow , is there a way to cancel death message?
gamerule
Another way?
nope
at least nickname works
Yey
thanks a lot anyway
So, @wise grail, I think that you must run gamerule showdeathmessages false, then gamerule showdeathmessages true
Don't worry ^^
I'm happy for help you
And gamerule sendcommandfeedback false