HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Leaderboard

06-26-2002, 01:36 AM#1
Karedis
How would I go about making a kills leaderboard and then updating it with the retail WE...?

I've tried using a Kills Array and the owner of killing unit thing, but to no avail. Help? I'm new at this array stuff.
06-27-2002, 01:35 PM#2
Guest
Set up the leaderboard

Events
-3 seconds has past
Actions
-Create a leaderboard for (all players) titled Kills
-Pick ever playier in (all players controlled by a user player) and do (add (picked player) to (last created leaderboard) with label (Name of (picked player) and value 0)

Update the leaderboard
Events
- Unit owned by player 1 dies
- Unit owned by player 2 dies
- Unit owned by player 3 dies
- Unit owned by player 4 dies
- Unit owned by player 5 dies
- Unit owned by player 6 dies
- Unit owned by player 7 dies
- Unit owned by player 8 dies
Conditions (if you don't allow killing your own units)
- (Owner of (Dying unit)) is not equal to (Owner of(killing unit))
Actions
Actions
-set kills[(Player number of (Owner of (killing unit)))] = (kills[(Player number of (Owner of (killing unit)))] + 1)
- Change the value for (Owner of (killing unit)) in (Last created leaderboard) to kills[(player number of ((Owner of (killing unit)))]
-Sort (last created leaderboard) by value in descending order
06-29-2002, 03:39 PM#3
Guest
hey there
i cant find the trigger to set this option:
set kills[(Player number of (Owner of (killing unit)))] = (kills[(Player number of (Owner of (killing unit)))] + 1)

can you help me, plz?
06-29-2002, 06:05 PM#4
Guest
I did my updating a little different. The creation I did the same pretty much.
The following code uses 5 int variables. One is used to hold the number of the player that owns the killing unit.
The other 4 keep track of the number of kills for each player.

Code:
function Trig_Update_Board_Func002001 takes nothing returns boolean
    return ( udg_pnum == 0 )
endfunction

function Trig_Update_Board_Func003001 takes nothing returns boolean
    return ( udg_pnum == 1 )
endfunction

function Trig_Update_Board_Func004001 takes nothing returns boolean
    return ( udg_pnum == 2 )
endfunction

function Trig_Update_Board_Func005001 takes nothing returns boolean
    return ( udg_pnum == 3 )
endfunction

function Trig_Update_Board_Actions takes nothing returns nothing
     set udg_pnum = GetConvertedPlayerId(GetOwningPlayer     (GetKillingUnitBJ()))
    if ( Trig_Update_Board_Func002001() ) then
        set udg_p1kills = udg_p1kills + 1
        call LeaderboardSetPlayerItemValueBJ( GetOwningPlayer(GetKillingUnitBJ()), GetLastCreatedLeaderboard(), ( udg_p1kills ) )
    endif
    if ( Trig_Update_Board_Func003001() ) then
        set udg_p2kills = udg_p2kills + 1
        call LeaderboardSetPlayerItemValueBJ( GetOwningPlayer(GetKillingUnitBJ()), GetLastCreatedLeaderboard(), ( udg_p2kills ) )
    endif
    if ( Trig_Update_Board_Func004001() ) then
        set udg_p3kills = udg_p3kills + 1
        call LeaderboardSetPlayerItemValueBJ( GetOwningPlayer(GetKillingUnitBJ()), GetLastCreatedLeaderboard(), ( udg_p3kills ) )
    endif
    if ( Trig_Update_Board_Func005001() ) then
        set udg_p4kils = udg_p4kils + 1
        call LeaderboardSetPlayerItemValueBJ( GetOwningPlayer(GetKillingUnitBJ()), GetLastCreatedLeaderboard(), ( udg_p4kils ) )
    endif
    call LeaderboardSortItemsBJ( GetLastCreatedLeaderboard(), bj_SORTTYPE_SORTBYVALUE, false )
endfunction

//===========================================================================
function InitTrig_Update_Board takes nothing returns nothing
    set gg_trg_Update_Board = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Update_Board, Player(0), EVENT_PLAYER_UNIT_DEATH )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Update_Board, Player(1), EVENT_PLAYER_UNIT_DEATH )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Update_Board, Player(2), EVENT_PLAYER_UNIT_DEATH )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Update_Board, Player(3), EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddAction( gg_trg_Update_Board, function Trig_Update_Board_Actions )
endfunction

Some things to note.
I haven't taken the time to find the syntax they use for a switch statement which would be much nicer then the 4 separate if's.
When I declared my vars I made a typo in "p4kils" should have been "p4kills".

The basic logic is to keep track of all the kills by incrementing the proper value by 1 for each kill. The setting the value in the board for the new kill count.

I found no intrinsic function to get the current value for a leader board position. So after a while I gave up and decided to keep track of the values myself.
06-30-2002, 04:41 AM#5
Mr.123
IMO, life101's method is much cleaner, compact, and efficient. Why forgo arrays and use separate variables?

T0RRiCiTY:
You can't find it because you need to create a variable called kills of type "integer array". Then use the setvariable to set kills and set the index. The rest should be clear.
06-30-2002, 01:02 PM#6
Guest
Sure, it would be no problem to throw those into an array.

Oh. Now that you mentioned it, I see the only difference between ours was an array. The name "kills" being the array and the leader board threw me off in the initial one.
06-30-2002, 03:30 PM#7
Guest
OK, this should allow you to create a leader board very easily.

Create an Interger Array called "akills"

Create a new trigger named "Create Board"
Convert it to custom text and insert this code

Code:
function Trig_Create_Board_Func002002 takes nothing returns nothing
    call LeaderboardAddItemBJ( GetEnumPlayer(), GetLastCreatedLeaderboard(), GetPlayerName(GetEnumPlayer()), 0 )
endfunction

function Trig_Create_Board_Actions takes nothing returns nothing
    call CreateLeaderboardBJ( GetPlayersAll(), "TRIGSTR_017" )
    call ForForce( GetPlayersAll(), function Trig_Create_Board_Func002002 )
endfunction

//===========================================================================
function InitTrig_Create_Board takes nothing returns nothing
    set gg_trg_Create_Board = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_Create_Board, 3.00 )
    call TriggerAddAction( gg_trg_Create_Board, function Trig_Create_Board_Actions )
endfunction

Create another trigger called "Update Board"
and convert it to custom text
Paste in this code

Code:
function Trig_Update_Board_Actions takes nothing returns nothing
    set udg_akills[GetPlayerTeam(GetOwningPlayer(GetKillingUnitBJ()))] = ( udg_akills[GetPlayerTeam(GetOwningPlayer(GetKillingUnitBJ()))] + 1 )
    call LeaderboardSetPlayerItemValueBJ( GetOwningPlayer(GetKillingUnitBJ()), GetLastCreatedLeaderboard(), udg_akills[GetPlayerTeam(GetOwningPlayer(GetKillingUnitBJ()))] )
    call LeaderboardSortItemsBJ( GetLastCreatedLeaderboard(), bj_SORTTYPE_SORTBYVALUE, false )
endfunction

//===========================================================================
function InitTrig_Update_Board takes nothing returns nothing
    set gg_trg_Update_Board = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Update_Board, Player(0), EVENT_PLAYER_UNIT_DEATH )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Update_Board, Player(1), EVENT_PLAYER_UNIT_DEATH )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Update_Board, Player(2), EVENT_PLAYER_UNIT_DEATH )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Update_Board, Player(3), EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddAction( gg_trg_Update_Board, function Trig_Update_Board_Actions )
endfunction

Notes:
You'll need to fix some line breaks once you paste this.
The first triggers comments line shouldn't have a line break. The 2nd trigger has 3 lines and the comments line that need to have the line break remoed.
07-05-2002, 11:05 PM#8
Guest
I get this error whenever testing this -set kills[(Player number of (Owner of (killing unit)))] = (kills[(Player number of (Owner of (killing unit)))] + 1)
..

Line 50: Attempt to index a non-array variable
07-06-2002, 01:08 AM#9
Guest
Need to initalize the variable at some point before changing any of the values.
When you create the leaderboard, set the value of each element in the array to 0

You can do this in the GUI or you can use this code and place it in the action at start up

Code:
    set bj_forLoopAIndex = 0
    set bj_forLoopAIndexEnd = CountPlayersInForceBJ(GetPlayersAll())
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set udg_akills[GetForLoopIndexA()] = 0
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
07-06-2002, 02:31 AM#10
Mr.123
This may be obvious, but make sure you have the 'array' box checked in the variables menu.
07-06-2002, 03:36 PM#11
Guest
now it is invalid type for specified operator...
Whats going on!?
07-06-2002, 08:09 PM#12
Guest
forgot to add this, after i got the array thing working, or so I thought.
07-06-2002, 08:43 PM#13
Mr.123
Post the map? You shouldn't have a problem with operator errors.
07-06-2002, 11:18 PM#14
Guest
Ok It is no where near finished but if I post do you think you could fix it all up for me? Also, how exactly would I post it if I do?

lol, nm I just read your tutorial and got it all working thx alot man.