How to use *addrid script command properly
Method 1: Exploits its multi-concurrent run
-> use *addrid right before ending the script
addrid will run multiple instances equal to number of player attached, which, not entirely a bad thing
when use properly, as shown below, don't have to use loop
prontera,155,179,5 script kickall 1_F_MARIA,{
if ( getgmlevel() < 99 ) end;
mes "I will kick all players after this dialog close";
mes "Exclude: autotrader, GMs, wondering in town.";
close2;
addrid 0;
if ( getgmlevel() >= 60 ) end; // don't kick GMs
if ( checkvending() & 2 ) end; // shouldn't kick @autotraders
if ( getmapflag( strcharinfo(3), mf_town ) ) end; // doesn't kick anyone in the town
atcommand "@kick "+ strcharinfo(0);
end;
}
Method 2: Get all the RID in an array
-> use donpcevent as calling a function, within that label, store the account IDs
the preferred method, this method is safe from running multiple instances
prontera,155,182,5 script getallusers 1_F_MARIA,{
donpcevent strnpcinfo(0)+"::OnGetAID"; // treat this as calling a function to get online player's account ID
for ( .@i = 0; .@i < .c; ++.@i )
announce (.@i +1)+". "+ rid2name(.aid[.@i]), bc_all;
end;
OnGetAID:
.c = 0;
addrid 0;
.aid[.c++] = getcharid(3);
end;
}
- script getallmap HIDDEN_NPC,{
end;
OnTest:
donpcevent strnpcinfo(0)+"::OnGetAID";
for ( .@i = 0; .@i < .c; ++.@i )
announce (.@i +1)+". "+ rid2name(.aid[.@i]), bc_all;
end;
OnGetAID:
.c = 0;
addrid 5, 0, "payon"; // only attach to everyone inside payon map
.aid[.c++] = getcharid(3);
end;
OnInit:
bindatcmd "test", strnpcinfo(0)+"::OnTest";
end;
}
guild_vs2,0,0,0 script getareausers HIDDEN_NPC,{
end;
OnTest:
donpcevent strnpcinfo(0)+"::OnGetAID";
for ( .@i = 0; .@i < .c; ++.@i )
announce (.@i +1)+". "+ rid2name(.aid[.@i]), bc_all;
end;
OnGetAID:
.c = 0;
addrid 4, 0, 46, 46, 53, 53; // attach everyone in the map 'guild_vs2' of (46,46,53,53) area
.aid[.c++] = getcharid(3);
end;
OnInit:
bindatcmd "test2", strnpcinfo(0)+"::OnTest";
end;
}