2

I need MORE help

FillkTheFillker 8/7/21 11:20 am
283
8/9/2021 3:06 pm
ok, I'm new in datapacks and I have a doubt, how would I make a victory system for my map?
I tried to create one where if the person died 3 times, his score would reset and it would show that he lost.
Then it worked, but for the winner I don't know how to do it.
who should win would be the last person to stay alive, without dying 3 times.
Posted by
FillkTheFillker
Level 14 : Journeyman Architect
1

  Have something to say?

JoinSign in

10

Art1f4ct
08/07/2021 5:10 pm
Level 24 : Expert Miner
I'd start by changing the order of commands so the title displays before your clear the scoreboard. This way you can have the title command check the scoreboard and display the "You win" and "You loose" titles to players by their number of deaths. I'd also reset all players' scores and clear all players' effects so the game is fully reset. I'd do it like this [assuming this runs as the player who died 3 times]:

title @s title ["",{"text":"You Lose","color":"red"}]
title @a[scores={Deaths=..2}] title ["",{"text":"You Win","color":"green"}]
scoreboard players reset @a Deaths

..2
means "up to 2", which means that every player except for the one with a score of 3 will see this title (in the case of a 1v1, that's 1 player). There are many ways to do this, but I think this is the simplest change to your code.
2
SUPERIONtheKnight
08/08/2021 8:47 am
Level 30 : Artisan System
history
But we are told that the winner should be the "the last person to stay alive, without dying 3 times". With this setup, only one player will have to die 3 times, and everyone other than the one player who died will be announced as a winner. The solution to this is to simply count how many players are remaining, and select the only player remaining when all of the others have died 3 times.

Command to start the game:
scoreboard players add @a Deaths 0
Commands to run during game:
scoreboard players set #PlayerCount Deaths 0execute as @a[scores={Deaths=..2}] run scoreboard players add #PlayerCount Deaths 1execute if score #PlayerCount Deaths matches ..1 run title @a[scores={Deaths=..2}] title ["",{"text":"You Win","color":"green"}]title @a[scores={Deaths=3..}] title ["",{"text":"You Lose","color":"red"}]execute if score #PlayerCount Deaths matches ..1 run scoreboard players reset @a Deathsscoreboard players reset @a[scores={Deaths=3..}] Deaths
3
FillkTheFillker
08/08/2021 5:06 pm
Level 14 : Journeyman Architect
history
I tested your command, but in all the parts that had [​scores={Deaths=..2}] an error appeared in them
1
SUPERIONtheKnight
08/09/2021 1:07 am
Level 30 : Artisan System
history
Huh, how strange, I think I've found our problem. There is nothing wrong with the commands themselves, but rather with how they are getting copied. Apparently there was an invisible character that you can't see when you go to copy off of the webpage, so when you paste it into the mcfunction file, it doesn't work. Hopefully, I fixed this problem, and it should work if you try again! :)

If it doesn't work, I need more details:
What is the error? Very hard to help fix the problem if I don't know what the problem is.
What Minecraft version are you using? The above commands are meant for 1.17.1, and may not work in older versions of the game.
Are you using any mods that could conflict with vanilla commands? If so, you might need to use /minecraft:command instead of /command.
Are there any other details you can think of giving me that might help me better understand what's going on?
2
FillkTheFillker
08/09/2021 12:17 pm
Level 14 : Journeyman Architect
Ok ok, here's the thing, I think it's almost ok now, but since I put a /schedule for the command to be active always checking, it ends up repeating the "you win" command endless
The question is, how would I prevent this from happening?
1
SUPERIONtheKnight
08/09/2021 12:58 pm
Level 30 : Artisan System
history
I would run the function I gave only when any given player has died. You can do that with the commands given in this post. Something worth noting is that you are always going to win in a singleplayer environment because you are the only player(Unless you opened the world to LAN and invited some friends on that is).

EDIT: Having invisible character issue again with the new commands. Trying to fix
EDIT2: Fixed

scoreboard objectives add hasDied deathCount
execute if entity @a[scores={hasDied=1..}] run function path:to/above/function
scoreboard players reset @a[scores={hasDied=1..}] hasDied
2
FillkTheFillker
08/08/2021 4:39 pm
Level 14 : Journeyman Architect
you two are gods
1

Welcome