[Ajuda] loop ver membros
#1

To com problema ao criar um loop de ver os membros da facзгo, pq o loop roda 100 vezes (eu acho) o noem da mesma pessoa e fica floodando, o que eu fiz de errado?
Код:
	CMD:fmembers(playerid) {
		if(fmembro[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "You do not participate in a faction.");
		new string[30];
		new suafacid = fmembro[playerid];

		for(new i = 0; i < MAX_PLAYERS; i++)
		{
			if(fmembro[playerid] == suafacid) {
				format(string, sizeof(string), "%s %i", PlayerName(playerid), fcargo[playerid] );
				SendClientMessage(playerid, COLOR_WHITE, string);
			}
		}
		return 1;
	}
Reply
#2

Код:
	CMD:fmembers(playerid) {
		if(fmembro[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "You do not participate in a faction.");
		new string[30];
		new suafacid = fmembro[playerid];

		for(new i = 0; i < MAX_PLAYERS; i++)
		{
			if(fmembro[playerid] == suafacid) {
				format(string, sizeof(string), "%s %i", PlayerName(playerid), fcargo[playerid] );
				SendClientMessage(playerid, COLOR_WHITE, string);
			}
		}
		return 1;
	}
Deixei em negrito seu erro. Vocк estб verificando, a cada vez que o loop й executado, se o playerid (quem digitou o comando) й da facзгo suafacid, que й a prуpria facзгo do player. Vocк tem que verificar se o jogador atual (de ID i) й da facзгo.
Reply
#3

pawn Код:
CMD:fmembers(playerid) {
        if(fmembro[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "You do not participate in a faction.");
        new string[30];
        new suafacid = fmembro[playerid];

        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(fmembro[i] == suafacid) {
                format(string, sizeof(string), "%s %i", PlayerName(i), fcargo[i] );
                SendClientMessage(playerid, COLOR_WHITE, string);
            }
        }
        return 1;
    }
Reply
#4

Acredito que seria isso, ou nгo entendi a questгo.

pawn Код:
CMD:fmembers(playerid) {
        if(fmembro[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "You do not participate in a faction.");
        new string[30];
        new suafacid = fmembro[playerid];

        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(fmembro[playerid] == fmembro[i]) {
                format(string, sizeof(string), "%s %i", PlayerName(playerid), fcargo[playerid] );
                SendClientMessage(playerid, COLOR_WHITE, string);
            }
        }
        return 1;
    }
Reply
#5

pawn Код:
#include <foreach>

CMD:fmembers(playerid)
{
    if(fmembro[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "You do not participate in a faction.");

    new string[30], suafacid = fmembro[playerid];
    foreach(new i: Player)
    {
        if(fmembro[playerid] != fmembro[i]) continue;

        format(string, sizeof(string), "%s %i", PlayerName(playerid), fcargo[playerid] );
        SendClientMessage(playerid, COLOR_WHITE, string);
    }
    return 1;
}
Reply
#6

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
pawn Код:
#include <foreach>

CMD:fmembers(playerid)
{
    if(fmembro[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "You do not participate in a faction.");

    new string[30], suafacid = fmembro[playerid];
    foreach(new i: Player)
    {
        if(fmembro[playerid] != fmembro[i]) continue;

        format(string, sizeof(string), "%s %i", PlayerName(playerid), fcargo[playerid] );
        SendClientMessage(playerid, COLOR_WHITE, string);
    }
    return 1;
}
Imbecilidade adicionar uma include dessas para um simples comando.


Se quer otimizaзгo, faзa do modo correcto!
pawn Код:
CMD:fmembers(playerid){

        if(!fmembro[playerid])
            return SendClientMessage(playerid, COLOR_RED, "You do not participate in a faction.");

        static
            string[30], m, i
        ;

        for(m = GetMaxPlayers(), i = 0; i ^ m; ++i){

            if(!(fmembro[playerid]  ^ fmembro[i])){

                SendClientMessage(playerid, -1, (format(string, 30, "%s %i", PlayerName(playerid), fcargo[playerid] ), string));
            }
        }

        return 1;
    }
Reply
#7

Quote:
Originally Posted by zSuYaNw
Посмотреть сообщение
Imbecilidade adicionar uma include dessas para um simples comando.


Se quer otimizaзгo, faзa do modo correcto!
pawn Код:
CMD:fmembers(playerid){

        if(!fmembro[playerid])
            return SendClientMessage(playerid, COLOR_RED, "You do not participate in a faction.");

        static
            string[30], m, i
        ;

        for(m = GetMaxPlayers(), i = 0; i ^ m; ++i){

            if(!(fmembro[playerid]  ^ fmembro[i])){

                SendClientMessage(playerid, -1, (format(string, 30, "%s %i", PlayerName(playerid), fcargo[playerid] ), string));
            }
        }

        return 1;
    }
Vocк й o ъnico que deve aprender a fazк-lo corretamente.

Atualize-se, hб uma nova funзгo; uma funзгo que vocк claramente nгo saiba. ---> https://sampwiki.blast.hk/wiki/GetPlayerPoolSize <---.

Vocк tambйm tem que verificar se um jogador estб conectado ao realizar esse tipo de loops, onde claramente nгo o fazer. Tambйm ' foreach', sendo uma inclusгo que lida com iteradores, й muito mais rбpido do que o seu cуdigo "mais otimizado".
Reply
#8

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
Vocк й o ъnico que deve aprender a fazк-lo corretamente.

Atualize-se, hб uma nova funзгo; uma funзгo que vocк claramente nгo saiba. ---> https://sampwiki.blast.hk/wiki/GetPlayerPoolSize <---.

Vocк tambйm tem que verificar se um jogador estб conectado ao realizar esse tipo de loops, onde claramente nгo o fazer. Tambйm ' foreach', sendo uma inclusгo que lida com iteradores, й muito mais rбpido do que o seu cуdigo "mais otimizado".
Nгo entendeu o raciocнnio lуgico?
https://en.wikipedia.org/wiki/Logic_programming


OK ok.. Para usar a nossa querida inclusгo "foreach" ele teria que adicionar funзхes no OnPlayerConnect e OnPlayerDisconnect.. teria tambйm que modificar todos os loops do servidor para ter uma rapidez notбvel.

Em relaзгo a include GetPlayerPoolSize, й uma funзгo legal e eu nгo sabia.

Serб que vale a pena modificar todos os loops por um programa?

Forзar alguйm usar uma include por causa de um comando nгo irб ajudar, apenas irб complicar entгo arrume seus argumentos, pense bem e volte aqui quando tiver algo formado.
Reply
#9

Quote:
Originally Posted by zSuYaNw
Посмотреть сообщение
Nгo entendeu o raciocнnio lуgico?
https://en.wikipedia.org/wiki/Logic_programming


OK ok.. Para usar a nossa querida inclusгo "foreach" ele teria que adicionar funзхes no OnPlayerConnect e OnPlayerDisconnect.. teria tambйm que modificar todos os loops do servidor para ter uma rapidez notбvel.

Em relaзгo a include GetPlayerPoolSize, й uma funзгo legal e eu nгo sabia.

Serб que vale a pena modificar todos os loops por um programa?

Forзar alguйm usar uma include por causa de um comando nгo irб ajudar, apenas irб complicar entгo arrume seus argumentos, pense bem e volte aqui quando tiver algo formado.
Se vocк nгo tem uma ъnica idйia do que foreach faz, como funciona ou nada sobre isso, eo que vocк estб falando de um modo geral, vocк provavelmente deve manter seus argumentos para si mesmo.

GetPlayerPoolSize () й uma SA:MP nativa! E nгo й ilegal!!!

O laзo que eu usei em que os loops de comando apenas atravйs de jogadores conectados e vocк nгo tem que mudar qualquer um dos seus loops ou adicionar qualquer cуdigo externo que seja!!!

Se vocк nгo pode obtк-lo direito, nгo faзa outros corretas, quando vocк estб claramente errado!!!

~ ****** translate, speak English or Spanish?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)