Page 1 of 1

Good way to start a script for all players?

Posted: Sun Mar 22, 2009 6:18 am
by Snocks
Hey

Im looking for a way to start a script for all players. I using pol 095 and I tried a way I thought would work.

Code: Select all

    local players := EnumerateOnlineCharacters();
    local numplayer := len(players);
    local player;

    local i := 0;

for (i := 1; i <= numplayer; i := i + 1)
	player := players[i];
    
    If (player.cmdlevel==0)

	start_script( "::XXX", player );
    endif
endfor
Wouldn't this code start the script on the first player, then move to the next one before that script finish? Cus right now it runs the script in the first player, but then it stops.

Re: Good way to start a script for all players?

Posted: Sun Mar 22, 2009 6:35 am
by mr bubbles
Yep that will start the script for each player. I see no problem with it.

Re: Good way to start a script for all players?

Posted: Sun Mar 22, 2009 6:38 am
by Snocks
mr bubbles wrote:Yep that will start the script for each player. I see no problem with it.
Will it wait for the script to finish? Because when I test it the script starts for just the first player.

Re: Good way to start a script for all players?

Posted: Sun Mar 22, 2009 6:53 am
by ncrsn
You may want to test another way to accomplish that. Basically it's the same but without all those neat variables. Documentation will tell you more about foreach statement if it's a new one to you.

Code: Select all

foreach player in EnumerateOnlineCharacters()
    if (player.cmdlevel == 0)
         Start_Script("::XXX", player);
    endif
endforeach
Also, using print function will help you to debug your scripts. E.g. adding print(i); inside the for loop would tell you for sure how many times the new script was launched.

Re: Good way to start a script for all players?

Posted: Sun Mar 22, 2009 7:05 am
by Snocks
ncrsn wrote:You may want to test another way to accomplish that. Basically it's the same but without all those neat variables. Documentation will tell you more about foreach statement if it's a new one to you.

Code: Select all

foreach player in EnumerateOnlineCharacters()
    if (player.cmdlevel == 0)
         Start_Script("::XXX", player);
    endif
endforeach
Also, using print function will help you to debug your scripts. E.g. adding print(i); inside the for loop would tell you for sure how many times the new script was launched.

Yeah, ill try that way :) Thanks, ill get back if it works :)

Re: Good way to start a script for all players?

Posted: Sun Mar 22, 2009 7:19 am
by mr bubbles
start_script doesn't wait for the script to finish, it just starts it then moves on.

Re: Good way to start a script for all players?

Posted: Mon Mar 23, 2009 2:16 am
by Gnafu
Do you have any setcritical() in your "::XXX" script?