SA-MP Forums Archive
/a not working - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: /a not working (/showthread.php?tid=308888)



/a not working - geerdinho8 - 05.01.2012

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;
}



Re: /a not working - [MG]Dimi - 05.01.2012

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


Re: /a not working - geerdinho8 - 05.01.2012

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

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


Re: /a not working - [MG]Dimi - 05.01.2012

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.


Re: /a not working - Jochemd - 05.01.2012

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.


Re: /a not working - geerdinho8 - 05.01.2012

Not working.

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


Re: /a not working - geerdinho8 - 05.01.2012

Sorry but i won't use ZCMD and sccanf


Re: /a not working - [MG]Dimi - 05.01.2012

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.


Re: /a not working - geerdinho8 - 05.01.2012

Hmm, not working


Re: /a not working - Gh05t_ - 05.01.2012

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;
}