SA-MP Forums Archive
[Off] Qual a melhor forma de criar uma Loop. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Non-English (https://sampforum.blast.hk/forumdisplay.php?fid=9)
+--- Forum: Languages (https://sampforum.blast.hk/forumdisplay.php?fid=33)
+---- Forum: Português/Portuguese (https://sampforum.blast.hk/forumdisplay.php?fid=34)
+---- Thread: [Off] Qual a melhor forma de criar uma Loop. (/showthread.php?tid=599759)



Qual a melhor forma de criar uma Loop. - [BOPE]Seu._.Madruga - 29.01.2016

Olб galera boa noite a todos, bom eu queria saber qual a melhor forma de criar uma loop que tenha inicio 0 e o final seja a quantidade de players online.
Porйm uma loop de forma mais rбpida existe essa possнvel forma?

PHP код:
for(new 0MAX_PLAYERSi++)
{

PHP код:
for(new 0GetMaxPlayers(); ++i)
{




Re: Qual a melhor forma de criar uma Loop. - SickAttack - 30.01.2016

pawn Код:
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i ++)
{
    if(!IsPlayerConnected(i))
    {
        continue;
    }

    // ...
}



Re: Qual a melhor forma de criar uma Loop. - Kuddy - 30.01.2016

Usar MAX_PLAYERS й mais barato para o processamento, jб que vocк estб usando uma macro e nгo uma funзгo.

Se quer mais velocidade e mais praticidade, utilize o "foreach" do ******.


Re: Qual a melhor forma de criar uma Loop. - JonathanFeitosa - 30.01.2016

GetPlayerPoolSize


Re: Qual a melhor forma de criar uma Loop. - De4gle - 30.01.2016

GetPlayerPoolSize mas ele pega o ID mais alto online ou seja ele pode passar por jogadores desconectados, use foreach se quiser mais eficiкncia e velocidade alйm da vantagem de nгo precisar verificar se o player estб conectado pois ele pega apenas os conectados


Re: Qual a melhor forma de criar uma Loop. - Coringa_Vilao - 30.01.2016

use foreach recomendo , pega apenas os jogadores online ...


Re: Qual a melhor forma de criar uma Loop. - Monotox - 30.01.2016

GetPlayerPoolSize, tambйm acho interessante adicionar que tambйm existe para os veнculos GetVehiclePoolSize.

Код:
FreezeAll()
{
    for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++) // note that we assign the return value to a new variable (j) to avoid calling the function with each iteration
    {
        TogglePlayerControllable(i, 0);
    }
}
Код:
RepairAllVehicles()
{
    for(new i = 1, j = GetVehiclePoolSize(); i <= j; i++) // vehicleids start at 1
    {
        RepairVehicle(i);
    }
}