Results 1 to 4 of 4

Thread: Save statsistic on name

  1. #1
    Private First Class
    Join Date
    Jul 2013
    Posts
    170
    Thanks
    44
    Thanked 16 Times in 11 Posts

    Save statsistic on name

    How to save statistic on player name?

    Who can help?

    Thanks!

  2. #2
    Private First Class
    Join Date
    Feb 2013
    Posts
    201
    Thanks
    4
    Thanked 10 Times in 7 Posts
    PHP Code:
    f=openfile("users/stats/"+self.name+".cfg""write");
    fprintln(fself.stat["rank"]);
    fprintln(fself.stat["xp"]);
    fprintln(fself.stat["needxp"]);
    fprintln(fself.stat["prestige"]);
    closefile(f); 

  3. #3
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts
    Saving files on a player's name might cause trouble when the name contains an invalid character.

  4. #4
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by Mitch View Post
    Saving files on a player's name might cause trouble when the name contains an invalid character.
    Indeed, which is why you should always strip a player's name from any non-alphanumeric symbols. This is the method I use:

    Code:
     filename = sanitizeName( self.name ) + "_data.ini;
    Code:
    sanitizeName( str )
    {
    	if( !isDefined( str ) || str == "" ) return "";
    
    	validchars = "0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz";
    
    	tmpname = monotone( str );
    	string = "";
    	prevchr = "";
    	for( i = 0; i < tmpname.size; i++ )
    	{
    		chr = tmpname[i];
    		if( chr == "." )
    		{
    			if( !string.size ) continue; // avoid leading dots
    			if( chr == prevchr ) continue; // avoid double dots
    		}
    		else if( chr == "[" ) chr = "{";
    		else if( chr == "]" ) chr = "}";
    
    		prevchr = chr;
    		for( j = 0; j < validchars.size; j++ )
    		{
    			if( chr == validchars[j] )
    			{
    				string += chr;
    				break;
    			}
    		}
    	}
    
    	if( string == "" ) string = "noname";
    	
    	return string;
    }
    
    monotone( str )
    {
    	if( !isDefined( str ) || ( str == "" ) )
    		return( "" );
    
    	s = "";
    
    	colorCheck = false;
    	for( i = 0; i < str.size; i++ )
    	{
    		ch = str[ i ];
    		if( colorCheck )
    		{
    			colorCheck = false;
    
    			switch( ch )
    			{
    				case "0":	// black
    				case "1":	// red
    				case "2":	// green
    				case "3":	// yellow
    				case "4":	// blue
    				case "5":	// cyan
    				case "6":	// pink
    				case "7":	// white
    				case "8":	// Olive
    				case "9":	// Grey
    					break;
    				
    				default:
    					s += ( "^" + ch );
    					break;
    			}
    		}
    		else if( ch == "^" )
    			colorCheck = true;
    		else
    			s += ch;
    	}
    	
    	return( s );
    }

  5. The Following 2 Users Say Thank You to Tally For This Useful Post:

    Ni3ls (13th August 2014),Rocky (17th August 2014)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •