admin chat code has a bug -
BlackWolf120 - 12.03.2011
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.
Re: admin chat code has a bug -
omer5198 - 12.03.2011
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?
Re: admin chat code has a bug -
Kwarde - 12.03.2011

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;
}
Re: admin chat code has a bug -
BlackWolf120 - 12.03.2011
hi thx for ur help.
It works now thx.
Re: admin chat code has a bug -
Kwarde - 12.03.2011
No problem.
And off course it works, I made it ^^. No just kidding. I make mistakes too (alot :P)
Re: admin chat code has a bug -
HyperZ - 12.03.2011
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)
|
Re: admin chat code has a bug -
Kwarde - 12.03.2011
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
Re: admin chat code has a bug -
HyperZ - 12.03.2011
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.
Re: admin chat code has a bug -
Kwarde - 12.03.2011
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)
Re: admin chat code has a bug -
HyperZ - 12.03.2011
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.