[AJUDA] Ajuda com o comando anunciar
#1

pawn Код:
new index;
             new tmp[256];
             tmp = strtok(cmdtext, index);
    if(strcmp(cmd, "/an", true) == 0)
    {
    new val = strval(tmp);
    new anuncio[256];
    new anunciado[256];
    if(GetPlayerMoney(playerid) > 250)
    {
    format(anunciado,sizeof anunciado,"%s",val);
    format(anuncio, sizeof anuncio, "%s Anunciou: %s",String,anunciado);
    SendClientMessageToAll(VERDE,"*--------------------------------------------*");
    SendClientMessageToAll(AMARELO, anuncio);
    SendClientMessage(playerid,VERMELHO,"Esse anuncio custou 250 R$");
    GivePlayerMoney(playerid,-250);
    }
    else
    {
    SendClientMessage(playerid,VERMELHO,"Vocк nгo tem dinheiro para anunciar");
    }
    return 1;
    }
             return 1;
             }
Qual o problema com o cod. ?
quando eu digito /an [texto]
aparece:
*-----------------------------------*
NOME Anunciou: ??
Este anuncio le custou 250 R$

Onde ta ?? й a mesma coisa que nada, eu digito o texto mas nгo sai nada
desde jб agradeзo !
Reply
#2

pawn Код:
new index;
    new tmp[256];
    tmp = strtok(cmdtext, index);
    if(strcmp(cmd, "/an", true) == 0)
    {
    new val = strval(tmp);
    new anuncio[256];
    new anunciado[256];
    if(GetPlayerMoney(playerid) > 250)
    {
    format(anuncio, sizeof anuncio, "%s Anunciou: %s",String,anunciado);
    SendClientMessage(AMARELO, anuncio);
    SendClientMessage(playerid,VERMELHO,"Esse anuncio custou 250 R$");
    GivePlayerMoney(playerid,-250);
    }
    else
    {
    SendClientMessage(playerid,VERMELHO,"Vocк nгo tem dinheiro para anunciar");
    }
    return 1;
}
Reply
#3

pawn Код:
format(String, sizeof(String), "%s Anunciou: %s",anunciado,anuncio);
SendClientMessage(AMARELO, String);
Reply
#4

Desculpa Don Speed mas nгo entendi...
pawn Код:
new index;
    new tmp[256];
    tmp = strtok(cmdtext, index);
    if(strcmp(cmd, "/an", true) == 0)
    {
    new val = strval(tmp);
    new anuncio[256];
    new anunciado[256];
    if(GetPlayerMoney(playerid) > 250)
    {
    format(anuncio, sizeof anuncio, "%s Anunciou: %s",String,anunciado);// a segunda %s ta definido como anunciando e a variavel anunciando ta apenas definida mas com valor 0, no code que passei a variavel anunciando formatava a variavel val, val= qoue ele escreveu !
    SendClientMessage(AMARELO, anuncio);
    SendClientMessage(playerid,VERMELHO,"Esse anuncio custou 250 R$");
    GivePlayerMoney(playerid,-250);
    }
    else
    {
    SendClientMessage(playerid,VERMELHO,"Vocк nгo tem dinheiro para anunciar");
    }
    return 1;
}
Acredito que assim nгo funcione ....
Estбva pensando e gostaria de saber se assim funcionaria:
pawn Код:
new index;
    new tmp[256];
    tmp = strtok(cmdtext, index);
    if(strcmp(cmd, "/an", true) == 0)
    {
    new val = strval(tmp);
    new anuncio[256];
    if(GetPlayerMoney(playerid) > 250)
    {
    format(anuncio, sizeof anuncio, "%s Anunciou: %d",String,val);
    SendClientMessage(AMARELO, anuncio);
    SendClientMessage(playerid,VERMELHO,"Esse anuncio custou 250 R$");
    GivePlayerMoney(playerid,-250);
    }
    else
    {
    SendClientMessage(playerid,VERMELHO,"Vocк nгo tem dinheiro para anunciar");
    }
    return 1;
}
Reply
#5

Enderman a variavel String foi definida globalmente, e ela contem o nome do player
vou explicar meu code.
pawn Код:
new index;
new tmp[256];
tmp = strtok(cmdtext, index);
if(strcmp(cmd, "/an", true) == 0)
{
new val = strval(tmp); // seta a varival val para o que ele digitar
new anuncio[256];
if(GetPlayerMoney(playerid) > 250)//verifica se tem mais doque 250 no dinheiro
{
format(anuncio, sizeof anuncio, "%s Anunciou: %s",String,val);//formata pra exibir o nome e oque digitou, String= NOME, uma variavel global, val=oque ele digitou !
SendClientMessage(AMARELO, anuncio);//envia a menssagem
SendClientMessage(playerid,VERMELHO,"Esse anuncio custou 250 R$");//avisa que custou 250
GivePlayerMoney(playerid,-250);//tira os 250 do player
}
else
{
SendClientMessage(playerid,VERMELHO,"Vocк nгo tem dinheiro para anunciar");//aqui caso ele nгo tenho 250 !
}
return 1;
}
De acordo com minha logica estб perfeito, mas nгo ta saindo o anuncio apenas o nome !
Reply
#6

Vai ver й porque tu estбs imprimando uma Intiger com %s...

pawn Код:
new val = strval(tmp); // seta a varival val para o que ele digitar
Nгo seta a variavel para oque ele digitar, ela transforma a variavel em intiger...
Reply
#7

Achas que eu deveria usar %d no format ?
ou deixar %s e mudar o val para strval(val) no format ?
Reply
#8

pawn Код:
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
    idx++;
}
new offset = idx;
new result[64];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
    result[idx - offset] = cmdtext[idx];
    idx++;
}
result[idx - offset] = EOS;
Ao invйs de converter uma string para intiger vocк precisa localizar a string digitada, no caso (result).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)