[Tutorial] Radar de Pessoas
#1

Olб galera, tudo bem? Bom, esse й o meu primeiro tutorial em nнvel iniciante, isso mesmo, iniciante porque pra fazer isso й a coisa mais simples que tem no pawno, porйm pouca gente desconhece. Vou ensinar б vocкs como criar modificar o Radar do GTA, fazendo sumir os pontos de X pessoa e aparecer para Y pessoa. Parece complicado, mas nгo й.

Primeiramente, a gente utiliza um Timer de checagem + uma public.

pawn Код:
//OnGameModeInit:
SetTimer("AtualizarRadar",2000,1);

forward AtualizarRadar();
public AtualizarRadar()
{
    return 1;
}
Bom, definimos a public com um tempo de 2 segundos de checagem. Vocк pode alterar o valor, pra 1000 ou mais se quiser...

Agora as funзхes que a gente utiliza nessa coisinha de Deus:

- Uma funзгo de checagem de Distвncia de X player a Y player.
- Utilizamos o valor do SA-MP chamado SetPlayerMarkerForPlayer(playerid,targetid,color);

Bom, vamos lб?

pawn Код:
public AtualizarRadar()
{
    for ( new i = 0; i < MAX_PLAYERS; i ++ )
    {
        if(IsPlayerConnected(i))
        {
            new Float:playerPos[3];
            new Float:targetPos[3];
            GetPlayerPos(i,playerPos[0],playerPos[1],playerPos[2]);

            for ( new j = 0; j < MAX_PLAYERS; j ++ )
            {
                if(IsPlayerConnected(j) && j != i)
                {
                    GetPlayerPos(j,targetPos[0],targetPos[1],targetPos[2]);
                    new distancia;
               
                    //Fуrmula da Distвncia entre 2 X.
                    distancia = floatround(floatsqroot(floatpower(floatabs(floatsub(playerPos[0],targetPos[0])),2)+floatpower(floatabs(floatsub(playerPos[1],targetPos[1])),2)));

                    if(distancia <= 200) // Distancia й menor que 200 metros, vamos fazer o jogador sumir no mapa do outro
                    {
                        SetPlayerMarkerForPlayer(i,j,(GetPlayerColor(j) & 0xFFFFFF00));
                    }
                    else // Caso nгo, ele aparece no mapa
                    {
                        SetPlayerMarkerForPlayer(i,j,GetPlayerColor(j));
                    }
                }
            }
        }
    }
    return 1;
}
Caso vocк nгo entendeu porque daquele valor com & nas cores, verifique isto na Wiki SA-MP: https://sampwiki.blast.hk/wiki/SetPlayerMarkerForPlayer

Bom, й isso ai, um simples exemplo de como fazer sumir e aparecer o jogador. Agora, vamos viajar um pouco? Vamos fazer que um cara do TEAM_LEI pode enxergar os outros no radar somente pelo level de procurado?

Acompanhe:

pawn Код:
//Topo
#define TEAM_LEI 0

public AtualizarRadar()
{
    for ( new i = 0; i < MAX_PLAYERS; i ++ )
    {
        if(IsPlayerConnected(i))
        {
            new Float:playerPos[3];
            new Float:targetPos[3];
            GetPlayerPos(i,playerPos[0],playerPos[1],playerPos[2]);

            for ( new j = 0; j < MAX_PLAYERS; j ++ )
            {
                if(IsPlayerConnected(j) && j != i)
                {
                    GetPlayerPos(j,targetPos[0],targetPos[1],targetPos[2]);
                    new distancia;
               
                    //Fуrmula da Distвncia entre 2 X.
                    distancia = floatround(floatsqroot(floatpower(floatabs(floatsub(playerPos[0],targetPos[0])),2)+floatpower(floatabs(floatsub(playerPos[1],targetPos[1])),2)));
   
                    if(GetPlayerTeam(i) == TEAM_LEI && GetPlayerTeam(j) != TEAM_LEI)
                    {
                        switch(GetPlayerWantedLevel(j))
                        {
                            case 0: SetPlayerMarkerForPlayer(i,j,0xF6F669AA); // Amarelo bem fraquinho
                            case 1: SetPlayerMarkerForPlayer(i,j,0xF6F62EAA); // Amarelo Fraco
                            case 2: SetPlayerMarkerForPlayer(i,j,0xF6F600AA); // Amarelo Mйdio
                            case 3: SetPlayerMarkerForPlayer(i,j,0xF6C600AA); // Amarelo
                            case 4: SetPlayerMarkerForPlayer(i,j,0xE5B700AA); // Amarelo Forte
                            case 5: SetPlayerMarkerForPlayer(i,j,0xE58400AA); // Laranja
                            case 6: SetPlayerMarkerForPlayer(i,j,0xE51E00AA); // Vermelho
                        }
                    }
                }

                else
                {

                    if(distancia <= 200) // Distancia й menor que 200 metros, vamos fazer o jogador sumir no mapa do outro
                    {
                        SetPlayerMarkerForPlayer(i,j,(GetPlayerColor(j) & 0xFFFFFF00));
                    }
                    else // Caso nгo, ele aparece no mapa
                    {
                        SetPlayerMarkerForPlayer(i,j,GetPlayerColor(j));
                    }
                }
            }
        }
    }
    return 1;
}
Entendendo o Biribondo do cуdigo:

Temos uma comparaзгo, de que se o Player (i) estar no time 0 (TEAM_LEI) e o Target (j) nгo estiver no time 0 (TEAM_LEI), ele vai aparecer segundo as cores do seu Level de procurado. As cores que escolhi foi uma variaзгo entre Amarelo, Laranja e Vermelho.

Bom, й isso ai galera. Fiz o tuto correndo, deve ter uns errinhos bбsicos ai e algumas coisinhas que dб para arrumar e optimizar mais... Enfim, aprendi isso lendo, vendo e quebrando a cara...

Entгo, dб para vocкs viajarem nesses codes. Dб para fazer que um admin enxergue os players de acordo com a ameaзa (Total de Reports), que os players nгo enxerguem administradores... enfim...

Qualquer erro assustador, й sу gritar.
Reply


Messages In This Thread
Radar de Pessoas - by LuaN_ - 08.03.2011, 13:06
Re: Radar de Pessoas - by Falcon. - 08.03.2011, 14:28
Re: Radar de Pessoas - by Kruger - 08.03.2011, 14:46
Re: Radar de Pessoas - by [Ips]Guh - 08.03.2011, 14:53
Re: Radar de Pessoas - by LuaN_ - 08.03.2011, 17:00
Re: Radar de Pessoas - by telmo_ferreira - 10.04.2011, 11:11
Re: Radar de Pessoas - by Edu33 - 20.05.2012, 11:24
Re: Radar de Pessoas - by Psat - 20.05.2012, 11:27
Re: Radar de Pessoas - by DrTHE - 20.05.2012, 12:47

Forum Jump:


Users browsing this thread: 1 Guest(s)