• 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.

[JASS] Who has the most?

Status
Not open for further replies.
Level 7
Joined
Feb 26, 2005
Messages
210
Here's my dilema; I'm working on a map where when the time ends the player with the most points wins. Problem? I have no idea how to determine who has the most points! Yes I can keep track as to how many points each player actually has, but I cannot tell who has the most overall. It gets even more complicated when two or more players have the most points (ie. a tie)!

Help?
 
Level 8
Joined
Jul 9, 2006
Messages
41
A ponderous problem. Perhaps with many loops?
(Brief draft)
JASS:
function OnGameEnd takes nothing returns nothing
local integer i=1
local player winner=Player(0)
local boolean tie=false
local force tieforce=CreateForce()
loop
exitwhen i>11
if GetPlayerPoints(Player(i))>GetPlayerPoints(winner) then
set winner=Player(i)
endif
set i=i+1
endloop
set i=0
loop
exitwhen i>11
if GetPlayerPoints(Player(i))==GetPlayerPoints(winner) and Player(i) != winner then
set tie=true
endif
set i=i+1
endloop
if tie==true then
set i=0
loop
exitwhen i>11
if GetPlayerPoints(Player(i))==GetPlayerPoints(winner) then
call ForceAddPlayer(tieforce,Player(i))
endif
set i=i+1
endloop
//Whatever you want to do to the tying players, add here.
else
call DisplayTextToForce(GetPlayersAll(),GetPlayerName(winner)+" has won!")
//Add endgame stuff here?
endif
endfunction
Course, you'd need your GetPlayerPoints function to return the points of that player...
 
Level 8
Joined
Oct 20, 2004
Messages
66
This is basically the above code that's simpler and easier to read.

JASS:
function OnGameEnd takes nothing returns nothing
    local integer PlayerNumber = 1
    local integer WinnerPoints
    local integer PlayerPoints
    local player Winner = Player(0)
    local force TieForce = CreateForce()

    loop
        exitwhen PlayerNumber > 11
        set WinnerPoints = GetPlayerPoints(Winner)
        set PlayerPoints = GetPlayerPoints(Player(PlayerNumber))
        if PlayerPoints > WinnerPoints then
            set Winner = Player(PlayerNumber)
            call ForceClear(TieForce)
            call ForceAddPlayer(TieForce, Player(PlayerNumber))
        elseif PlayerPoints == WinnerPoints then
            call ForceAddPlayer(TieForce, Player(PlayerNumber))
        endif
        set PlayerNumber = PlayerNumber + 1
    endloop

    if CountPlayersInForceBJ(TieForce) > 1 then

        // Whatever you want to do to the players who are tied, add here.

    else
        call DisplayTextToForce(GetPlayersAll(),GetPlayerName(Winner) + " has won with " + I2S(WinnerPoints) + " points!")

        // Whatever you want to do when the winner has been declared, add here.

    endif

    call DestroyForce(TieForce)
    set Winner = null
    set TieForce = null
endfunction
 
Status
Not open for further replies.
Top