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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

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