library HandleCounter initializer Init
// ________________________________________
// +----------------------------------------+
// | H A N D L E C O U N T E R v1 |
// +----------------------------------------+
// | By Romek - For his Demo Map |
// |________________________________________|
// +----------------------------------------+
// Frankly, I don't care about the efficiency of a handle counter.
// Nor do I care about how well a temporary script is coded. <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue :p" loading="lazy" data-shortname=":p" />
globals
private leaderboard LB
private location array Loc
private constant integer DEC = 0x100000
private integer Last = DEC * DEC
private integer Curr = 0
private integer Change = 0
endglobals
private struct T extends array
static integer S = 0
static integer M = 0
static integer H = 0
static string SS = "00"
static string MS = "00"
static string HS = "00"
endstruct
private function H2I takes handle h returns integer
return h
return 0
endfunction
private function Expire takes nothing returns nothing
local integer i = 0
set T.S = T.S + 1
if T.S > 60 then
set T.S = 1
set T.M = T.M + 1
if T.M >= 10 then
set T.MS = I2S(T.M)
else
set T.MS = "0" + I2S(T.M)
endif
endif
if T.M > 60 then
set T.M = 1
set T.H = T.H + 1
if T.H >= 10 then
set T.HS = I2S(T.H)
else
set T.HS = "0" + I2S(T.H)
endif
endif
if T.S >= 10 then
set T.SS = I2S(T.S)
else
set T.SS = "0" + I2S(T.S)
endif
call LeaderboardSetItemLabel(LB, 2, " " + T.HS + ":" + T.MS + ":" + T.SS)
loop
set i = i + 1
set Loc<i> = Location(0., 0.)
exitwhen i == 100
endloop
set Curr = (H2I(Loc[100]) - DEC) - 100
call LeaderboardSetItemValue(LB, 0, Curr)
loop
call RemoveLocation(Loc<i>)
set Loc<i> = null
set i = i - 1
exitwhen i < 0
endloop
set Change = Curr - Last
set Last = Curr
if Change > 0 then
call LeaderboardSetItemValue(LB, 1, Change)
call LeaderboardSetItemValueColor(LB, 1, 0xFF, 0, 0, 0xFF)
else
call LeaderboardSetItemValue(LB, 1, Change)
call LeaderboardSetItemValueColor(LB, 1, 0, 0xFF, 0, 0xFF)
endif
endfunction
private function Start takes nothing returns nothing
set LB = CreateLeaderboard()
//call LeaderboardSetLabel(LB, " Handle Counter:")
call LeaderboardSetLabel(LB, "")
call PlayerSetLeaderboard(GetLocalPlayer(), LB)
call LeaderboardAddItem(LB, "Handles:", 0, Player(15))
call LeaderboardAddItem(LB, "Change:", 0, Player(15))
call LeaderboardAddItem(LB, " 00:00:00", 0, Player(15))
// Colours of the LABELS
call LeaderboardSetItemLabelColor(LB, 0, 0xFF, 0xDF, 0x00, 0xFF) // Handles
call LeaderboardSetItemLabelColor(LB, 1, 0x00, 0xB7, 0xEB, 0xFF) // Changed
call LeaderboardSetItemLabelColor(LB, 2, 0x77, 0x77, 0x77, 0xFF) // Time
// Colours of the ITEMS. (Except 'Changed:')
call LeaderboardSetItemValueColor(LB, 0, 0xFF, 0xFF, 0xFF, 0xFF)
call LeaderboardSetItemValueColor(LB, 2, 13, 33, 37, 0) // Making the Time one invisible
call LeaderboardSetSizeByItemCount(LB, 2)
call LeaderboardDisplay(LB, true)
call TimerStart(GetExpiredTimer(), 1., true, function Expire)
endfunction
private function Init takes nothing returns nothing
call TimerStart(CreateTimer(), 0., false, function Start)
endfunction
endlibrary</i></i></i>
Handles which are extended by the new type agent need to be nulled, as they leak.