• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Work out current position

Status
Not open for further replies.
Level 14
Joined
Oct 16, 2010
Messages
749
Hi,

I've been making a little minigame which has a multiboard that shows you your ingame score as you play. It can be up to 12 players and the multiboard only contains players in the game.

But I was thinking of how to add a "Position" column, so it'd show you what position you are in the game in terms of your score. (1st, 2nd 3rd etc)

I have an idea of how I'd do it but there's probably much more efficient ways of doing it.

So would anyone know of a good way of checking each player's score (ingame variable) and putting them in order of who has the most score? Given that everyone starts with the same score it'd probably be good if players were able to be in equal position with eachother.

Any ideas?
 

Chaosy

Tutorial Reviewer
Level 41
Joined
Jun 9, 2011
Messages
13,239
JASS:
//! zinc
	library whatever	
	{
		public struct List
		{
			integer size = 0;
			integer values[99];
			
			public static method create() -> thistype
			{
				thistype this = thistype.allocate();
				return this;
			}
			
			public method add(integer i)
			{
				this.values[this.size] = i;
				size += 1;
			}
			
			method removeAt(integer i)
			{
				this.values[i] = this.values[this.size - 1];
				this.values[this.size - 1] = 0;
				this.size -= 1;
			}
			
			method destroy()
			{
				this.deallocate();
			}
			
			public method writeList()
			{
				integer j = 0;
				while(j < this.size)
				{
					BJDebugMsg(I2S(this.values[j]));
					j += 1;
				}
			}
			
		public method sortList()
        {
            integer i, j, x = 0;
            for(0 <= i < this.size)
            {
                x = this.values[i];
                j = i;
                while(j > 0 && this.values[j - 1] > x)
                {
                    this.values[j] = this.values[j - 1];
                    j = j - 1;
                }
                this.values[j] = x;
            }
            i = 0;
        }
			
		method getSize() -> integer
		{
			return this.size;
		}
			
		}
		function onInit()
		{
			//Demo
			/*
			List myList = List.create();
			myList.add(5);
			myList.add(3);
			myList.add(7);
			myList.add(88);
			myList.add(69);
			myList.writeList();
			BJDebugMsg("-----");
			myList.removeAt(1);
			myList.sortList();
			BJDebugMsg("-----");
			myList.writeList();
			*/
		}
	}
//! endzinc
  • Untitled Trigger 001
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Custom script: local List myList = List.create()
      • -------- [number] is the player number, so 1 = player red --------
      • Set score[1] = 65
      • Set score[2] = 23
      • Set score[3] = 97
      • Set score[4] = 33
      • For each (Integer A) from 1 to 4, do (Actions)
        • Loop - Actions
          • Custom script: call myList.add(udg_score[bj_forLoopAIndex ])
      • Custom script: call myList.sortList()
      • Custom script: call myList.writeList()
      • Custom script: call myList.destroy()
Result:
ffbe48217963c370320d23efb200d72f.png
 
Status
Not open for further replies.
Top