#How to Create SendMessage Variants Based on a Single Function

1 messages · Page 1 of 1 (latest)

marble epoch
#

I want to create a world/player message function that four parameters: If the message is global (world.sendMessage) or not (player.sendMessage), what type of message it is, the player to send it to if it is not global, and the message itself. The problem is that I don't know how to create a working script like that. So can anyone help me with this?

The function define part should look like this: function sendGameplayMessage(global, type, player, message).

visual salmon
#

It is should be 4 param? Because I can make only 2

#
function sendGameplayMessage(message, player) {
  return player
    ? player.sendMessage(message)
    : world.sendMessage(message)
}
marble epoch
#

The type is for what kind of notification it is, whether it'd be error, information, announcement, etc.

visual salmon
#
function sendGameplayMessage(message, type, player) {
  // Handler for type

  return player
    ? player.sendMessage(message)
    : world.sendMessage(message)
}
marble epoch
#

Well, what I have set up for the type is this:
ERROR:

.playSound('desmp.sting.error')
.sendMessage(`§l§7[§cX§7] §r§l${message}`)

INFORMATION:

.playsound('desmp.sting.info')
.sendMessage(`§l§7[§9i§7] §r§l${message}`)
visual salmon
#
function sendGameplayMessage(message, type, player) {
  if (type === "error") {
    message = `§l§7[§9i§7] §r§l${message}`
  } else if (type === "info") {
    message = `§l§7[§cX§7] §r§l${message}`
  }

  dimension.playSound(`desmp.string.${type}`)
  return player
    ? player.sendMessage(message)
    : world.sendMessage(message)
}
marble epoch
#

Huh. Thanks.

blazing smelt
marble epoch
#

I was gonna say lol

visual salmon
#

Lol, I didn't see it, mb

marble epoch
#

@visual salmon

marble epoch
#

Uh...

visual salmon
#

Isn't sound play globally?

#

Nvm

#
function sendGameplayMessage(message, type, player) {
  if (type === "error") {
    message = `§l§7[§9i§7] §r§l${message}`
  } else if (type === "info") {
    message = `§l§7[§cX§7] §r§l${message}`
  }

  player
    ? player.playSound(`desmp.string.${type}`)
    : dimension.playSound(`desmp.string.${type}`)
  player
    ? player.sendMessage(message)
    : world.sendMessage(message)
}
marble epoch
#

Thanks.

marble epoch
#

@visual salmon First of all, the sound is not working. Secondly, what is dimension?? It's defined as an any, so it doesn't exist.

visual salmon
#

It should be world.playSound

#

I thought the playSound inside Dimension class

marble epoch
#

Yeah. Changed it to that, still not working.

visual salmon
#

Show your recent code

marble epoch
#

Hang on, just a sec.

#
/**
 * 
 * @param {string} message 
 * @param {string} type 
 * @param {Player} player 
 * @returns
 */
export function sendGameplayMessage(message, type, player) {
    if (type === 'error') {
        message = `§l§7[§cX§7] §r§l${message}`
    } else if (type === 'exclamation') {
        message = `§l§7[§e!§7] §r§l${message}`
    } else if (type === 'info') {
        message = `§l§7[§9i§7] §r§l${message}`
    } else if (type === 'help') {
        message = `§l§7[§b?§7] §r§l${message}`
    } else if (type === 'notify_generic') {
        message = `§l§7[§b!§7] §r§l${message}`
    } else if (type === 'notify_positive') {
        message = `§l§7[§a!§7] §r§l${message}`
    } else if (type === 'notify_negative') {
        message = `§l§7[§c!§7] §r§l${message}`
    } else if (type === 'mail') {
        message = `§l§7[§d!§7] §r§l${message}`
    } else if (type === 'death') {
        message = `§l§7[§4X§7] §r§l${message}`
    } else if (type === 'announcement') {
        message = `§l§7[§6!§7] §e${message}`
    } else if (type === 'modwarning') {
        message = `§l§7[§4!§7] §c${message}`
    }

    player
        ? player.playSound(`desmp.sting.${type}`)
        : world.playSound(`desmp.sting.${type}`)

    player
        ? player.sendMessage(message)
        : world.sendMessage(message)
}
blazing smelt
marble epoch
#

True, but at the same time, the else if thing was Franky's idea.

#

But that's not the problem.

#

The problem is the sound not playing if it's a global message like an announcement.

blazing smelt
#
/**
 * 
 * @param {string} message 
 * @param {string} type 
 * @param {Player} player 
 * @returns
 */
export function sendGameplayMessage(message, type, player) {
    switch (type) {
        case 'error': 
            message = `§l§7[§cX§7] §r§l${message}`
            break;
        case 'exclamation': 
            message = `§l§7[§e!§7] §r§l${message}`
            break;
        case 'info': 
            message = `§l§7[§9i§7] §r§l${message}`
            break;
        case 'help': 
            message = `§l§7[§b?§7] §r§l${message}`
            break;
        case 'notify_generic': 
            message = `§l§7[§b!§7] §r§l${message}`
            break;
        case 'notify_positive': 
            message = `§l§7[§a!§7] §r§l${message}`
            break;
        case 'notify_negative': 
            message = `§l§7[§c!§7] §r§l${message}`
            break;
        case 'mail': 
            message = `§l§7[§d!§7] §r§l${message}`
            break;
        case 'death': 
            message = `§l§7[§4X§7] §r§l${message}`
            break;
        case 'announcement': 
            message = `§l§7[§6!§7] §e${message}`
            break;
        case 'modwarning': 
            message = `§l§7[§4!§7] §c${message}`
            break;
}
    player
        ? player.playSound(`desmp.sting.${type}`)
        : world.playSound(`desmp.sting.${type}`)

    player
        ? player.sendMessage(message)
        : world.sendMessage(message)
}```
marble epoch
#

But thanks for the switch stuff anyway.

blazing smelt
#

yeah I'm just looking at that rn

#

holdon

#

hm

#

@marble epoch try doing the incantation with the wrong capitalisation

#

like

marble epoch
#

Incantation?

#

These are gameplay messages.

blazing smelt
#

whatever the input is

marble epoch
#

Not incantations.

blazing smelt
#

for the book

#

the spell name or whatever

#

yeah Ik I just wanted to see something

#

cause last time I made it for u so that you didn't need the right capitalisation

#

yah

#

ok

#

cool

#

@marble epoch can you send the code where you run the function? like your gui code

#

just the part where the function is run

#

run

marble epoch
#
function announcePrompt(player, text) {
    player.playSound(`desmp.sting.exclamation`)
    new MessageFormData()
    .title('Make Announcement')
    .body(`Are you sure you want to make this announcement? This will alert all players about your input!\n\n§lANNOUNCEMENT TEXT: §r${text}`)
    .button1('Yes')
    .button2('No')
    .show(player).then((result) => {
        if (result.selection === 0) return announceMenu(player)
        if (result.canceled) {
            return announceMenu(player)
        } else
        sendGameplayMessage(`${text}`, 'announcement')
    })
}
blazing smelt
#

yeah

#

ah

#

i think I might know

#

uh

#

yeah holdon a sec

#

holdup

#

@marble epoch just run this command /playsound desmp.sting.announcement

#

does it even make any sound

#

yeah

#

ik

#

i'm just wondering if ur sound actually exists tho lmao

#

so the sound works normally right

#

ok

#

thats really weird

#
/**
 * 
 * @param {string} message 
 * @param {string} type 
 * @param {Player} player 
 * @returns
 */
export function sendGameplayMessage(message, type, player) {
    switch (type) {
        case 'error': 
            message = `§l§7[§cX§7] §r§l${message}`
            break;
        case 'exclamation': 
            message = `§l§7[§e!§7] §r§l${message}`
            break;
        case 'info': 
            message = `§l§7[§9i§7] §r§l${message}`
            break;
        case 'help': 
            message = `§l§7[§b?§7] §r§l${message}`
            break;
        case 'notify_generic': 
            message = `§l§7[§b!§7] §r§l${message}`
            break;
        case 'notify_positive': 
            message = `§l§7[§a!§7] §r§l${message}`
            break;
        case 'notify_negative': 
            message = `§l§7[§c!§7] §r§l${message}`
            break;
        case 'mail': 
            message = `§l§7[§d!§7] §r§l${message}`
            break;
        case 'death': 
            message = `§l§7[§4X§7] §r§l${message}`
            break;
        case 'announcement': 
            message = `§l§7[§6!§7] §e${message}`
            break;
        case 'modwarning': 
            message = `§l§7[§4!§7] §c${message}`
            break;
    }

    if(player ?? false) {
        player.playSound(`desmp.sting.${type}`)
        player.sendMessage(message)
    } else {
        world.playSound(`desmp.sting.${type}`)
        world.sendMessage(message)
    }
}```
#

try this out

#

oh wait a sec

#

there

#

@marble epoch

marble epoch
#

Yeah, I'm still here.

#

I was just having heart pains.

blazing smelt
#

shit man. that sucks

#

i swear i heard somethn

#

lol

#

@marble epoch send another announcement real quick

#

ah

#

ok

#

i heard a different sound then

#

i think from the form or something

#

there's link a ding sound

#

when u send it

#

are you sure that the two sounds aren't running over each other or something

marble epoch
#
function announcePrompt(player, text) {
    player.playSound(`desmp.sting.exclamation`)
    new MessageFormData()
    .title('Make Announcement')
    .body(`Are you sure you want to make this announcement? This will alert all players about your input!\n\n§lANNOUNCEMENT TEXT: §r${text}`)
    .button1('Yes')
    .button2('No')
    .show(player).then((result) => {
        if (result.selection === 0) return announceMenu(player)
        if (result.canceled) {
            return announceMenu(player)
        } else
        sendGameplayMessage(`${text}`, 'announcement')
    })
}
blazing smelt
#

hm

#

maybe world.playSound is broken

#

@marble epoch there is a sound options part which includes a location

#

i'm pretty sure that world.playSound plays sound like in a certain spot of the world, not just to the entire world

#

oop

#

idk then

#

bugrock moment ig

#

nah

#

you could just do world.getPlayers().foreach{

#

eyah ig

#

o right

#

yah

#

np

#

@marble epoch send code here

#

just the playsound part?

marble epoch
blazing smelt
#

why are all of them ifs except for the 13 - 19 one

#

you have one else if

#

and all the others are ifs

#

hm

#

whats the sound name again

#

u sure thats matching

#

@marble epoch wait does the particle appear when you die

#

yeah ik why

#

you have the entity coords

#

but

#

the entity is dead

#

so

#

idk

#

lmao

#

holdon i'll figure it out real quick

#

oh wait

#

nvm

#

sorry

#

uh

#

its cause you did entityY twice

#

your Z values have entityY instead of entityZ @marble epoch

#

yeah

#

${entityX} ${entityY} ${entityY}

#

yeah

#

check

#

lmao

#

heh

#

so yeah i was wrong about the death thing its just ur coordinates were wrong

#

alg

#

👍🏻

#

its like playing in some random area of the world lmao

#

yeah lol

marble epoch
#
world.events.playerSpawn.subscribe((data) => {
    if (!data.player.hasTag('ReturningPlayer') && !data.player.getDynamicProperty('hasCharacter') && data.initialSpawn) {
        world.sendMessage(`§l§b${data.player.name} has joined the game for the first time!`)
        data.player.runCommandAsync(`give @s desmp:main_menu_book 1 0 {"minecraft:item_lock":{"mode":"lock_in_inventory"},"minecraft:keep_on_death":{}}`)
        welcomeMenu(data.player)
        data.player.addTag('ReturningPlayer')
    }
    if (data.player.getDynamicProperty('hasCharacter') && data.player.hasTag('ReturningPlayer') && data.initialSpawn) {
        world.sendMessage(`§e${data.player.name} has joined the game.`)
        createCharacterMenu(data.player)
    } else if (data.initialSpawn && data.player.hasTag('ReturningPlayer') && data.player.getDynamicProperty('hasCharacter')) {
        world.sendMessage(`§e${data.player.getDynamicProperty('charName')} (${data.player.name}) has joined the game.`)
    }
})
blazing smelt
#

hm

blazing smelt
#

@marble epoch go to chat, and go all the way to the first message

#

is it the welcome message?

#

I have a similar system, but the welcome messages always appear really early, so when he player loads in, the message isn't displaying anymore

#

since the "player" actually loads into the game before the actual visuals load, so theres usually a couple of seconds while the player is "loaded in", but the actual player's view is still the loading screen

#

oh yeah also why is there different else if and ifs

#

you should change the second if to an else if

#

cool imma probably go as well