Script command execute for all players in the map

First use getunits() to capture all players on the map in an array.
Then loop through the array using the for() function.

Sample:

.@count = getunits(BL_PC, .@units, false, "prontera"); // Adds all BL_PC on prontera type to the array .@units
for (.@i = 0; .@i < .@count; .@i++)
debugmes(sprintf("%s", rid2name(.@units[.@i]))); // Prints a debug msg in console of the player name


It's returning their Account ID btw.

 
Last edited by a moderator:
I tried:

.@count = getunits(BL_PC, .@units, false, "prontera"); // Adds all BL_PC on prontera type to the array .@units

for (.@i = 0; .@i < .@count; .@i++){
mes "Hello";
close;
}




But he just ran the command 2 times in the same player.

Code:
And not one in each.
 
Last edited by a moderator:
@luizragna this because mes() and most commands only run for the attached player. If you want to run it for another player you will have to attachrid(.@units[.@i]); or addtimer(0, "MyNPC::MyEvent", .@units[.@i]);

If you go for the timer approach you might as well just use maptimer()

 
Last edited by a moderator:
Thank you, guys!

The full script:

Code:
universe,40,40,4	script	Tester#OP	4_M_REINDEER,{

.@count = getunits(BL_PC, .@units, false, "universe"); // Adds all BL_PC on prontera type to the array .@units

for (.@i = 0; .@i < .@count; .@i++)
	addtimer(0, "Tester#OP::OnMyEvent", .@units[.@i]);
	
end;

OnMyEvent:
mes "Hello";
close;
	
}
 
Back
Top