// callfunc "shuffle", <min num>, <max num>, <output array> {, <count> };
function script shuffle {
.@static = getarg(0);
.@range = getarg(1) +1 - .@static;
.@count = getarg(3, 0);
if ( .@range <= 0 )
return 0;
if ( !.@count || .@count > .@range )
.@count = .@range;
while ( .@i < .@count ) {
.@r = .@save = rand( .@i, .@range -1 ) ;
if ( !.@tmp1[.@i] ) {
.@r = .@tmp1[.@r] ? .@tmp2[.@r] : .@r;
.@tmp2[.@i] = .@r;
.@tmp2[.@save] = .@i;
.@tmp1[.@save] = 1;
set getelementofarray( getarg(2), .@i ), .@r + .@static;
set getelementofarray( getarg(2), .@save ), .@i + .@static;
}
.@i++;
}
return .@count;
}
- script dkfdjhsfkjs -1,{
OnInit:
bindatcmd "test", strnpcinfo(0)+"::Onooo", 99,100;
bindatcmd "qwer", strnpcinfo(0)+"::Onaaa", 99,100;
bindatcmd "asdf", strnpcinfo(0)+"::Onbbb", 99,100;
end;
Onooo:
getservermember 0;
for ( .@i = 0; .@i < $@servermembercount; .@i++ )
dispbottom $@servermembername$[.@i];
end;
Onaaa:
// while ( .@i++ < 100 ) { // ran a test with 100 times
getservermember 2;
.@winneraid = $@servermemberaid[ rand( $@servermembercount ) ];
announce "Winner is "+ rid2name( .@winneraid ), bc_all;
getitem 501, 1, .@winneraid;
// }
end;
Onbbb:
// while ( .@j++ < 100 ) { // ran a test with 100 times
getservermember 2;
callfunc "shuffle", 0, $@servermembercount -1, .@r;
for ( .@i = 0; .@i < $@servermembercount; .@i++ ) {
attachrid $@servermemberaid[ .@r[.@i] ];
if ( getgmlevel() < 60 && checkvending() != 2 ) {
announce "Winner is "+ strcharinfo(0), bc_all;
getitem 501, 1;
break;
}
}
// }
end;
}