View Full Version : Save statsistic on name
Rocky
13th August 2014, 09:21
How to save statistic on player name?
Who can help?
Thanks!
malyczolg
13th August 2014, 09:46
f=openfile("users/stats/"+self.name+".cfg", "write");
fprintln(f, self.stat["rank"]);
fprintln(f, self.stat["xp"]);
fprintln(f, self.stat["needxp"]);
fprintln(f, self.stat["prestige"]);
closefile(f);
Mitch
13th August 2014, 10:32
Saving files on a player's name might cause trouble when the name contains an invalid character.
Tally
13th August 2014, 15:50
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:
filename = sanitizeName( self.name ) + "_data.ini;
sanitizeName( str )
{
if( !isDefined( str ) || str == "" ) return "";
validchars = "0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTt UuVvWwXxYyZz";
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 );
}
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.