Quick Strings... Problem
#1

Hello im using Quick Stringsm and i got bug in it some pictures are given below.

when i type /me $loc


result..


it shows message to times.. but i want to send one time also with Player Name and ID.


My Code..
strings code..
pawn Код:
CheckQuickStrings(playerid, text[])
{
    new idx = strfind(text, "$");

    if(idx != -1)
    {
        new string[144];
        strcat(string, text);
        do
        {
            if(strcmp(string[idx], "$loc", true, 4) == 0)
            {
                new zone[MAX_ZONE_NAME];
                GetPlayer2DZone(playerid, zone, MAX_ZONE_NAME);

                strdel(string, idx, idx + 4);
                strins(string, zone, idx);
                continue;
            }
            else
            if(strcmp(string[idx], "$cash", true, 5) == 0)
            {
                new pmoney[70];
                format(pmoney, sizeof(pmoney), "$%d",GetPlayerCash(playerid));

                strdel(string, idx, idx + 5);
                strins(string, pmoney, idx);
                continue;
            }
            else
            if(strcmp(string[idx], "$ply", true, 4) == 0)
            {
                new closeststr[100], closestplayer = GetPlayerWhoIsClosest(playerid);

                if(IsPlayerConnected(closestplayer))
                format(closeststr, sizeof(closeststr), "%s (%d)",PlayerInfo[closestplayer][pName],closestplayer);
                else
                format(closeststr, sizeof(closeststr), "%s (%d)",PlayerInfo[playerid][pName], playerid);

                strdel(string, idx, idx + 4);
                strins(string, closeststr, idx);
                continue;
            }
        }
        while((idx = strfind(string, "$", false, idx + 1)) != -1);

        SendPlayerMessageToAll(playerid, string);
    }
    return 1;
}
* danish007 command..
pawn Код:
COMMAND:me(playerid, params[])
{
    return cmd_say(playerid, params);
}
COMMAND:say(playerid, params[])
{
        if (PlayerInfo[playerid][pSpawned] == 1)
        {
        new idx,string[256],length = strlen(params);
        while ((idx < length) && (params[idx] <= ' '))
        {
            idx++;
        }
        new offset = idx;
        new result[512];
        while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
        {
            result[idx - offset] = params[idx];
            idx++;
        }
        result[idx - offset] = EOS;
       
        if(stringContainsIP(result))
        {
        SendClientMessage(playerid,COLOR_ERROR,"Invalid Message.");
        return 1;
        }

        if (PlayerInfo[playerid][pMuted] == 1)
        {
            SendClientMessage(playerid,COLOR_ERROR,"#Error: You Muted.");
            return 1;
        }

        if (!strlen(result))
        {
            SendClientMessage(playerid, COLOR_ERROR, "USAGE: /me (message).");
            return 1;
        }
        format(string, sizeof(string), "%s (%d): %s",PlayerInfo[playerid][pName], playerid, result);
       
        CheckQuickStrings(playerid, result);
        SendClientMessageToAll(GetPlayerColor(playerid), string);
        }else{
        SendClientMessage(playerid, COLOR_ERROR, "You Cannot Use This Command When You're Dead.");
        }
        return 1;
}
helper will get +rep
Reply
#2

REMOVED
Reply
#3

but these $loc or $anytstrings are already defined in it?

[EDIT]: not works..
Reply
#4

Mix the stock and command together and it'll fix the problem.
Reply
#5

Well, you're sending 2 messages, of course you'll see both of them.
The first one is inside the QuickStrings function,
pawn Код:
SendPlayerMessageToAll(playerid, string);
The second one is sent by the command:
pawn Код:
SendClientMessageToAll(GetPlayerColor(playerid), string);
Remove one of them and it will work properly. Also, OnPlayerText callback prints a message of its own, so you'll have to return 0 to stop the default message from being printed. Be careful when doing that, because if you don't type anything that contains your keywords ("$loc" or whatever), the server won't print any message (because your function won't find the keyword and OnPlayerText is blocked by the return 0).
Reply
#6

HazardouS already told you the problem

if you want to use the function a bit more dynamic you should remove some parts
so it only modifies the string and doesn't send anything
pawn Код:
CheckQuickStrings(playerid, string[], size = sizeof string)
{
    new idx = strfind(string, "$");

    if(idx != -1)
    {
        do
        {
            if(strcmp(string[idx], "$loc", true, 4) == 0)
            {
                new zone[MAX_ZONE_NAME];
                GetPlayer2DZone(playerid, zone, MAX_ZONE_NAME);

                strdel(string, idx, idx + 4);
                strins(string, zone, idx, size);
                continue;
            }
            if(strcmp(string[idx], "$cash", true, 5) == 0)
            {
                new pmoney[32];
                format(pmoney, sizeof(pmoney), "$%d",GetPlayerCash(playerid));

                strdel(string, idx, idx + 5);
                strins(string, pmoney, idx, size);
                continue;
            }
            if(strcmp(string[idx], "$ply", true, 4) == 0)
            {
                new id = GetPlayerWhoIsClosest(playerid);
                if(!IsPlayerConnected(id)) id = playerid;

                new closeststr[32];
                format(closeststr, sizeof(closeststr), "%s (%d)", PlayerInfo[id][pName], id);

                strdel(string, idx, idx + 4);
                strins(string, closeststr, idx, size);
                continue;
            }
        }
        while((idx = strfind(string, "$", false, idx + 1)) != -1);

        return true;
    }
    return false;
}
pawn Код:
COMMAND:say(playerid, params[])
{
    if (PlayerInfo[playerid][pSpawned] != 1)
        return SendClientMessage(playerid, COLOR_ERROR, "You Cannot Use This Command When You're Dead.");
    if (PlayerInfo[playerid][pMuted] == 1)
        return SendClientMessage(playerid,COLOR_ERROR,"#Error: You Muted.");
    if (!strlen(params))
        return SendClientMessage(playerid, COLOR_ERROR, "USAGE: /me (message).");
    if (stringContainsIP(params))
        return SendClientMessage(playerid,COLOR_ERROR,"Invalid Message.");

    new string[144];

    strcat(string, params);
    CheckQuickStrings(playerid, string); // replaces all tags inside string
    format(string, sizeof(string), "%s (%d): %s",PlayerInfo[playerid][pName], playerid, string);

    return SendClientMessageToAll(GetPlayerColor(playerid), string);
}
You probably need to edit OnPlayerText also
pawn Код:
new string[144];
strcat(string, text);
CheckQuickStrings(playerid, string);
SendPlayerMessageToAll(playerid, string);
return false;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)