/a not working
#1

please help
pawn Код:
if(strcmp(cmd, "/a", true) == 0)
        {
        if(pInfo[playerid][Admin] >= 0)
        {
        tmp = strtok(cmdtext,idx);
        new text;
            text = strval(tmp);
         if(!strlen(tmp))
         {
             SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /a [text]");
         }
         else
         {
                GetPlayerName(playerid, adminname, sizeof(adminname));
                format(string,sizeof(string),"Adminchat (%s): %s", adminname, text);
                MessageToAdmins(purple,string);
                }
         }
         return 1;
}
pawn Код:
public MessageToAdmins(color,const string[])
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
    if(IsPlayerConnected(i) == 1)
    if(pInfo[i][Admin] >= 0)
    SendClientMessage(i, color, string);
    }
    return 1;
}
Reply
#2

pawn Код:
if(!strcmp(cmd, "/a", true))
{
    if(pInfo[playerid][Admin] < 1) return 0;
    new text = cmdtext[4], adminname[24];
    if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /a [text]");
    GetPlayerName(playerid, adminname, sizeof(adminname));
    format(string,sizeof(string),"Adminchat (%s): %s", adminname, text);
    MessageToAdmins(purple,string);
    return 1;
}

stock MessageToAdmins(color,msg[])
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && pInfo[i][Admin] >= 1) SendClientMessage(i, color, string);
    }
    return 1;
}
This is how I would make it. Should work. Untested. Also your statements are saying if player's level is 0 or higher which means it includes 0. I guess the lowest your admin level is 1, not 0 so I changed script according to it. Also I think you can't make public callback for function. Use
pawn Код:
stock
Have fun. Post if any errors
Reply
#3

What to do with:
pawn Код:
forward MessageToAdmins(color,const string[]);
then?

Cuz when i delete it, the string isn't defined anymorre.
Reply
#4

sorry my fault. Delete forward...
pawn Код:
stock MessageToAdmins(color,msg[])
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && pInfo[i][Admin] >= 1) SendClientMessage(i, color, msg);
    }
    return 1;
}
This is good one.
Reply
#5

I suggest you to use dcmd/zcmd/ycmd and sscanf. There are much, much better things available than strcmp + strtok

pawn Код:
CMD:a(playerid, params[])
{
    new text[128];
    if(!sscanf(params,"s[128]",text))
    {
        new adminname[MAX_PLAYER_NAME];
        GetPlayerName(playerid, adminname, sizeof(adminname));
        format(string,sizeof(string),"Adminchat (%s): %s", adminname, text);
        MessageToAdmins(purple,string);
    }
    else return SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /a [text]");
    return 1;
}
       
public MessageToAdmins(color,const string[])
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(pInfo[i][Admin])
            SendClientMessage(i, color, string);
        }
    }
    return 1;
}
This is how you should make such things with ZCMD and sscanf.
Reply
#6

Not working.

I guess it is because in the command it is string and in the stock the variable is msg?
Reply
#7

Sorry but i won't use ZCMD and sccanf
Reply
#8

pawn Код:
CMD:a(playerid, params[])
{
    new text[128];
    if(!sscanf(params,"s[128],text))
    {
        new adminname[MAX_PLAYER_NAME];
        GetPlayerName(playerid, adminname, sizeof(adminname));
        format(string,sizeof(string),"
Adminchat (%s): %s", adminname, text);
        MessageToAdmins(purple,string);
    }
    else return SendClientMessage(playerid, COLOR_YELLOW, "
USAGE: /a [text]");
    return 1;
}
       
public MessageToAdmins(color,const string[])
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(pInfo[i][Admin])
            SendClientMessage(i, color, string);
        }
    }
    return 1;
}
@Jochemd Your code is too blue xD You forgot "at the sscanf

@geerdinho8 That doesn't make any difference. That's only param defining.
Reply
#9

Hmm, not working
Reply
#10

Quote:
Originally Posted by geerdinho8
Посмотреть сообщение
Hmm, not working
pawn Код:
CMD:a(playerid, params[])
{
    if(isnull(params)) return true;
    new string[156], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    format(string,sizeof(string),"Adminchat (%s): %s", name, params);
    for(new i=0; i < MAX_PLAYERS; i++) if(IsPlayerConnected(i)) if(pInfo[i][Admin])
    SendClientMessage(i, -1, string);
    return true;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)