Thanks for asking your question!
Once you have finished, please close your thread.
Use the /close command or button below.
1 messages · Page 1 of 1 (latest)
Once you have finished, please close your thread.
//The Database
const gangs = new Database("test");
//Function that gets players score
function getScore(player, money) {
try {
return world.scoreboard.getObjective(money).getScore(player.scoreboard);
}
catch (error) {
return 0;
}
}
world.events.beforeItemUse.subscribe((gangMenus)=>{
const player = gangMenus.source;
const item = gangMenus.item;
//Illegal characters in Gang Name RegEx
const illegalChars = /[^a-z0-9§]/gi;
const gangCreate = new ModalFormData();
gangCreate.title("Gang Creation");
gangCreate.textField("Choose your Gang's Name.", "Alphanumeric Only!");
const gangsDropdown = new ModalFormData();
gangs.keysSync().then((v)=> {
gangsDropdown.dropdown("Gangs", v)
})
if (item.typeId == 'minecraft:apple') {
gangCreate.show(player).then((result)=>{
let gangName = result.formValues[0];
if (illegalChars.test(gangName)) {
player.tell("§cYour Gang Name can only include alphanumeric characters!")
return
}
if (getScore(player, 'money') < 10000) {
player.tell("§cYou don't have enough money!")
return
}
if (!gangs.has(gangName)) {
player.tell("§cA Gang already has this name!")
return
}
if(getScore(player, 'money') >= 10000) {
console.warn("Gang Created")
player.runCommandAsync("scoreboard players remove @s money 10000")
gangs.set(gangName, {
"Notoriety": 0,
"Bounty": 0,
"Bank": 0,
"Blacklist": [],
"Players": []
})
}
});
}
if (item.typeId == 'minecraft:golden_apple') {
gangsDropdown.show(player).then((res)=>{
gangsDropdown.delete(res.formValues[0]);
```
You could’ve edited the original message instead of deleting
So, above is the code, the import and ending braces are removed are too long
I couldn't, I tried adding the three backticks at the top and it kept sending my keyboard down and moving me down the message when I tried to click it
Just like Jayly said: you should ask the person who creates the database
Anyways, the part that doesn't work is the part that adds the gang you've named to the database. Not sure why it isn't working. Every other error is working, if I don't use alphanumeric, I get an error, if I don't have enough money, error. But, suddenly, the if adding the gang to the database doesn't work. The console warn also isn't running, not sure why.
He takes ages to respond
There is no other choice
Hold on, it used to work tho
Until I fixed the if statement to test if you had enough money, it worked
What errors does it throw?
Nothing, it just doesn't do anything when I hit submit whilst having all the requirements to make a gang
It doesn't even console warn anything
So the form opens it just does nothing when submitting
Yup
It used to
It'll say when I don't have enough money, and when I don't use alphanumeric, but if I meet all the requirements it just doesn't do anything. The console warn doesn't run
//The Database
const gangs = new Database("test");
//Function that gets players score
function getScore(player, money) {
try {
return world.scoreboard.getObjective(money).getScore(player.scoreboard);
}
catch (error) {
return 0;
}
}
world.events.beforeItemUse.subscribe((gangMenus)=>{
const player = gangMenus.source;
const item = gangMenus.item;
//Illegal characters in Gang Name RegEx
const illegalChars = /[^a-z0-9§]/gi;
const gangCreate = new ModalFormData();
gangCreate.title("Gang Creation");
gangCreate.textField("Choose your Gang's Name.", "Alphanumeric Only!");
const gangsDropdown = new ModalFormData();
gangs.keysSync().then((v)=> {
gangsDropdown.dropdown("Gangs", v)
})
if (item.typeId == 'minecraft:apple') {
gangCreate.show(player).then((result)=>{
let gangName = result.formValues[0];
if (illegalChars.test(gangName)) return player.tell("§cYour Gang Name can only include alphanumeric characters!");
if (!gangs.has(gangName)) return player.tell("§cThere is already a Gang with the same name!");
if (getScore(player, 'money') < 10000) {
return player.tell("§cYou don't have enough money!");
} else {
gangs.set(gangName, {
"Notoriety": 0,
"Bounty": 0,
"Bank": 0,
"Blacklist": [],
"Players": [],
}) ;
player.runCommandAsync("scoreboard players remove @s money 10000");
return console.warn("Gang Created");
}
});
}
if (item.typeId == 'minecraft:golden_apple') {
gangsDropdown.show(player).then((res)=>{
gangsDropdown.delete(res.formValues[0]);
```
Cheers