Help me - Quick Strings ($ply, $cash e.t.c)
#1

SOLVED
Reply
#2

I'd recommend using strreplace by Slice instead.

pawn Код:
CheckQuickStrings(playerid, string[])
{
    if(strfind(string, "$loc", true) != -1)
    {
        new zone[MAX_ZONE_NAME];
        GetPlayer2DZone(playerid, zone, MAX_ZONE_NAME);
        strreplace(string, "$loc", zone, true, .maxlength = 144);
    }
    if(strfind(string, "$cash", true) != -1)
    {
        new pmoney[10];
        format(pmoney, sizeof(pmoney), "$%d", GetPlayerCash(playerid));
        strreplace(string, "$cash", pmoney, true, .maxlength = 144);
    }
    if(strfind(string, "$ply", true) != -1)
    {
        new id = GetPlayerWhoIsClosest(playerid), closeststr[32];
        if(!IsPlayerConnected(id)) id = playerid;
        format(closeststr, sizeof(closeststr), "%s (%d)", PlayerInfo[id][pName], id);
        strreplace(string, "$ply", closeststr, true, .maxlength = 144);
    }
    return 1;
}

stock strreplace(string[], const search[], const replacement[], bool:ignorecase = false, pos = 0, limit = -1, maxlength = sizeof(string)) // Credit to Slice
{
    if(!limit) return 0;
    new sublen = strlen(search);
    if(!sublen) return 0;
    if(!strcmp(search, replacement, ignorecase)) return 0;
    new
            bool:packed = ispacked(string),
            maxlen = maxlength,
            replen = strlen(replacement),
            len = strlen(string),
            count = 0
    ;
    if(packed) maxlen *= 4;
    while(-1 != (pos = strfind(string, search, ignorecase, pos)))
    {
        strdel(string, pos, pos + sublen);
        len -= sublen;
        if((replen) && ((len + replen) < maxlen))
        {
            strins(string, replacement, pos, maxlength);
            pos += replen;
            len += replen;
        }
        if(limit != -1 && ++count >= limit) break;
    }
    return count;
}
Reply
#3

If you are returning 0 in OnPlayerText then the chat message won't be sent.

Possible reasons I can think of:
Your do...while goes into an infinite loop - but you said that the messages are printed in your console(server log) so an infinite loop cannot be the problem

You are returning 0 at OnPlayerText, show us your OPT callback.

I am guessing that using string again is causing the problem.Try with another string.
Don't use the argument string.Make a local array to do the replacements then use strcat to copy it back.
@Threshold wouldn't you code be slower?PAWN is way way slower than natives.
Reply
#4

- Solved.
Reply
#5

Change return 1 to return 0.

EDIT:
Quote:

@Threshold wouldn't you code be slower?PAWN is way way slower than natives.

What are you talking about? There is no native function to replace a string...
Reply
#6

- Solved.
Reply
#7

If OnPlayerText returns 1, it will send the original text to main chat... that is why you still see the quickstrings as '$loc' etc.

Return 0...

pawn Код:
public OnPlayerText(playerid, text[])
{
// other codes

// end
    new string11[144];
    strcat(string11, text);
    CheckQuickStrings(playerid, string11);
    SendPlayerMessageToAll(playerid, string11);
    return 0;
}
https://sampwiki.blast.hk/wiki/OnPlayerText
Reply
#8

Thanks You Very much, @Threshold. +REP man

Thanks <3
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)