Re: How replace this with strins? -
MasonSFW - 02.11.2014
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;
}
How replace this with strins? -
MasonSFW - 02.11.2014
pawn Код:
GetPlayerName(id, Pnames, sizeof(Pnames));
new r[20];
format(r,sizeof(r), "%s", DMNAME(id));
strins(text, r, 0, 128);
SendClientMessageToAll(-1, text);
Re: How replace this with strins? -
MasonSFW - 02.11.2014
Bump
Re: How replace this with strins? -
Jefff - 02.11.2014
You need store text into array
pawn Код:
new str[145];
strcat(str, text);
strins(str, DMNAME(id), 0);
SendClientMessageToAll(-1, str);
Re: How replace this with strins? -
Quickie - 02.11.2014
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;
}
Re: How replace this with strins? -
MasonSFW - 02.11.2014
Rep+, for helping
Re: How replace this with strins? -
Quickie - 02.11.2014
BTW change the embedded color {000000} to {FFFFFF} thats color white
Re: How replace this with strins? -
MasonSFW - 02.11.2014
Also add loops too, please
Re: How replace this with strins? -
MasonSFW - 02.11.2014
Ohh it worked fine
![Smiley](images/smilies/smile.png)
Thank you so much
Re: How replace this with strins? -
Quickie - 02.11.2014
Enjoy
![Cheesy](images/smilies/biggrin.png)
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;
}