admin chat code has a bug
#1

hi,

just put together a code for an admin chat.
It works fine but if i got a space in my text (u know the space between 2 words), everything behind the space does not appear in the admin chat anymore.
Whats the error?

pawn Код:
dcmd_a(playerid,params[])
{
new text[256];
if(Spieler[playerid][AdminLevel] == 0)
{
return SendClientMessage(playerid, 0xFF0000FF, "You are not an admin!");
}
if(sscanf(params,"s[256]",text))
{
new str[128];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof name);
format(str,sizeof str,"[ADMIN] %s: %s",name,text);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(Spieler[i][eingeloggt] == 1)
{
if(Spieler[playerid][AdminLevel] > 0)
{
SendClientMessage(i,0xFF66FFAA,str);
}
}
}
}
}
return 1;
}
thx in advance.
Reply
#2

i didn't understand your problem... if you type /a TEXT it will write it on admin chat? and if so... when you do space it deletes what ever was before?
Reply
#3

Do not use [256]. Use maximal [128].
And sscanf is called when there are NO params in a string. Here's an example:

pawn Код:
dcmd_a(playerid, params[])
{
    new str[128], input[75], pName[MAX_PLAYER_NAME];
    if(sscanf(params, "s", input)) return SendClientMessage(playerid, 0xFFFFFFAA, "USAGE: /a [text]");
    if(IsPlayerAdmin(playerid) || Spieler[playerid][AdminLevel] > 0){
        format(str, 128, "[ADMIN] %s(%d): %s", pName, playerid, input);
        for(new i = 0; i < MAX_PLAYERS; i++)
            if(IsPlayerAdmin(i) || Spieler[playerid][AdminLevel] > 0)
                SendClientMessage(i, 0x00FFFFAA, str);
    }
    return 1;
}
Reply
#4

hi thx for ur help.
It works now thx.
Reply
#5

No problem.
And off course it works, I made it ^^. No just kidding. I make mistakes too (alot :P)
Reply
#6

There must be strings array.
pawn Код:
dcmd_a(playerid, params[])
{
    new str[128], pName[MAX_PLAYER_NAME];
    if(sscanf(params, "s[128]", params)) return SendClientMessage(playerid, 0xFFFFFFAA, "USAGE: /a [text]");
    if(IsPlayerAdmin(playerid) || Spieler[playerid][AdminLevel] > 0)
    {
        format(str, 128, "[ADMIN] %s(%d): %s", pName, playerid, params);
        for(new i = 0; i < MAX_PLAYERS; i++)
        if(IsPlayerAdmin(i) || Spieler[playerid][AdminLevel] > 0)
        SendClientMessage(i, 0x00FFFFAA, str);
    }
    return 1;
}
Edit:
@Kwarde
You've just edited your post.
at 1st there was:
Quote:
Originally Posted by Kwarde
Посмотреть сообщение
No problem.
And off course it works, I made it ^^.
And now i saw that there is:
Quote:
Originally Posted by Kwarde
Посмотреть сообщение
No problem.
And off course it works, I made it ^^. No just kidding. I make mistakes too (alot :P)
Reply
#7

I know. I mean I'm not always wrong (just prooved it in another topic)
and btw about the sscanf, about the 's[128]' -> It's not needed. I mean I never use that and it still works. And he also said it's workin
Reply
#8

Quote:
Originally Posted by Kwarde
Посмотреть сообщение
I know. I mean I'm not always wrong (just prooved it in another topic)
and btw about the sscanf, about the 's[128]' -> It's not needed. I mean I never use that and it still works. And he also said it's workin
Ofc it'll works without arrays too but you'll get warnings in your server console.
Reply
#9

Hmm I'll take a look at it tomorrow :P
Wait , are you using in the scripts the sscanf2 (the plugin) or the older sscanf? 'cuz I'm still using the old one (I'll change soon)
Reply
#10

Quote:
Originally Posted by Kwarde
Посмотреть сообщение
Hmm I'll take a look at it tomorrow :P
Wait , are you using in the scripts the sscanf2 (the plugin) or the older sscanf? 'cuz I'm still using the old one (I'll change soon)
WaoW What a joke.

Edit: YEah i suggest you to use SSCANF2.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)