SA-MP Forums Archive
strreplace problem - 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: strreplace problem (/showthread.php?tid=280084)



strreplace problem - antonio600x - 30.08.2011

Code:
C:\Documents and Settings\Administrator\Desktop\SAMP SERVER\gamemodes\gmbeta.pwn(191) : error 035: argument type mismatch (argument 2)
C:\Documents and Settings\Administrator\Desktop\SAMP SERVER\gamemodes\gmbeta.pwn(192) : error 029: invalid expression, assumed zero
C:\Documents and Settings\Administrator\Desktop\SAMP SERVER\gamemodes\gmbeta.pwn(402) : error 025: function heading differs from prototype
C:\Documents and Settings\Administrator\Desktop\SAMP SERVER\gamemodes\gmbeta.pwn(403) : error 021: symbol already defined: "strreplace"
C:\Documents and Settings\Administrator\Desktop\SAMP SERVER\gamemodes\gmbeta.pwn(411) : warning 209: function "strreplace" should return a value
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
Code:
public OnPlayerText(playerid, text[])
{
    new pname[MAX_PLAYER_NAME], str[128];
    GetPlayerName(playerid, pname, sizeof(pname));
    strreplace(pname, '_', ' ');/191
    format(str, sizeof(str), "%s says: %s", pname, text);.
    ProxDetector(30.0, playerid, str, COLOR_FADE1, COLOR_FADE2, COLOR_FADE3, COLOR_FADE4, COLOR_FADE5);
    return 0;
}
Code:
stock strreplace(string[], find, replace)//402
{//403
    for(new i=0; string[i]; i++)
    {
        if(string[i] == find)
        {
            string[i] = replace;
        }
    }
}//411
how to fix that?


Re: strreplace problem - Pinguinn - 30.08.2011

You have already 'strreplace', but try this

pawn Code:
stock strreplace(string[], find, replace)
{
    for(new i=0; string[i]; i++)
    {
        if(string[i] == find)
        {
            string[i] = replace;
        }
    }
    return replace;
}



Re: strreplace problem - antonio600x - 30.08.2011

Code:
C:\Documents and Settings\Administrator\Desktop\SAMP SERVER\gamemodes\gmbeta.pwn(191) : error 035: argument type mismatch (argument 2)
C:\Documents and Settings\Administrator\Desktop\SAMP SERVER\gamemodes\gmbeta.pwn(192) : error 029: invalid expression, assumed zero
C:\Documents and Settings\Administrator\Desktop\SAMP SERVER\gamemodes\gmbeta.pwn(402) : error 025: function heading differs from prototype
C:\Documents and Settings\Administrator\Desktop\SAMP SERVER\gamemodes\gmbeta.pwn(403) : error 021: symbol already defined: "strreplace"
C:\Documents and Settings\Administrator\Desktop\SAMP SERVER\gamemodes\gmbeta.pwn(411) : error 079: inconsistent return types (array & non-array)



Re: strreplace problem - JaTochNietDan - 30.08.2011

You could easily use the standard strfind function to do the same thing, for example:

pawn Code:
public OnPlayerText(playerid, text[])
{
    new pname[MAX_PLAYER_NAME], str[128];
    GetPlayerName(playerid, pname, sizeof(pname));

    pname[strfind(pname, "_", false)] = ' '; // Find the location of _ in the array and replace it with a space!

    format(str, sizeof(str), "%s says: %s", pname, text);
    ProxDetector(30.0, playerid, str, COLOR_FADE1, COLOR_FADE2, COLOR_FADE3, COLOR_FADE4, COLOR_FADE5);
    return 0;
}
Simple as that, no need for a custom function!


Re: strreplace problem - antonio600x - 30.08.2011

C:\Documents and Settings\Administrator\Desktop\SAMP SERVER\gamemodes\gmbeta.pwn(195) : error 029: invalid expression, assumed zero


format(str, sizeof(str), "%s kaze: %s", pname, text);.


Re: strreplace problem - JaTochNietDan - 30.08.2011

Is that a full stop that's in your code too after the semi colon? Or did you just write it in the post, I suggest using pawn BBCode in future to make it easier to see.

Anyway, there shouldn't be a fullstop there.