SA-MP Forums Archive
[Ajuda] Verificar valor da variavel - 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: [Ajuda] Verificar valor da variavel (/showthread.php?tid=452857)



Verificar valor da variavel - LucaAllexandre - 22.07.2013

galera, nгo estou lembrando como se faz pra verificar o valor da variavel eu fiz desse geito:
pawn Code:
//TOPO Do gamemode
new tanogod;

//onplayercommand
if (strcmp("/god", cmdtext, true, 10) == 0)
{
tanogod = 1;
SetPlayerHealth(playerid, 10000);
SendClientMessage(playerid, -1, "[GOD] Vocк ativou o modo god, para desativar digite: (/god)");
return 1;
}

if (strcmp("/ofgod", cmdtext, true, 10) == 0)
{
if tanogod = 0;
{
 sendclientmessage(playerid, "teste");
}
else
{
SetPlayerHealth(playerid, 100);
SendClientMessage(playerid, -1, "[GOD] Vocк desativou o modo god. (/god)");
}
return 1;
}
estб certo? sim ou nгo? poderiam me ajudar, nгo lembro como que era... ;/


Re: Verificar valor da variavel - WLSF - 22.07.2013

Tenta assim:
pawn Code:
new godmod[MAX_PLAYERS];

if (!strcmp(cmdtext, "/godon"))
{
    if (godmod[playerid] == 1) return SendClientMessage(playerid, -1, "Jб estб ativado.");
    godmod[playerid] = 1;
    SetPlayerHealth(playerid, 999999);
    SendClientMessage(playerid, -1, "ATIVADO");
    return 1;
}
if (!strcmp(cmdtext,"/godoff"))
{
    if (godmod[playerid] == 1) // << Assim
    {
        SetPlayerHealth(playerid, 100);
        godmod[playerid] = 0;
        SendClientMessage(playerid, -1, "DESATIVADO");
    }
    return 1;
}
Te recomendo a utilizar uma variбvel indexada por players, para dividir, quando tiver trabalhando com comandos gerais, pois se dois players utilizarem o comando e a var nгo tiver indexada por jogador, isso irб gerar bugs na execuзгo do cуdigo.


Re: Verificar valor da variavel - LucaAllexandre - 22.07.2013

Qual й a do [max_player?]


Re: Verificar valor da variavel - WLSF - 22.07.2013

Quote:
Originally Posted by Willian_Luigi
View Post
uma variбvel indexada por players, para dividir, quando tiver trabalhando com comandos gerais, pois se dois players utilizarem o comando e a var nгo tiver indexada por jogador, isso irб gerar bugs na execuзгo do cуdigo.
Vai separar essa variбvel pelo id do player, й como se vocк tivesse dando um valor pra cada jogador.


Re: Verificar valor da variavel - PT - 22.07.2013

usando o seu como base

pawn Code:
//TOPO Do gamemode
new tanogod[MAX_PLAYERS] = 0;

// OnPlayerConnect
tanogod[playerid] = 0;


//onplayercommand
if (strcmp("/god", cmdtext, true, 10) == 0)
{
    tanogod[playerid] = 1;
    SetPlayerHealth(playerid, 999999);
    SendClientMessage(playerid, -1, "[GOD] Vocк ativou o modo god, para desativar digite: (/god)");
    return 1;
}

if (strcmp("/ofgod", cmdtext, true, 10) == 0)
{
    if(tanogod[playerid] == 0)
    {
        SendClientMessage(playerid, -1, "Nao tens god ligado");
        return 1;
    }
    else
    {
        tanogod[playerid] = 0;
        SetPlayerHealth(playerid, 100);
        SendClientMessage(playerid, -1, "[GOD] Vocк desativou o modo god. (/god)");
    }
    return 1;
}
tenta ae


Re: Verificar valor da variavel - LucaAllexandre - 22.07.2013

Caaara, o meu tava quase certo PT, Obrigado! e obrigado por tentar ajudar William, e suas explicaзхes!

Pronto li seu codigo, e jб anexei no meu celebro =)

+REP


Re: Verificar valor da variavel - PT - 23.07.2013

Quote:
Originally Posted by Diksplay
View Post
Caaara, o meu tava quase certo PT, Obrigado! e obrigado por tentar ajudar William, e suas explicaзхes!

Pronto li seu codigo, e jб anexei no meu celebro =)

+REP
Usa tambem e identaзгo fica bem melhor