[PEDIDO]Strtok
#1

Boas galerinha do bem eu vim ate aqui pedi um favorzinho para voces eu queria que se alguem podesse fazer um tutorial de como usar

pawn Код:
strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
    index++;
    }
    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result)- 1)))
    {
    result[index - offset] = string[index];
    index++;
    }
    result[index - offset] = EOS;
    return result;
}
Porque eu ainda sou muito Noob e nгo sei utilizar quando tento utiliza-lo me da uma porrada de erros e warnings

para vcs terem uma idйia eu nгo sei fazer um simples comando de /darvida ID para vcs verem minha noobice nem copiando de outro GM eu nгo sei da erros e warnings Brigadin a quem me ajudar
Reply
#2

Simples.


Strtok funciona assim:

pawn Код:
strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))//Aqui ele vк se a string tem um espaзo. Enquanto ela tiver, o script continua.
    {
    index++;
    }
    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result)- 1)))//Aqui ele faz a mбgica de transformar o texto que estб em espaзo em outro texto.
    {
    result[index - offset] = string[index];
    index++;
    }
    result[index - offset] = EOS;//Aqui й o resultado. A string :)


CONSELHO:


No comeзo de seu OnPlayerCommandText adicione:
pawn Код:
new idx;
new tmp[128];
E para usar o strtok:

pawn Код:
tmp = strtok(cmdtext, idx); //Pronto :). Agora TMP й a string depois do comando.
Para adicionar mais do que somente um valor (EX: /mensagem [playerid] [cor] [mensagem]), й sу fazer:

pawn Код:
new suastringaqui[TAMANHO_DA_ARRAY]; //Recomendo 128 de array, se for mensagem. Se nгo, use 64 ou menos :)

Eis um cуdigo de darvida.

De brinde, um de setar armor tambйm
pawn Код:
if(strcmp(cmd, "/darvida", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            tmp = strtok(cmdtext, idx); //Aqui ele vк o que й escrito depois de sethp;
            if(!strlen(tmp))//Aqui ele checa se vocк nгo escreveu nada
            {
                SendClientMessage(playerid, 0xFFFFFFFF, "USO: /darvida [playerid/PartOfName] [health]");
                return 1;
            }
            new playa;//Variбvel usada como sendo a do id do player;
            new health;//Variavel usada para ser a quantidade de HP a ser setada;
            playa = ReturnUser(tmp);//Define que player й para retornar um usuбrio;
            tmp = strtok(cmdtext, idx);//Outro strtok, que define um espaзo depois da ID do player;
            health = strval(tmp);//Retorna o valor de tmp(string que й a vida do player em valores numйricos inteiros;
            if(IsPlayerConnected(playa))
            {
                if(playa != INVALID_PLAYER_ID)
                {
                    SetPlayerHealth(playa, health);//Seta o HP.
                }
                else
                {
                    SendClientMessage(playerid, 0xFFFFFFFF, "Jogador NГO conectado!");
                }
            }
        }
        return 1;
    }
    if(strcmp(cmd, "/darcolete", true) == 0)//Mesma coisa do acima :)
    {
        if(IsPlayerConnected(playerid))
        {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, 0xFFFFFFFF, "USO: /darcolete [playerid/PartOfName] [armor]");
                return 1;
            }
            new playa;
            new health;
            playa = ReturnUser(tmp);
            tmp = strtok(cmdtext, idx);
            health = strval(tmp);
            if(IsPlayerConnected(playa))
            {
                if(playa != INVALID_PLAYER_ID)
                {
                    SetPlayerArmour(playa, health);
                }
                else
                {
                    SendClientMessage(playerid, 0xFFFFFFFF, "Jogador NГO conectado!");
                }
            }
        }
        return 1;
    }

Espero ter tirado sua dъvida.
Reply
#3

Sua Explicaзгo й quase perfeita, sу com dois erros de floats.

Corrigindo:


pawn Код:
new Float:playa;//Variбvel usada como sendo a do id do player;
            new Float:health;//Variavel usada para ser a quantidade de HP a ser setada;
Reply
#4

Nгo й um FLOAT health.


Porquк vocк nгo vai digitar um FLOAT, e sim um valor INTEGER.


Fail seu, Garfield


E COMO EU VOU TER UM FLOAT NA ID DO PLAYER LOL?
Reply
#5

pawn Код:
new Float:health;
 SetPlayerHealth(playa, health);//Seta o HP.
Reply
#6

o garfield ta correto lelete...
Reply
#7

Vou repetir.



VOCК.


NГO.


DIGITA.


UM.


FLOAT!


No /darvida vocк nгo digita 0.35.


Nгo existe isso.



Nгo й necessбrio um float pra vocк poder setar o HP.



._.
Reply
#8

Quote:
Originally Posted by LeLeTe
Посмотреть сообщение
Simples.


Strtok funciona assim:

pawn Код:
strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))//Aqui ele vк se a string tem um espaзo. Enquanto ela tiver, o script continua.
    {
    index++;
    }
    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result)- 1)))//Aqui ele faz a mбgica de transformar o texto que estб em espaзo em outro texto.
    {
    result[index - offset] = string[index];
    index++;
    }
    result[index - offset] = EOS;//Aqui й o resultado. A string :)


CONSELHO:


No comeзo de seu OnPlayerCommandText adicione:
pawn Код:
new idx;
new tmp[128];
E para usar o strtok:

pawn Код:
tmp = strtok(cmdtext, idx); //Pronto :). Agora TMP й a string depois do comando.
Para adicionar mais do que somente um valor (EX: /mensagem [playerid] [cor] [mensagem]), й sу fazer:

pawn Код:
new suastringaqui[TAMANHO_DA_ARRAY]; //Recomendo 128 de array, se for mensagem. Se nгo, use 64 ou menos :)

Eis um cуdigo de darvida.

De brinde, um de setar armor tambйm
pawn Код:
if(strcmp(cmd, "/darvida", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            tmp = strtok(cmdtext, idx); //Aqui ele vк o que й escrito depois de sethp;
            if(!strlen(tmp))//Aqui ele checa se vocк nгo escreveu nada
            {
                SendClientMessage(playerid, 0xFFFFFFFF, "USO: /darvida [playerid/PartOfName] [health]");
                return 1;
            }
            new playa;//Variбvel usada como sendo a do id do player;
            new health;//Variavel usada para ser a quantidade de HP a ser setada;
            playa = ReturnUser(tmp);//Define que player й para retornar um usuбrio;
            tmp = strtok(cmdtext, idx);//Outro strtok, que define um espaзo depois da ID do player;
            health = strval(tmp);//Retorna o valor de tmp(string que й a vida do player em valores numйricos inteiros;
            if(IsPlayerConnected(playa))
            {
                if(playa != INVALID_PLAYER_ID)
                {
                    SetPlayerHealth(playa, health);//Seta o HP.
                }
                else
                {
                    SendClientMessage(playerid, 0xFFFFFFFF, "Jogador NГO conectado!");
                }
            }
        }
        return 1;
    }
    if(strcmp(cmd, "/darcolete", true) == 0)//Mesma coisa do acima :)
    {
        if(IsPlayerConnected(playerid))
        {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, 0xFFFFFFFF, "USO: /darcolete [playerid/PartOfName] [armor]");
                return 1;
            }
            new playa;
            new health;
            playa = ReturnUser(tmp);
            tmp = strtok(cmdtext, idx);
            health = strval(tmp);
            if(IsPlayerConnected(playa))
            {
                if(playa != INVALID_PLAYER_ID)
                {
                    SetPlayerArmour(playa, health);
                }
                else
                {
                    SendClientMessage(playerid, 0xFFFFFFFF, "Jogador NГO conectado!");
                }
            }
        }
        return 1;
    }

Espero ter tirado sua dъvida.

Valeooooooooooooooooooooooooooooo agora aprendi como funciona strtok sу estou tendo problemas com os sendername mas nada que duas ou tres modificaзхes nгo resolva Obrigado
Reply
#9

Quote:
Originally Posted by LeLeTe
Посмотреть сообщение
Vou repetir.



VOCК.


NГO.


DIGITA.


UM.


FLOAT!


No /darvida vocк nгo digita 0.35.


Nгo existe isso.



Nгo й necessбrio um float pra vocк poder setar o HP.



._.
pawn Код:
if(strcmp(cmdtext, "/v",  true) == 0)
{
for(new i = 0; i < MAX_PLAYERS i++)
{
if(IsPlayerConnected(i))
{
SetPlayerHealth(i,100);// й a mesma coisa
}
}
return 1;
}
Reply
#10

Fail das Crianзas,rs

pawn Код:
SetPlayerHealth(playerid,10);
Nгo й Necessбrio Floats,
e Onde jб se viu playerid em um Float? Na boa Garfield & Kasura
Aprendem melhor depois tentam Corrigir os que sabem mais....
Sу serгo necessбrio Float caso Getar o Valor (GetPlayerHealth) pois a Funзгo Set jб й definida caso nгo use Float
Fail


Garfield sу para Corrigir seu Cуdigo
pawn Код:
if(strcmp(cmdtext, "/v",  true) == 0)
{
     for(new i = 0; i < MAX_PLAYERS; i++)
     {
         if(IsPlayerConnected(i))
         {
             SetPlayerHealth(i,100);// й a mesma coisa
         }
      }
      return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)