5
\$\begingroup\$

So I've been writing a script over the last little while in Python that interacts with the Minecraft console. I'm basically trying to make a scoreboard based currency system that is world independent and doesnt require command blocks.

I'm having trouble here with the setdisplay sidebar. I often see other peoples sidebar instead of my own.

When I setdisplay list is shows correctly in tab list per character. Can I make my sidebar scoreboard show correctly per character as well? It seems like everyone is seeing the same scoreboard for 1 player.

Full source: https://github.com/Veritas83/Minecraft.SNAPSHOT.Commands.Mod/blob/master/commands.by.YT_Veritas0923.py

screenshot

UpdateSB()

    def UpdateSB():
        setsb = "scoreboard players operation $ Character = @a money\n"
        #print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
        p.stdin.write(setsb)
        setsb = "scoreboard players operation Rank Character = @a rank\n"
        #print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
        p.stdin.write(setsb)
        setsb = "scoreboard players operation Kills Character = @a totalkills\n"
        #print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
        p.stdin.write(setsb)
        setsb = "scoreboard players operation Wood Character = @a wood\n"
        #print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
        p.stdin.write(setsb)
        setsb = "scoreboard players operation Stone Character = @a stone\n"
        #print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
        p.stdin.write(setsb)
        setsb = "scoreboard players operation Coal Character = @a coal\n"
        #print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
        p.stdin.write(setsb)
        setsb = "scoreboard players operation Iron Character = @a iron\n"
        #print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
        p.stdin.write(setsb)
        setsb = "scoreboard players operation Gold Character = @a gold\n"
        #print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
        p.stdin.write(setsb)
        setsb = "scoreboard players operation Redstone Character = @a redstone\n"
        #print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
        p.stdin.write(setsb)
        setsb = "scoreboard players operation Diamond Character = @a diamond\n"
        #print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
        p.stdin.write(setsb)
        setsb = "scoreboard objectives setdisplay list money\n"
        #print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
        p.stdin.write(setsb)
        setsb = "scoreboard objectives setdisplay sidebar Character\n"
        #print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
        p.stdin.write(setsb)
        setsb = "scoreboard players set @a killcounter 0\n"
        #print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
        p.stdin.write(setsb)
        setsb = "scoreboard players set @a woodcounter 0\n"
        #print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
        p.stdin.write(setsb)
        setsb = "scoreboard players set @a stonecounter 0\n"
        #print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
        p.stdin.write(setsb)
        setsb = "scoreboard players set @a coalcounter 0\n"
        #print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
        p.stdin.write(setsb)
        setsb = "scoreboard players set @a ironcounter 0\n"
        #print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
        p.stdin.write(setsb)
        setsb = "scoreboard players set @a goldcounter 0\n"
        #print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
        p.stdin.write(setsb)
        setsb = "scoreboard players set @a redstonecounter 0\n"
        #print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
        p.stdin.write(setsb)
        setsb = "scoreboard players set @a diamondcounter 0\n"
        #print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
        p.stdin.write(setsb)

ProcessRewards

    def ProcessRewards(metric,reward):
        for i in range(1,6):
            setsb = "scoreboard players add @a[score_" + metric + "counter_min=" + str(i) + ",score_rank_min=0,score_rank=3] money " + str(int(round((int(i) * int(reward)) * 1.2))) + "\n"
            print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
            p.stdin.write(setsb)
            setsb = "scoreboard players add @a[score_" + metric + "counter_min=" + str(i) + ",score_rank_min=4,score_rank=6] money " + str(int(round((int(i) * int(reward)) * 1.6))) + "\n"
            print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
            p.stdin.write(setsb)
            setsb = "scoreboard players add @a[score_" + metric + "counter_min=" + str(i) + ",score_rank_min=7,score_rank=9] money " + str(int(round((int(i) * int(reward)) * 2))) + "\n"
            print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
            p.stdin.write(setsb)
            setsb = "scoreboard players add @a[score_" + metric + "counter_min=" + str(i) + ",score_rank_min=10,score_rank=10] money " + str(int(round((int(i) * int(reward)) * 2.4))) + "\n"
            print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
            p.stdin.write(setsb)
            setsb = "scoreboard players add @a[score_" + metric + "counter_min=" + str(i) + ",score_rank_min=11,score_rank=11] money " + str(int(round((int(i) * int(reward)) * 2.8))) + "\n"
            print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
            p.stdin.write(setsb)
            setsb = "scoreboard players add @a[score_" + metric + "counter_min=" + str(i) + ",score_rank_min=12,score_rank=12] money " + str(int(round((int(i) * int(reward)) * 3.2))) + "\n"
            print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
            p.stdin.write(setsb)
            setsb = "scoreboard players add @a[score_" + metric + "counter_min=" + str(i) + ",score_rank_min=13,score_rank=13] money " + str(int(round((int(i) * int(reward)) * 5))) + "\n"
            print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
            p.stdin.write(setsb)
            setsb = "scoreboard players add @a[score_" + metric + "counter_min=" + str(i) + ",score_rank_min=14,score_rank=14] money " + str(int(round((int(i) * int(reward)) * 10))) + "\n"
            print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
            p.stdin.write(setsb)
            setsb = "scoreboard players add @a[score_" + metric + "counter_min=" + str(i) + ",score_rank_min=15,score_rank=15] money " + str(int(round((int(i) * int(reward)) * 15))) + "\n"
            print "[" + get24hrtime() + "] [Script thread/POLL]: " + setsb,
            p.stdin.write(setsb)

Scoreboard Init

        #Setup Scoreboard
        if sbset == False:
            setsb = "scoreboard objectives add inOverworld dummy\n"
            print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
            p.stdin.write(setsb)
            if usemoney == True:
                setsb = "scoreboard objectives add Character dummy\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard objectives add Info dummy\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard objectives add totalkills stat.mobKills Kills\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard objectives add killcounter stat.mobKills\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard objectives add woodcounter stat.mineBlock.minecraft.log\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard objectives add stonecounter stat.mineBlock.minecraft.stone\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard objectives add coalcounter stat.mineBlock.minecraft.coal_ore\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard objectives add ironcounter stat.mineBlock.minecraft.iron_ore\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard objectives add goldcounter stat.mineBlock.minecraft.gold_ore\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard objectives add redstonecounter stat.mineBlock.minecraft.redstone_ore\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard objectives add diamondcounter stat.mineBlock.minecraft.diamond_ore\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard objectives add wood stat.mineBlock.minecraft.log Wood\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard objectives add stone stat.mineBlock.minecraft.stone\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard objectives add coal stat.mineBlock.minecraft.coal_ore\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard objectives add iron stat.mineBlock.minecraft.iron_ore\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard objectives add gold stat.mineBlock.minecraft.gold_ore\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard objectives add redstone stat.mineBlock.minecraft.redstone_ore\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard objectives add diamond stat.mineBlock.minecraft.diamond_ore\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard objectives add woodcounter stat.mineBlock.minecraft.log\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard objectives add rank dummy Rank\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard objectives add money dummy Money\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard objectives setdisplay sidebar Character\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard players operation $ Character = @a money\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard players operation Rank Character = @a rank\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard players operation Kills Character = @a totalkills\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard players operation Wood Character = @a wood\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard players operation Coal Character = @a coal\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard players operation Iron Character = @a iron\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard players operation Gold Character = @a gold\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard players operation Redstone Character = @a redstone\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard players operation Diamond Character = @a diamond\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard players operation Kills Info = @a totalkills\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
                setsb = "scoreboard objectives setdisplay list rank\n"
                print "[" + get24hrtime() + "] [Script thread/INIT]: " + setsb,
                p.stdin.write(setsb)
            sbset = True

6s poll timer

        #6s Poll time
        if sbset == True and currtime - lasttimepoll > 6:
            lasttimepoll = time.time()
            if usemoney == True:
                tasks = ['kill','wood','stone','coal','iron','gold','redstone','diamond']
                reward = [10,5,1,8,16,32,10,64]
                for t in range(0,len(tasks)):
                    a=ProcessRewards(tasks[t],reward[t])
            a=UpdateSB()
            a=OverworldCheck()
\$\endgroup\$
  • \$\begingroup\$ You have a ton of repeating code, making it unnecessarily hard for you to change something. Please make functions that, e.g. in the Scoreboard init, only take in "Coal Character = @a coal". I also did not understand what you mean with "show correctly per character", you may need to express that in another way. \$\endgroup\$ – Tau Apr 9 '18 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.