problem with SetPlayerName function.
#1

PHP код:
            new name2[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
            
GetPlayerName(playeridname2sizeof(name2));
            
strmid(pInfo[playerid][Name], name2024);
            
format(stringsizeof(string), "%i_%s",pInfo[playerid][Respect], name2);
            
SetPlayerName(playeridstring); 


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.
Reply
#2

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.
Reply
#3

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 falsepos 0limit = -1maxlength 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 (-!= (pos strfind(stringsearchignorecasepos))) {
        
// Delete the string we found
        
strdel(stringpospos 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(stringreplacementposmaxlength);
            
            
pos += replen;
            
len += replen;
        }
        
        
// Is there a limit of number of replacements, if so, did we break it?
        
if (limit != -&& ++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)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)