problem with SetPlayerName function. -
wallen - 07.02.2018
PHP код:
new name2[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
GetPlayerName(playerid, name2, sizeof(name2));
strmid(pInfo[playerid][Name], name2, 0, 24);
format(string, sizeof(string), "%i_%s",pInfo[playerid][Respect], name2);
SetPlayerName(playerid, string);
I only wanted to show 1 number 12314_ example. not 1231_123_125415_12312 etc...
And how to detect when someone like types /stats 2 instead saying "You viewing the stats of player 213124_Nickname, without these numbers? I put that on the onplayerupdate callbacj so it would update everytime he gets new respects.
Re: problem with SetPlayerName function. -
Eoussama - 07.02.2018
While not necessarily bad, using
strcpy for string copying is better.
In most cases, using
OnPlayerUpdate is bad practice, or at least, in this case, it's better if to use a timer, or even better, call the function that updates the player's name inside the function responsible for changing the player's respect points.
Re: problem with SetPlayerName function. -
Mugala - 08.02.2018
you can basically use one of the Slice's function, strreplace and replace these numbers with nothing (not a spaces, just nothing).
PHP код:
stock strreplace(string[], const search[], const replacement[], bool:ignorecase = false, pos = 0, limit = -1, maxlength = sizeof(string)) {
// No need to do anything if the limit is 0.
if (limit == 0)
return 0;
new
sublen = strlen(search),
replen = strlen(replacement),
bool:packed = ispacked(string),
maxlen = maxlength,
len = strlen(string),
count = 0
;
// "maxlen" holds the max string length (not to be confused with "maxlength", which holds the max. array size).
// Since packed strings hold 4 characters per array slot, we multiply "maxlen" by 4.
if (packed)
maxlen *= 4;
// If the length of the substring is 0, we have nothing to look for..
if (!sublen)
return 0;
// In this line we both assign the return value from "strfind" to "pos" then check if it's -1.
while (-1 != (pos = strfind(string, search, ignorecase, pos))) {
// Delete the string we found
strdel(string, pos, pos + sublen);
len -= sublen;
// If there's anything to put as replacement, insert it. Make sure there's enough room first.
if (replen && len + replen < maxlen) {
strins(string, replacement, pos, maxlength);
pos += replen;
len += replen;
}
// Is there a limit of number of replacements, if so, did we break it?
if (limit != -1 && ++count >= limit)
break;
}
return count;
}
for example, let's say that player's name is George12 or Ge1o2rge
PHP код:
new name[28],string[128];
GetPlayerName(playerid,name,28);
strreplace(name, "1", "");
strreplace(name, "2", "");
format(string,sizeof(string),"Hello %s",name);
so output will be like this.
Hello George (instead of numbers in names)