#Get all players in Dropdown (Modal form)

1 messages · Page 1 of 1 (latest)

neon token
#

get the list of all players connected in the "Dropdown" of "ModalForm" is that it returns the nickname of the selected players is not the position in the index/list

//ModalForm Example
function openModalForm(player) {
    const ModalForm = new ui.ModalFormData()

    ModalForm.title('Modal Form')
    ModalForm.textField('This is a Textfield', 'This is a Placeholdertext')
    ModalForm.dropdown('This is a Dropdown', ['Option 1', 'Option 2', 'Option 3', 'Option 4', 'Option 5'], 0)
    ModalForm.slider('This is a Slider', 0, 100, 1, 50)
    ModalForm.toggle('This is a Toggle', false)
    
    ModalForm.show(player).then(response => {
        if (response.canceled) {
            openMain(player)
            return
        }
        let [textField, dropdown, slider, toggle] = response.formValues
        player.runCommandAsync(`tellraw @s {"rawtext":[{"text":"Textfiel: ${textField}\nDropdown: ${dropdown}\nSlider: ${slider}\nToggle: ${toggle}\n"}]}`)
    })
}
untold remnant
#
const players = world.getAllPlayers().map(plr => plr.name);
ModalForm.dropdown("Players", players, 0);
neon token
#

I want it return the name

#

I need to import something before?

#
//Module
import * as mc from '@minecraft/server'
import * as ui from '@minecraft/server-ui'
#
//ModalForm Example
function openModalForm(player) {
    const ModalForm = new ui.ModalFormData()
    const players = mc.world.getAllPlayers().map(plr => plr.name)

    ModalForm.title('Modal Form')
    ModalForm.textField('Modal Form textField', 'Modal Form placeholderText')
    ModalForm.dropdown("Players", players, 0)
    ModalForm.slider('Modal Form slider', 0, 100, 1, 50)
    ModalForm.toggle('Modal Form toggle', false)
    
    ModalForm.show(player).then(response => {
        if (response.canceled) {
            openMain(player)
            return
        }
        let [textField, dropdown, slider, toggle] = response.formValues
        player.runCommandAsync(`tellraw @s {"rawtext":[{"text":"Textfiel: ${textField}\nDropdown: ${dropdown}\nSlider: ${slider}\nToggle: ${toggle}\n"}]}`)
    })
}
untold remnant
#

To return a value we must do something first.

...
let [textField, dropdown, slider, toggle] = respone.formValues;
player.runCommandAsync(`tellraw @s {"rawtext":[{"text":"TextFiel: ${textField}\nDropdown: ${players[dropdown]}...`);
neon token
untold remnant
#

Yes.

neon token
#

Just i have last question

#

I am confused to put async and await on in my code because to build form i use function

untold remnant
#

I don't think you need async/await it for now.

neon token
#

Before RunCommand Async i have made a toggle button to Disable/Enable with Action form button but now it dont work with RunCommandAsync and how i disable that

ActionForm.show(source).then(response => {
        if (response.canceled) {
            openArenaMenu(source)
            source.runCommandAsync(`playsound note.bass @s`)
        }
        switch (response.selection) {
            case 0:
                source.runCommandAsync(`structure load kitStarter ~ ~ ~`)
                source.runCommandAsync(`playsound random.levelup @s`)
                break
            case 1:
                source.runCommandAsync(`scoreboard players add @s autostarterkit 1`)
                if (getScore('autostarterkit', source) == 1) {// HERE
                    source.runCommandAsync(`tellraw @s {"rawtext":[{"text":"Auto-Équiper le Kit de Départ: §aActiver"}]}`)
                    source.runCommandAsync(`playsound random.levelup @s`)
                } else {
                    source.runCommandAsync(`scoreboard players set @s autostarterkit 0`)
                    source.runCommandAsync(`tellraw @s {"rawtext":[{"text":"Auto-Équiper le Kit de Départ: §cDésactiver"}]}`)
                    source.runCommandAsync(`playsound note.bass @s`)
                }
                break
        }
    })
#

@untold remnant

untold remnant
#

Maybe async/await can help on this, but I'm sorry to say that I haven't worked with asynchronous functions yet, so I don't know how to help you, sorry. But maybe @Remember M9 can help.

neon token
#

But very thx with dropdown ^^

untold remnant
#

Well, runCommandAsync() is an async function and returns a promise, so maybe this information will help a little.

neon token
#

@untold remnant
Just I'm confused with the tables

In fact in a dropdown I would like to have a list that is displayed like this in the dropdown §cRed, §aVert but that it returns §c, §aVert

like that

const colors = ['§fWhite' == '§f', '§aGreen' == '§a']
median topaz
#

what

#
const colors = {
    "§fWhite": "§f",
    "§aGreen": "§a",
}```
#

called a dictionary

#

or some ppl call it an object i think

neon token
#

Because i dont have error but this form with the dictionnary canot open@median topaz

median topaz
#

okay @neon token heres an example

#
function test() {
    const colors = {
        "§fWhite": "§f",
        "§aGreen": "§a",
    }
    console.warn(colors["§fWhite"])
}```
neon token
#
//Alert
function openAlert(player) {
    const ModalForm = new ui.ModalFormData()
    const colors = {'§fWhite': '§f', '§aGreen': '§a'}

    ModalForm.title('Send Alert')
    ModalForm.dropdown('Color', colors, 0)
    ModalForm.textField('Message', 'Type the message')

    ModalForm.show(player).then(response => {
        if (response.canceled) {
            openMain(player)
            return
        }
        let [dropdown, textField] = response.formValues
        player.runCommandAsync(`tellraw @a {"rawtext":[{"text":"§l§7[§4Alert§7] §r${colors[dropdown]}${textField}"}]}`)
    })
}
median topaz
#

also

#

u should use world.sendMessage instead of tellraw

neon token
#

Do u have an idea to apply dictionnary on dropdown?

#

@median topaz

median topaz
#

bro can u wait

neon token
#

Yes sorry

median topaz
#

search up javascript dictionaries