SA-MP Forums Archive
[SOLVED] Need some help with strreplace - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [SOLVED] Need some help with strreplace (/showthread.php?tid=144740)



[SOLVED] Need some help with strreplace - [03]Garsino - 28.04.2010

pawn Код:
public OnPlayerText(playerid, text[])
{
    if(strfind(text, "$mb", true))
    {
        format(string,sizeof(string),"%d Mystery Bags Found", PlayerInfo[playerid][MysteryBagsFound]);
        strreplace("$mb", string, text);
    }
    return 1;
}
Ok, so the code doesn't give any errors or anything. But it just doesn't work. It sends the original message and not the one with the replaced "$mb".

First time with strreplace, so yeah, I could need some help


Re: Need some help with strreplace - M4S7ERMIND - 28.04.2010

Try with SendPlayerMessageToAll:
pawn Код:
if(strfind(text, "$mb", true))
{
  format(string,sizeof(string),"%d Mystery Bags Found", PlayerInfo[playerid][MysteryBagsFound]);
  SendPlayerMessageToAll(playerid, strreplace("$mb", string, text));
  return 0;
}



Re: Need some help with strreplace - [03]Garsino - 29.04.2010

Problem solved, bpeterson helped me (<3). So yeah, it didn't work with the normal strreplace, so he gave me a custom function and now it works.


Re: [SOLVED] Need some help with strreplace - bpeterson - 29.04.2010

Yes, I suggest to use this function:

pawn Код:
stock strreplace2(string[], const find[], const replace[], bool:ignorecase=false, count=cellmax, maxlength=sizeof(string))
{
    if(isnull(find) || isnull(string)) return 0;
    new matches;
    for(new idx, flen = strlen(find), rlen = strlen(replace), pos = strfind(string, find, ignorecase); pos != -1 && idx < maxlength && matches < count; pos = strfind(string, find, ignorecase, idx)) {
        strdel(string, pos, pos + flen);
        if(rlen) strins(string, replace, pos, maxlength);   // Crashy
        idx = pos + rlen;
        matches++;
    }
    return matches;
}