SA-MP Forums Archive
Help making a global play command please - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Help making a global play command please (/showthread.php?tid=331101)



Help making a global play command please - lsfmd - 03.04.2012

Im trying to make a global play command for 0.3d's built in PlayAudioStreamForPlayer function, but I dont know how to go about doing it. Could anyone assist me? Im making the command /gplay [link here]


Re: Help making a global play command please - blank. - 03.04.2012

pawn Код:
for(new i = 0;i<MAX_PLAYERS;i++)
    {
    if(IsPlayerConnected(i))
        {
        PlayAudioStreamForPlayer(i,"url");
        }
    }



Respuesta: Help making a global play command please - Marricio - 03.04.2012

pawn Код:
foreach(Player, i)
    PlayAudioStreamForPlayer( i, url );



Re: Help making a global play command please - aRoach - 03.04.2012

pawn Код:
for( new slots = GetMaxPlayers( ), i; i < slots; i++ )
{
    if ( !IsPlayerConnected( i ) ) continue;

    PlayAudioStreamForPlayer( i, "URL" );
}
Fastest plain player-loop...
PS: Not faster than foreach...


Re: Help making a global play command please - PrawkC - 03.04.2012

Quote:
Originally Posted by aRoach
Посмотреть сообщение
pawn Код:
for( new slots = GetMaxPlayers( ), i; i < slots; i++ )
{
    if ( !IsPlayerConnected( i ) ) continue;

    PlayAudioStreamForPlayer( i, "URL" );
}
Fastest plain player-loop...
PS: Not faster than foreach...
This would be faster, using MAX_PLAYERS or any variable defining the slots is faster than having to call GetMaxPlayers();

Код:
for(new i; i < MAX_PLAYERS; i++)
{
	if(!IsPlayerConnected(i))
		continue;

	PlayAudioSteamForPlayer(i, "url");
}



Re: Help making a global play command please - aRoach - 03.04.2012

Nope... GetMaxPlayers get exactly the number of max players, MAX_PLAYERS is only a define that, default is '500', the fastest is mine...
There is a prove: https://sampforum.blast.hk/showthread.php?tid=216730


Re: Help making a global play command please - PrawkC - 03.04.2012

Quote:
Originally Posted by aRoach
Посмотреть сообщение
Nope... GetMaxPlayers get exactly the number of max players, MAX_PLAYERS is only a define that, default is '500', the fastest is mine...
There is a prove: https://sampforum.blast.hk/showthread.php?tid=216730
Its not faster, there was a thread comparing GetMaxPlayers to defines and it was proven that it is slower to use GetMaxPlayers, It is indeed faster to use a number than a function.


Re: Help making a global play command please - aRoach - 03.04.2012

Dude, the loop repeat 500 times, when you use the Define.
When you use GetMaxPlayers, the loop will repeat only .. times....


Re: Help making a global play command please - blank. - 03.04.2012

Quote:
Originally Posted by aRoach
Посмотреть сообщение
Dude, the loop repeat 500 times, when you use the Define.
When you use GetMaxPlayers, the loop will repeat only .. times....
pawn Код:
#undef MAX_PLAYERS
#define MAX_PLAYERS 50



Re: Help making a global play command please - IstuntmanI - 03.04.2012

Quote:
Originally Posted by aRoach
Посмотреть сообщение
Dude, the loop repeat 500 times, when you use the Define.
When you use GetMaxPlayers, the loop will repeat only .. times....
Код:
for( new slots = GetMaxPlayers( ), i; i < slots; i++ )
{
    if ( !IsPlayerConnected( i ) ) continue;

    PlayAudioStreamForPlayer( i, "URL" );
}
faster:
Код:
for( new i = GetMaxPlayers( ); i < slots; i++ )
{
    if ( !IsPlayerConnected( i ) ) continue;

    PlayAudioStreamForPlayer( i, "URL" );
}
You are creating slots variable and i variable in loop instead of only one variable doing the same...

And if you have MAX_PLAYERS defined as your max players slots, it's faster than GetMaxPlayers.

EDIT: 3 replies at -almost- same time, lol.