How replace this with strins?
#1

This code:

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;
        }
        GetPlayerName(id,pname,sizeof(pname));
        strdel(text,findid,findid+5);
        strins(text,pname,findid,sizeof(pname));
        SendClientMessageToAll(-1,text);
        return 0;
    }
    return 1;
}
Reply
#2

pawn Код:
GetPlayerName(id, Pnames, sizeof(Pnames));
     new r[20];
     format(r,sizeof(r), "%s", DMNAME(id));
     strins(text, r, 0, 128);
     SendClientMessageToAll(-1, text);
Reply
#3

Bump
Reply
#4

You need store text into array

pawn Код:
new str[145];
strcat(str, text);
strins(str, DMNAME(id), 0);
SendClientMessageToAll(-1, str);
Reply
#5

i got a better one
it only works for the first "id 0"
ill be adding loops later
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;
}
Reply
#6

Rep+, for helping
Reply
#7

BTW change the embedded color {000000} to {FFFFFF} thats color white
Reply
#8

Also add loops too, please
Reply
#9

Ohh it worked fine Thank you so much
Reply
#10

Enjoy
NOTE: you will have a problem if you dont set the player's color
pawn Код:
SetPlayerColor(playerid,color);
current "id's" limit 10

and heres your loop


EDIT: NEW VERSION (bug free)
PM me if you found any bugs

pawn Код:
public OnPlayerText(playerid, text[])
{
    new findid=strfind(text,"id",true,0);
    if(findid!=-1)
    {  
        new msg[20],id,extra,name[MAX_PLAYER_NAME],tempmsg[300],tempmsg2[300],index,success;
        format(tempmsg2,sizeof(tempmsg2),"%s",text);
        for(new i;i!=10;i++)
        {
            new pname[MAX_PLAYER_NAME];
            findid=strfind(tempmsg2,"id",true,index);
            index=findid+5;
            if(findid==-1)
            {
                break;
            }
            strmid(msg,tempmsg2,findid,findid+5);
            if(sscanf(msg,"uu",extra,id))
            {
                continue;
            }
            if(id==INVALID_PLAYER_ID)
            {
                continue;
            }
            GetPlayerName(id,pname,sizeof(pname));
            strdel(tempmsg2,findid,index);
            strins(tempmsg2,"{%06x}%s{FFFFFF} ",findid,strlen("{%06x}%s{FFFFFF}"));
            format(tempmsg,sizeof(tempmsg),tempmsg2,GetPlayerColor(id) >>> 8,pname);
            format(tempmsg2,sizeof(tempmsg2),"%s",tempmsg);
            success++;
        }
        if(success==0)
        {
            return 1;
        }
        GetPlayerName(playerid,name,sizeof(name));
        format(tempmsg2,sizeof(tempmsg2),"{%06x}%s:  {FFFFFF}",GetPlayerColor(playerid) >>> 8,name);
        strcat(tempmsg2,tempmsg);
        SendClientMessageToAll(-1,tempmsg2);
        return 0;
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)