Jump to content
  • 0
luizragna

Script command execute for all players in the map

Question

5 answers to this question

Recommended Posts

  • 0

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.

Share this post


Link to post
Share on other sites
  • 0

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.

And not one in each.
Edited by luizragna

Share this post


Link to post
Share on other sites
  • 0

@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()

Share this post


Link to post
Share on other sites
  • 0

Thank you, guys!

 

The full script:

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;
	
}

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.