#how do i make a money transfer form?
1 messages · Page 1 of 1 (latest)
does this actually show the player on the dropdown?
what i would do is
let players = [];
for (let player of world.getPlayers()) {
players.push(player.name);
}
const players = world.getAllPlayers()
.dropdown(`Player`, players.map(p => p.name));
Wait
function Transfer(player){
const players = world.getPlayers();
const sendPoints = new ModalFormData();
sendPoints.title("Send Points To ur Friends")
sendPoints.dropdown("Select a player :", players.map(p => p.name), 0);
sendPoints.slider("Select amount", 0, 64, 2, 0);
sendPoints.show(player).then(({formValues}) => {
const [ resiver, amount] = formValues;
player.sendMessage(`you sent a ${amount} to ${resiver});
});
}```
: ) you need a money (scoreboard objective) transfer
Bro try what i sent to u and you will understand
const players = [...world.getPlayers()];
const moneyTransferForm = new ModalFormData()
.title(title)
.dropdown('§o§5Choose Who To Send Money!', players.map(player => player.nameTag))
.textField(`§uEnter The Amount Your Sending!\n§dCurrent Amount Of Money=§5 (${getScore('Money', player.nameTag)})`, `§oOnly Use Numbers`)
.show(player)
.then(({ formValues: [dropdown, textField] }) => {
const selectedPlayer = players[dropdown];
if (selectedPlayer === player) {
player.runCommandAsync(`tellraw @s {"rawtext":[{"text":"§cYou Cant Select Yourself"}]}`)
return
} if (textField.includes("-")) {
player.runCommandAsync(`tellraw @s {"rawtext":[{"text":"§cOnly Use Numbers"}]}`)
return
}
if (getScore('Money', player.nameTag) < textField) {
player.runCommandAsync(`tellraw @s {"rawtext":[{"text":"§cYou Dont Have Enough Money"}]}`);
return;
} try {
player.runCommandAsync(`scoreboard players remove @s Money ${textField}`)
player.runCommandAsync(`tellraw @s {"rawtext":[{"text":"§aSent §l${selectedPlayer.nameTag} §r§2$${textField}"}]}`)
selectedPlayer.runCommandAsync(`tellraw @s {"rawtext":[{"text":"§l${player.nameTag} §r§ahas given you §a${textField}"}]}`);
selectedPlayer.runCommandAsync(`scoreboard players add @s Money ${textField}`)
} catch {
player.runCommandAsync(`tellraw @s {"rawtext":[{"text":"§cOnly Use Numbers"}]}`)
return
}
}).catch((e) => {
console.error(e, e.stack)
});
}```
Lets you type the ammount to send
Also sends msg
@fossil tangle
Thats all u need
Oki
It work?
Dm me ure code man
It works for me
you didn't give him the getScore function thats why it doesn't work
@fossil tangle
The custom getScore() function must be defined by you. An example getScore function would be (based on the context provided here):
function getScore(player, objectiveID) {
return world.scoreboard.getObjective(objectiveID).getScore(player);
}
const money = world.scoreboard.getObjective("money");
const playerMoney = money.getScore(player);```
function Transfer(player){
const players = world.getPlayers();
const money = world.scoreboard.getObjective("money");
const playerMoney = money.getScore(player);
const sendPoints = new ModalFormData();
sendPoints.title("Send Points To ur Friends")
sendPoints.dropdown("Select a player :", players.map(p => p.name), 0);
sendPoints.slider("Select amount", 0, playerMoney, 2, 0);
sendPoints.show(player).then(({formValues}) => {
const [ resiver, amount] = formValues;
player.sendMessage(`you sent a ${amount} to ${resiver});
players[resiver].runCommand(`scoreboard players add @s money ${amount}`);
player.runCommand(`scoreboard players add @s money -${amount}`);
});
}```
@fossil tangle this is the full code try it
And make a scoreboard objective with name money
const getScore = (target, objective) => {
try {
return world.scoreboard.getObjective(objective)?.getScore(target) ?? 0;
} catch (error) {
return 0;
}
};```You can also use this to be able to get scores at any time you'd like
You give him difficult things, and he does not even know the easy things🙂
that is an easy thing
For u
slap it in your code then just put getScore(player, "money");.. that's all he needs to remember
that's simple to understand
use player.sendMessage
And world.scoreboard
then add a couple of extra things like instead of mapping all the players names ,map the ones whose name doesn't equal the player using the form, and make it say the name of the player you sent money to
now try again, but with the other player leaving the world
import {world} from "@minecraft/server";
import { ModalFormData } from "@minecraft/server-ui";
function getScore (target, objective) {
try {
return world.scoreboard.getObjective(objective)?.getScore(target) ?? 0;
} catch (error) {
return 0;
}
};
function transfer(p) {
const players = world.getPlayers();
const money = world.scoreboard.getObjective('money');
const playerMoney = getScore(p, 'money');
let sendPoints = new ModalFormData();
sendPoints.dropdown('Select player', players.map(p => p.name));
sendPoints.slider('Select amount', 0, playerMoney, 1);
sendPoints.show(p).then(r => {
if (r.canceled) return;
const sel = players[r.formValues[0]];
if (world.getPlayers()[r.formValues[0]].name === sel.name){
money.setScore(p, playerMoney - r.formValues[1]);
money.addScore(sel, r.formValues[1]);
sel.sendMessage(p.name + ' send you ' + r.formValues[1] + '$');
}
})
};```
Sorry any errors, i'm on phone
☠️
import { world }
There are 16 errors in this [code](#1165266768160362617 message).
Please read the attached file for the result.
There are 11 errors in this [code](#1165266768160362617 message).
Please read the attached file for the result.
is that player a participant of that scoreboard?
if not it won't work
why did you define a arrow function inside a function
just move it outside the function
: ) bruh
Broo resiver He is the player to whom you sent points
And you can make a condition
To check if the resiver has the same name of the player to make u can't send money to yourself
The player who resive the money or the player are send the money?
Add this
players[resiver].sendMessage(`§b${player.name}§r has sent to you §a${amount} points`);```
I make this
import {world} from "@minecraft/server";
import { ModalFormData } from "@minecraft/server-ui";
function getScore (target, objective) {
try {
return world.scoreboard.getObjective(objective)?.getScore(target) ?? 0;
} catch (error) {
return 0;
}
};
function transfer(p) {
const players = world.getPlayers();
const money = world.scoreboard.getObjective('money');
const playerMoney = getScore(p, 'money');
let sendPoints = new ModalFormData();
sendPoints.dropdown('Select player', players.map(p => p.name));
sendPoints.slider('Select amount', 0, playerMoney, 1);
sendPoints.show(p).then(r => {
if (r.canceled) return;
const sel = players[r.formValues[0]];
if (world.getPlayers()[r.formValues[0]].name === sel.name){
money.setScore(p, playerMoney - r.formValues[1]);
money.addScore(sel, r.formValues[1]);
sel.sendMessage(p.name + ' send you ' + r.formValues[1] + '$');
}
})
};```