SA-MP Forums Archive
Problem with STRINS - 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: Problem with STRINS (/showthread.php?tid=544283)



Problem with STRINS - Quickie - 01.11.2014

hello
am i using the strins the right way it should be used?

pawn Код:
public OnPlayerText(playerid, text[])
{
    new findid=strfind(text,"id",true,0);
    if(findid!=-1)
    {  
        new msg[20],id,extra,pname[MAX_PLAYER_NAME];
        strmid(msg,text,findid,findid+5);
        if(sscanf(msg,"uu",extra,id))
        {
            return 1;
        }
        if(id==INVALID_PLAYER_ID)
        {
            return 1;
        }
        printf("findid %d",findid);
        GetPlayerName(id,pname,sizeof(pname));
        printf("sizeof %d",sizeof(pname));
        printf("strlen %d",strlen(pname));
        printf( "getname %s",pname);
        strdel(text,findid,findid+5);
        print("strdel");
        strins(text,pname,findid,sizeof(pname));
       
        print("strins");
       
        printf("%s",text);
        SendClientMessageToAll(-1,text);
        return 0;
    }
    return 1;
}
i typed to my client
Quote:

test hello hello 0 id 0 yes hello

the result is
Quote:

test hello hello 0 yes hello

the id 0 should be replaced with my name (Quickie) but nothing happens and it looks like my code finished in strins

THE console print
Код:
findid 19
sizeof 24
strlen 7
getname Quickie
strdel
and the code stopped at strdel

i hope you can help me with this problem

thank you in advance


Re: Problem with STRINS - MasonSFW - 01.11.2014

Help this post pleassess


Re: Problem with STRINS - BroZeus - 01.11.2014

instead of using strfind and strdel and strins use str_replace
Information about str_replace - https://sampwiki.blast.hk/wiki/Strlib/str_replace
so new code would be-
pawn Код:
public OnPlayerText(playerid, text[])
{
    new findid=strfind(text,"id",true,0);
    if(findid!=-1)
    {  
        new msg[20],id,extra,pname[MAX_PLAYER_NAME];
        strmid(msg,text,findid,findid+5);
        if(sscanf(msg,"uu",extra,id))
        {
            return 1;
        }
        if(id==INVALID_PLAYER_ID)
        {
            return 1;
        }
        printf("findid %d",findid);
        GetPlayerName(id,pname,sizeof(pname));
        printf("sizeof %d",sizeof(pname));
        printf("strlen %d",strlen(pname));
        printf( "getname %s",pname);
        new r[20];
        format(r,sizeof(r),"id %i",id);//added this line
        str_replace(r, pname, text);//added this line
        printf("%s",text);
        SendClientMessageToAll(-1,text);
        return 0;
    }
    return 1;
}
str_replace function is part of strlib include which can be found here - https://sampforum.blast.hk/showthread.php?tid=85697


Re: Problem with STRINS - MasonSFW - 01.11.2014

Thank but it not work im tested.

player ID 0 name is Ganker

I said (Sparks is my name)

Quote:

Sparks: Hey id 0

replace to

Quote:

Hey id 0




Re: Problem with STRINS - Quickie - 02.11.2014

FIXED
pawn Код:
public OnPlayerText(playerid, text[])
{
    new findid=strfind(text,"id",true,0);
    if(findid!=-1)
    {  
        new msg[20],id,extra,pname[MAX_PLAYER_NAME],name[MAX_PLAYER_NAME];
        strmid(msg,text,findid,findid+5);
        if(sscanf(msg,"uu",extra,id))
        {
            return 1;
        }
        if(id==INVALID_PLAYER_ID)
        {
            return 1;
        }
        printf("findid %d",findid);
        GetPlayerName(id,pname,sizeof(pname));
        GetPlayerName(playerid,name,sizeof(name));
        strdel(text,findid,findid+5);
        new tempmsg[128],chat[128];
        strins(text,"%s ",findid,strlen("%s"));
        format(chat,sizeof(chat),"{%06x}%s: {FFFFFF}",GetPlayerColor(playerid) >>> 8,name);
        format(tempmsg,sizeof(tempmsg),text,pname);
        strcat(chat,tempmsg);
        SendClientMessageToAll(-1,chat);
        return 0;
    }
    return 1;
}