[b]Rampage[/b],
//===========================================================================
// A simple handle counter that shows:
// * Maximum handles reached
// * Elapsed seconds
//
//========== FOR VERSION 1.24+ ONLY ==========
//
// The leaderboard can be accessed with
// HandleCounter_LEADERBOARD
// The clock (timer) can be accessed with
// HandleCounter_CLOCK
//
// This could be useful only if you'd like to see
// if your map is leaking a lot of handles.
// Otherwise it isn't really needed.
//
// Requires a vJASS compiler to work.
//
// To use:
// Create a trigger named HandleCounter,
// convert to custom script and paste this.
//===========================================================================
library HandleCounter initializer Init
//===========================================================================
// Configurables
//===========================================================================
globals
// Leaderboard title/name.
private constant string TITLE = "Handle Counter"
// Text that represents the time.
private constant string TIME_TEXT = "Elapsed Time:"
// Should the leaderboard show time as well? True or false.
private constant boolean SHOW_TIME = true
// How often should the handle count update (of course this is not for the clock).
private constant real UPDATE_PERIOD = 0.25
// Number of locations created for better counting result.
private constant integer STACK_END_TRESHOLD = 15
// Player(0) = Player 1 (Red); Player(1) = Player 2 (Blue); etc.
// Player color of the maximum handles text.
private constant player MAX = Player(0)
// Player color of the time text.
private constant player TIME = Player(1)
endglobals
//===========================================================================
// Do not edit bellow this point unless you know what you're doing.
//===========================================================================
globals
public leaderboard LEADERBOARD = null
public timer CLOCK = null
private integer CURRENT_HANDLE = 0
private integer MAX_HANDLE = 0
private integer SECONDS = 0
endglobals
private function UpdateTime takes nothing returns nothing
set SECONDS = SECONDS + 1
call LeaderboardSetItemLabel(LEADERBOARD, 1, TIME_TEXT)
call LeaderboardSetItemValue(LEADERBOARD, 1, SECONDS)
endfunction
private function Callback takes nothing returns nothing
local location array loc
local integer a = 0
local integer index
local integer prevIndex = 0
local integer next = 0
loop
set loc[a] = Location(0., 0.)
set index = GetHandleId(loc[a]) - 0x100000
set a = a + 1
if index == prevIndex + 1 then
set next = next + 1
else
set next = 0
endif
set prevIndex = index
exitwhen next >= STACK_END_TRESHOLD
endloop
call LeaderboardSetItemValue(LEADERBOARD, 0, index - a)
loop
set a = a - 1
call RemoveLocation(loc[a])
set loc[a] = null
exitwhen a <= 0
endloop
endfunction
private function Actions takes nothing returns nothing
local timer tim = GetExpiredTimer()
set LEADERBOARD = CreateLeaderboard()
call LeaderboardSetLabel(LEADERBOARD, TITLE)
call PlayerSetLeaderboard(GetLocalPlayer(), LEADERBOARD)
call LeaderboardDisplay(LEADERBOARD, true)
call TimerStart(tim, UPDATE_PERIOD, true, function Callback)
call LeaderboardAddItem(LEADERBOARD, "Max Handles", 0, MAX)
call LeaderboardSetSizeByItemCount(LEADERBOARD, 1)
if SHOW_TIME then
set CLOCK = CreateTimer()
call TimerStart(CLOCK, 1., true, function UpdateTime)
call LeaderboardAddItem(LEADERBOARD, "", 1, TIME)
// Prevent leaderboard showing "1" during the first second.
call LeaderboardSetItemLabel(LEADERBOARD, 1, TIME_TEXT)
call LeaderboardSetItemValue(LEADERBOARD, 1, SECONDS)
call LeaderboardSetSizeByItemCount(LEADERBOARD, 2)
endif
set tim = null
endfunction
private function Init takes nothing returns nothing
call TimerStart(CreateTimer() , 0., false, function Actions)
endfunction
endlibrary