[Ajuda] Usar else
#1

Galera me ajudem a usar o else eu tento usar else mais bugou o comando *--*
Por favor explique tbm
O jeito que eu tentei fazer:

pawn Код:
COMMAND:tapa(playerid, params[])
{
    new Msg[128], Name[24], AdminName[24], OtherPlayer;
    SendAdminText(playerid, "/tapa", params);
    if (APlayerData[playerid][LoggedIn] == true)
    {

        if (APlayerData[playerid][PlayerLevel]  < 2)
        {

            if (sscanf(params, "u", OtherPlayer)) SendClientMessage(playerid, 0xFF0000AA, "Use: /tapa [id]");

            if (IsPlayerConnected(OtherPlayer))
            {

                GetPlayerName(playerid, AdminName, sizeof(AdminName));
                GetPlayerName(OtherPlayer, Name, sizeof(Name));
                new player1;
                player1 = OtherPlayer;
                new Float:tapax;
                new Float:tapay;
                new Float:tapaz;
                GetPlayerPos(player1, tapax, tapay, tapaz);
                SetPlayerPos(player1, tapax, tapay, tapaz+10);
                format(Msg, 128, "{FF0000}{FFFF00}[INFO] {FF0000}O Administrador %s deu um tapa em %s", AdminName, Name);
                SendClientMessageToAll(0xFFFFFFFF, Msg);
                PlayerFile_Save(OtherPlayer);
            }
            else
            SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}[ERRO] {FF0000}Esse jogador nгo se encontra online!");
        }
        else
        SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}[ERRO] {FF0000}Vocк nгo tem permissгo para usar esse comando!");
    }
    return 0;
}
Reply
#2

Vocк estб invertendo as coisas.
Reply
#3

Quote:
Originally Posted by zPain
Посмотреть сообщение
Vocк estб invertendo as coisas.
Explica?
Reply
#4

Acho que consegui consertar.. demorei mas tentei rs
Tomara que de certo
Leia este passo-a-passo ok?
Se nгo ler... Nгo vai dar certo mesmo

PHP код:
if(strcmp(cmdtext"/tapa"true) == 0)
{
    new 
Msg[128], Name[24], AdminName[24], OtherPlayer;
    
SendAdminText(playerid"/tapa"params);
    if (
APlayerData[playerid][LoggedIn] == true)
    {
        if (
APlayerData[playerid][PlayerLevel]  < 2)
        {
            if (
sscanf(params"u"OtherPlayer)) return SendClientMessage(playerid0xFF0000AA"Use: /tapa [id]");// Caso ele use /tapa, ou seja, sem ID
            
if (IsPlayerConnected(OtherPlayer))
            {
                
// Caso o player ID OtherPlayer esteja online acontecerб o seguinte:
                
                
GetPlayerName(playeridAdminNamesizeof(AdminName)); // Pegar o nome do playerid e transformar em AdminName
                
GetPlayerName(OtherPlayerNamesizeof(Name)); // Pegar o nome do OtherPlayer e transformar em Name
                
new player1;
                
player1 OtherPlayer// substituir "player1" por "Otherplayer", oq seria disperdнcio...
                
new Float:tapax;
                new 
Float:tapay;
                new 
Float:tapaz;
                
GetPlayerPos(player1tapaxtapaytapaz); // Pegar a pos X, Y, Z do player1 (Ou OtherPlayer)
                
SetPlayerPos(player1tapaxtapaytapaz+10); //Setar a pos X, Y, Z+10 pro player1 (Ou OtherPlayer)
                                                                // Isso significa que ele nгo vai sair do lugar, mas vai subir 10 metros e cair dps disso
                
format(Msg128"{FF0000}{FFFF00}[INFO] {FF0000}O Administrador %s deu um tapa em %s"AdminNameName); // criando uma string com variaveis
                
SendClientMessageToAll(0xFFFFFFFFMsg); // Mandar a string "Msg"
                
PlayerFile_Save(OtherPlayer); // Isso eu nгo sei... deve ser de alguma Include que eu nгo conheзa rs
            
}
            else   
// else significa (e se for ao contrбrio), ou seja, ao contrбrio de "IsPlayerConnected(OtherPlayer)"
            
{       // Que tambйm nгo й nada mais nada menos do que "!IsPlayerConnected(OtherPlayer)"
                
SendClientMessage(playerid0xFFFFFFFF"{FFFF00}[ERRO] {FF0000}Esse jogador nгo se encontra online!");
            }
        }
        else  
// Aqui o else nгo funcionaria... o else funciona com bools (true e false), com nъmeros nгo
        
{      // Apуs ler isso, substitua "else" por "if(APlayerData[playerid][PlayerLevel] > 1)"
              // Deste modo vocк estarб usando um "else" sу que de forma correta
        
SendClientMessage(playerid0xFFFFFFFF"{FFFF00}[ERRO] {FF0000}Vocк nгo tem permissгo para usar esse comando!");
        }
    }
    return 
1;

Reply
#5

pawn Код:
COMMAND:tapa(playerid, params[])
{
    new Msg[128], Name[24], AdminName[24], ID;
    SendAdminText(playerid, "/tapa", params);
    if (APlayerData[playerid][LoggedIn] == true)
    {
        if (APlayerData[playerid][PlayerLevel]  < 2)
        {
            if (sscanf(params, "u", ID)) return SendClientMessage(playerid, 0xFF0000AA, "Use: /tapa [id]");
            if (IsPlayerConnected(ID))
            {
                GetPlayerName(playerid, AdminName, sizeof(AdminName));
                GetPlayerName(I, Name, sizeof(Name));
                new Float:tapax, Float:tapay, Float:tapaz;
                GetPlayerPos(ID, tapax, tapay, tapaz);
                SetPlayerPos(ID, tapax, tapay, tapaz+15);
                format(Msg, 128, "{FF0000}{FFFF00}[INFO] {FF0000}O Administrador %s deu um tapa em %s", AdminName, Name);
                SendClientMessageToAll(0xFFFFFFFF, Msg);
                PlayerFile_Save(ID);
            }
            else SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}[ERRO] {FF0000}Esse jogador nгo se encontra online!");
        }
        else SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}[ERRO] {FF0000}Vocк nгo tem permissгo para usar esse comando!");
    }
    return 1;
}
Reply
#6

Quote:
Originally Posted by PT
Посмотреть сообщение
pawn Код:
COMMAND:tapa(playerid, params[])
{
    new Msg[128], Name[24], AdminName[24], ID;
    SendAdminText(playerid, "/tapa", params);
    if (APlayerData[playerid][LoggedIn] == true)
    {
        if (APlayerData[playerid][PlayerLevel]  < 2)
        {
            if (sscanf(params, "u", ID)) return SendClientMessage(playerid, 0xFF0000AA, "Use: /tapa [id]");
            if (IsPlayerConnected(ID))
            {
                GetPlayerName(playerid, AdminName, sizeof(AdminName));
                GetPlayerName(I, Name, sizeof(Name));
                new Float:tapax, Float:tapay, Float:tapaz;
                GetPlayerPos(ID, tapax, tapay, tapaz);
                SetPlayerPos(ID, tapax, tapay, tapaz+15);
                format(Msg, 128, "{FF0000}{FFFF00}[INFO] {FF0000}O Administrador %s deu um tapa em %s", AdminName, Name);
                SendClientMessageToAll(0xFFFFFFFF, Msg);
                PlayerFile_Save(ID);
            }
            else SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}[ERRO] {FF0000}Esse jogador nгo se encontra online!");
        }
        else SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}[ERRO] {FF0000}Vocк nгo tem permissгo para usar esse comando!");
    }
    return 1;
}
Ajuda resolver o erro:
pawn Код:
C:\Users\---\Desktop\BmcV2.0\pawno\include\PPC_PlayerCommands.inc(487) : error 029: invalid expression, assumed zer
Eu fiz o cуdigo assim para tirar o bug:
pawn Код:
COMMAND:tapa(playerid, params[])
{
    new Msg[128], Name[24], AdminName[24], OtherPlayer;
    SendAdminText(playerid, "/tapa", params);
    if (APlayerData[playerid][LoggedIn] == true)
    {
        if (APlayerData[playerid][PlayerLevel] >= 1)
        {
            if (sscanf(params, "u", OtherPlayer)) SendClientMessage(playerid, 0xFF0000AA, "Use: /tapa [id]");
            else
            {
                if (IsPlayerConnected(OtherPlayer))
                {
                    GetPlayerName(playerid, AdminName, sizeof(AdminName));
                    GetPlayerName(OtherPlayer, Name, sizeof(Name));
                    new player1;
                    player1 = OtherPlayer;
                    new Float:tapax;
                    new Float:tapay;
                    new Float:tapaz;
                    GetPlayerPos(player1, tapax, tapay, tapaz);
                    SetPlayerPos(player1, tapax, tapay, tapaz+10);
                    format(Msg, 128, "{FF0000}-| O Administrador %s deu um tapa em %s |-", AdminName, Name);
                    SendClientMessageToAll(0xFFFFFFFF, Msg);
                    PlayerFile_Save(OtherPlayer);
                        }
                        else
                        {
                        SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}[ERRO] {FF0000}Vocк nгo tem permissгo para usar esse comando!");
                    }
                }
                else
                {
                    SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}[ERRO] {FF0000}Esse jogador nгo se encontra online!");
            }
        }
        else
            return 0;
    }
    else
        return 0;
    return 1;
}
Sу que esta dando aquele erro..

A linha do erro й essa:
pawn Код:
else
Reply
#7

@zivo

Quote:
Originally Posted by Zivo
pawn Код:
// Aqui o else nгo funcionaria... o else funciona com bools (true e false), com nъmeros nгo
// Apуs ler isso, substitua "else" por "if(APlayerData[playerid][PlayerLevel] > 1)"
// Deste modo vocк estarб usando um "else" sу que de forma correta
Й a segunda vez que tenho que te falar que ELSE nгo funciona sу com bools!

pawn Код:
new a = 5;
if(a == 4)
    print("A й 4!");
else
    printf("A nгo й 4, pois ele й %d",a);
@topic

Aqui ensina como usar if/else if/else perfeitamente.

https://sampwiki.blast.hk/wiki/Control_Structures
Reply
#8

Mas em qual dos else?
Reply
#9

tenta, se der avisa q deu

PHP код:
COMMAND:tapa(playeridparams[])
{
    new 
Msg[128], Name[24], AdminName[24], OtherPlayer;
    
SendAdminText(playerid"/tapa"params);
    if (
APlayerData[playerid][LoggedIn] == true) {
    
        if (
APlayerData[playerid][PlayerLevel] >= 1) {
        
            if (
sscanf(params"u"OtherPlayer)) {SendClientMessage(playerid0xFF0000AA"Use: /tapa [id]");} else {
            
                if (
IsPlayerConnected(OtherPlayer)) {
                    
GetPlayerName(playeridAdminNamesizeof(AdminName));
                    
GetPlayerName(OtherPlayerNamesizeof(Name));
                    new 
player1;
                    
player1 OtherPlayer;
                    new 
Float:tapax;
                    new 
Float:tapay;
                    new 
Float:tapaz;
                    
GetPlayerPos(player1tapaxtapaytapaz);
                    
SetPlayerPos(player1tapaxtapaytapaz+10);
                    
format(Msg128"{FF0000}-| O Administrador %s deu um tapa em %s |-"AdminNameName);
                    
SendClientMessageToAll(0xFFFFFFFFMsg);
                    
PlayerFile_Save(OtherPlayer);
                } else {
SendClientMessage(playerid0xFFFFFFFF"{FFFF00}[ERRO] {FF0000}Esse jogador nгo se encontra online!");}
            }
        } else {
SendClientMessage(playerid0xFFFFFFFF"{FFFF00}[ERRO] {FF0000}Vocк nгo tem permissгo para usar esse comando!");
    }
    return 
1;

Reply
#10

Desde quando else serve apenas para contrariar bools ?

vocк saberia usar se ao menos jogar no ****** tradutor,

if = Se ....
else = Caso contrбrio ...
else if = Caso contrбrio se ....
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)