/ask Bug
#1

So I've made a /ans system and when I use it in-game it spams the whole chat.
Here is the code
Код:
CMD:ask(playerid,params[])
{
    new string[128],playername[24];
	if(sscanf(params,"s[128]",params)) return SendClientMessage(playerid, COLOR_YELLOW,"[COMMAND]{FFFFFF} Usage:{FFFF00} /ask [question]");
    GetPlayerName(playerid,playername,24);
    format(string,sizeof(string),"[QUESTION]{FFFFFF} %s has asked a question: %s [Use /ans to answer answer]",playername,params);
    for(new i=0; i<MAX_PLAYERS; i++)
    {
         if(IsPlayerConnected(playerid))
         {
           if(pInfo[playerid][Adminlevel] >= 1)
           {
              SendClientMessage(playerid,COLOR_ORANGE,string);
           }
         }
     }
    return 1;
}
Reply
#2

Код:
CMD:ask(playerid,params[])
{
    new string[128],playername[24];
	if(sscanf(params,"s[128]",params)) return SendClientMessage(playerid, COLOR_YELLOW,"[COMMAND]{FFFFFF} Usage:{FFFF00} /ask [question]");
    GetPlayerName(playerid,playername,24);
    format(string,sizeof(string),"[QUESTION]{FFFFFF} %s has asked a question: %s [Use /ans to answer answer]",playername,params);
    for(new i=0; i<MAX_PLAYERS; i++)
    {
         if(IsPlayerConnected(i))
         {
           if(pInfo[i][Adminlevel] >= 1)
           {
              SendClientMessage(i,COLOR_ORANGE,string);
           }
         }
     }
    return 1;
}
You was sending the message to the command executer for every player that is connected.
Reply
#3

Thanks!
Also here is my /ans command, looks like everyone can use it, players and admins, idk how.
Код:
CMD:ans(playerid,params[])
{
	new string[128],playername[24],playerb;
	if(pInfo[playerid][Adminlevel] >= 1)
 	if(pInfo[playerid][Adminlevel] == 0) return SendClientMessage(playerid, COLOR_RED,"[ERROR]{FFFFFF} You have entered an unknown command, please view {FFFF00}/cmds{FFFFFF} or{FFFF00} /commands{FFFFFF} and try again.");
    if(sscanf(params,"us[128]",playerb,params)) return SendClientMessage(playerid, COLOR_YELLOW,"[COMMAND]{FFFFFF} Usage:{FFFF00} /ans [playerid] [response]");
    if(!IsPlayerConnected(playerb)) return SendClientMessage(playerid,COLOR_GREY,"[SERVER]{FFFFFF} That player is not connected.");
    GetPlayerName(playerid,playername,24);
    format(string,sizeof(string),"[ANSWER]:{FFFFFF} %s",params);
    SendClientMessage(playerb,COLOR_ORANGE,string);
    GetPlayerName(playerb,playername,24);
    format(string,sizeof(string),"[INFO]{FFFFFF} You have replied to %s successfully!",playername);
    SendClientMessage(playerid,COLOR_ORANGE,string);

    return 1;
}
Idk what the problem is.. :/
Reply
#4

pawn Код:
if(pInfo[playerid][Adminlevel] >= 1)
    if(pInfo[playerid][Adminlevel] == 0) return SendClientMessage(playerid, COLOR_RED,"[ERROR]{FFFFFF} You have entered an unknown command, please view {FFFF00}/cmds{FFFFFF} or{FFFF00} /commands{FFFFFF} and try again.");
If you want only admins to be able to use the command, remove the first check and if you have a custom message shown in OnPlayerCommandPerformed then all you have to do is return 0.

pawn Код:
if(pInfo[playerid][Adminlevel] == 0) return 0;
Reply
#5

Thanks bro!
Reply
#6

This has nothing to do with the problem:

Why do you create two arrays, before checking if the player entered the command syntax incorrectly?
They would be wasted if the player didn't enter them correctly.

Also, why use sscanf when you already have params?
Just use isnull(string[]) when there's only need for 1 string parameter.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)