Unknown command issue
#1

I have a command /say and it also uses this

https://sampforum.blast.hk/showthread.php?tid=528401

So when you do /say Hello * Raises hand * < The text in the "*" should be purple but insted it gives me unknown command but if i do /say Hello it will work and show Jesse Brook says hello



Here is the stock i used

pawn Код:
stock FilterAsterisk(msg[], msglen = sizeof(msg))
{
    new i = 0, asteriskPair = 0;
    while (msg[i] != '\0')
    {
        if (msg[i] == '*')
        {
            if (asteriskPair == 0)
            {
                asteriskPair++;
                strins(msg, "{800080}", i, msglen);
            }
            else
            {
                asteriskPair = 0;
                strins(msg, "{FFFFFF}", i, msglen);
            }
        }
        i++;
    }
}



Here is the command


pawn Код:
CMD:say(playerid, params[])
{
    new text[256],embed_msg[144],string[144];
    if(sscanf(params, "s[256]", text)) SendClientMessage(playerid, COLOR_GREY, "USAGE: /say {FFFFFF}[text]");
    else
    {
        if(gPlayerLogged{playerid} == 0) return SendClientMessage(playerid, COLOR_WHITE, "You must be logged in to use this.");
        if(PlayerInfo[playerid][pMuted] == 1)return SendClientMessage(playerid, COLOR_LIGHTRED, "You are currently muted !");
        else if(PlayerInfo[playerid][pMask] == 1)
        {
            if(PlayerInfo[playerid][pAccent] >= 2)
            {
                format(string, sizeof(string), "Stranger says: [Accent %s] %s",GetPlayerAccent(playerid),text);
            }
            else
            {
                format(string, sizeof(string), "Stranger says: %s",text);
            }
        }
        else
        {
            if(PlayerInfo[playerid][pAccent] >= 2)
            {
                format(string, sizeof(string), "%s says: [Accent %s] %s",GetPlayerNameEx(playerid),GetPlayerAccent(playerid),text);
            }
            else
            {
                format(string, sizeof(string), "%s says: %s",GetPlayerNameEx(playerid),text);
            }
        }
        strcat((embed_msg[0] = '\0', embed_msg), string);
        FilterAsterisk(string);
        ProxDetector(20.0, playerid, string,COLOR_FADE1,COLOR_FADE2,COLOR_FADE3,COLOR_FADE4,COLOR_FADE5);SetPlayerChatBubble(playerid, string, COLOR_WHITE, 10.0, strlen(text)*100);
    }
    return 1;
}

Rep for help thanks
Reply
#2

The problem is that the string is 8 characters longer by the "strins".
Try this:

pawn Код:
stock FilterAsterisk(msg[], len = sizeof(msg)){
    new i=0,bool:pair = false;
    while(msg[i] != '\0'){
        if(msg[i] == '*'){
            if(!pair) strins(msg, "{800080}", i, len), i+=8;
            else strins(msg, "{FFFFFF}", i+1, len), i+=8;
            pair = !pair;
        }
        i++;
    }
}

Worked fine:
http://s7.directupload.net/images/140728/6wlwcdza.png



And if you want to delete the '*'-chars:
pawn Код:
stock FilterAsterisk(msg[], len = sizeof(msg)){
    new i=0,bool:pair = false;
    while(msg[i] != '\0'){
        if(msg[i] == '*'){
            if(!pair) strdel(msg,i,i+1), strins(msg, "{800080}", i, len), i+=8;
            else strdel(msg,i,i+1), strins(msg, "{FFFFFF}", i, len), i+=8;
            pair = !pair;
        }
        i++;
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)