17.05.2015, 06:28
(
Последний раз редактировалось Airman123; 18.05.2015 в 05:09.
)
SOLVED
CheckQuickStrings(playerid, string[])
{
if(strfind(string, "$loc", true) != -1)
{
new zone[MAX_ZONE_NAME];
GetPlayer2DZone(playerid, zone, MAX_ZONE_NAME);
strreplace(string, "$loc", zone, true, .maxlength = 144);
}
if(strfind(string, "$cash", true) != -1)
{
new pmoney[10];
format(pmoney, sizeof(pmoney), "$%d", GetPlayerCash(playerid));
strreplace(string, "$cash", pmoney, true, .maxlength = 144);
}
if(strfind(string, "$ply", true) != -1)
{
new id = GetPlayerWhoIsClosest(playerid), closeststr[32];
if(!IsPlayerConnected(id)) id = playerid;
format(closeststr, sizeof(closeststr), "%s (%d)", PlayerInfo[id][pName], id);
strreplace(string, "$ply", closeststr, true, .maxlength = 144);
}
return 1;
}
stock strreplace(string[], const search[], const replacement[], bool:ignorecase = false, pos = 0, limit = -1, maxlength = sizeof(string)) // Credit to Slice
{
if(!limit) return 0;
new sublen = strlen(search);
if(!sublen) return 0;
if(!strcmp(search, replacement, ignorecase)) return 0;
new
bool:packed = ispacked(string),
maxlen = maxlength,
replen = strlen(replacement),
len = strlen(string),
count = 0
;
if(packed) maxlen *= 4;
while(-1 != (pos = strfind(string, search, ignorecase, pos)))
{
strdel(string, pos, pos + sublen);
len -= sublen;
if((replen) && ((len + replen) < maxlen))
{
strins(string, replacement, pos, maxlength);
pos += replen;
len += replen;
}
if(limit != -1 && ++count >= limit) break;
}
return count;
}
@Threshold wouldn't you code be slower?PAWN is way way slower than natives. |
public OnPlayerText(playerid, text[])
{
// other codes
// end
new string11[144];
strcat(string11, text);
CheckQuickStrings(playerid, string11);
SendPlayerMessageToAll(playerid, string11);
return 0;
}