// my improved counting sort, idea from keyworld <3
// http://herc.ws/board/topic/4321-help-me-improve-this-merge-sort-algorithm/?do=findComment&comment=28247
// callfunc "counting_sort_index_desc", <input array>, <output array>, <total index>;
function script counting_sort_index_desc {
for ( .@i = 0; .@i < .@size; ++.@i ) {
setd ".@index_"+ .@arr
[.@i
] +"["+( .@tmp
[.@arr
[.@i
]] )+"]", .@i;
++.@tmp[.@arr[.@i]];
}
for ( ; .@size; --.@size ) {
--.@tmp[.@index];
.@out
[.@total
- .@size
] = getd( ".@index_"+ .@index
+"["+( .@tmp
[.@index
] )+"]" );
}
return;
}
prontera,150,180,5 script Top Hunter 1_F_MARIA,{
if ( .start == false ) {
mes "registration closed";
}
if ( getgmlevel() >
= 99 ) { // GMs should skip registration. MAKE SURE Turn this off if you are debugging this script with GM account
}
if ( .register_count >= 100 ) {
mes "only accept 100 registration";
}
.
register_aid[.
register_count++] = getcharid(3);
OnInit:
OnStart:
OnClock1030: // put all start timer here
OnClock2314:
.start = true;
mapwarp "guild_vs2",
"prontera",
156,
191;
announce "Top Hunter event started ~ accepting registrations ",
bc_all;
sleep 20000;
// 20 seconds to register, to debug this script of course
announce "Top Hunter event registration closed",
bc_all;
.start = false;
if ( .register_count < 3 ) {
announce "Top Hunter event aborted ... not enough players to start this event",
bc_all;
mapwarp "guild_vs2",
"prontera",
156,
191;
}
sleep 60000;
// event runs 60 seconds
mapannounce "guild_vs2",
"Top Hunter: Times Up~",
bc_all;
// here comes the magic ~ save all participants killcount into a temporary array
for ( .@i = 0; .@i < .register_count; ++.@i ) {
.@aid[.@i] = .register_aid[.@i];
.@killed[.@i] = @tophunter_killcount;
@tophunter_killcount = 0;
}
// magic !! sort the array from biggest number to smallest number, output in index format
callfunc "counting_sort_index_desc", .@killed, .@s, .
register_count;
/* announce "Top hunter Script Debugging Mode - List all players' killcount sorted", bc_all;
for ( .@i = 0; .@i < .register_count; ++.@i )
announce "No."+( .@i +1 )+" : "+ .@name$[ .@s[.@i] ] +" ["+ .@aid[ .@s[.@i] ]+"] with "+ .@killed[ .@s[.@i] ]+" kills.", bc_all;
announce " ====== ", bc_all;
*/
for ( .@i = 0; .@i < 3; ++.@i ) {
if ( .@killed[ .@s[.@i] ] ) { // must make at least 1 kill
.@winnername$[.@i] = .@name$[ .@s[.@i] ];
getitem 501,
10, .@aid
[ .@s
[.@i
] ];
// give 10 red potions to these winners
}
}
if ( .@killed[.@s[0]] )// make sure even the top place has score a kill
announce "Top Hunter: The Top Hunters are ["+ implode( .@winnername$,
"],[" )+"] !",
bc_all;
else
announce "Top Hunter: WOOT ! Every one just come in here and AFK ??",
bc_all;
mapwarp "guild_vs2",
"prontera",
156,
191;
.register_count = 0;
OnMobDead:
++@tophunter_killcount;
OnPCLogoutEvent:
for ( .@i = 0; .@i < .register_count; ++.@i ) {
--.register_count;
}
}
}
}
guild_vs2 mapflag nowarp
guild_vs2 mapflag nowarpto
guild_vs2 mapflag noteleport
guild_vs2 mapflag nomemo
guild_vs2 mapflag nopenalty
guild_vs2 mapflag noicewall
guild_vs2 mapflag nobranch