09.03.2010, 00:59
Look i havea login system but i want it to save the team name when the player makes an accoun and when they come back they spawn with only that team .
Код:
#include <a_samp> #include <dini> #define COLOR_RED 0x660000AA #define RED 0xFF9900AA #define ORANGE 0xFF0000AA #define LIGHTBLUE 0x4B00B0AA #define LOGINMENU 0x9955DEEE #define COLOR_LIGHTRED 0xFF99AADD #define COLOR_SEAGREEN 0x00EEADDF #define COLOR_GRAYWHITE 0xEEEEFFC4 forward OnPlayerRegister(playerid, password[]); forward OnPlayerLogin(playerid,password[]); forward Stats(playerid,targetid); enum pInfo { pKills, pTeam, pJoins, pKey, pDeaths }; new PlayerInfo[MAX_PLAYERS][pInfo]; new gPlayerAccount[MAX_PLAYERS]; public OnPlayerDisconnect(playerid, reason) { SaveStats(playerid); return 1; } public OnPlayerConnect(playerid) { new Pname[24]; GetPlayerName(playerid, Pname, 24); new plname[MAX_PLAYER_NAME]; new playername4[MAX_PLAYER_NAME]; new string[160]; SendClientMessage(playerid,RED, "|| Welcome ||"); GameTextForPlayer(playerid,"~g~Welcome",4500,1); GetPlayerName(playerid, playername4, sizeof(playername4)); format(string, sizeof(string), " %s has joined. ", playername4); SendClientMessageToAll(COLOR_RED, string); gPlayerAccount[playerid] = 0; PlayerInfo[playerid][pJoins] += 1; GetPlayerName(playerid, plname, sizeof(plname)); format(string, sizeof(string), "%s.ini", plname); if(fexist(string)) { gPlayerAccount[playerid] = 1; new loginstring[128]; new loginname[64]; GetPlayerName(playerid,loginname,sizeof(loginname)); format(loginstring,sizeof(loginstring),"Welcome! \n \nThat name is registered. please enter your password below:"); ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Login",loginstring,"Login","Exit"); } else { gPlayerAccount[playerid] = 0; new regstring[128]; new regname[64]; GetPlayerName(playerid,regname,sizeof(regname)); format(regstring,sizeof(regstring),"Welcome ! \n \nPlease register your account by typing the password below:"); ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Register",regstring,"Register","Exit"); } return 1; } public OnPlayerCommandText(playerid, cmdtext[]) { if (strcmp(cmd, "/stats", true) == 0) { if(IsPlayerConnected(playerid)) { Stats(playerid,playerid); } return 1; } return 0; } public OnPlayerLogin(playerid,password[]) { new string2[64]; new playername2[MAX_PLAYER_NAME]; GetPlayerName(playerid, playername2, sizeof(playername2)); format(string2, sizeof(string2), "%s.ini", playername2); new File: UserFile = fopen(string2, io_read); if ( UserFile ) { new PassData[256]; new keytmp[256], valtmp[256]; fread( UserFile , PassData , sizeof( PassData ) ); keytmp = ini_GetKey( PassData ); if( strcmp( keytmp , "Key" , true ) == 0 ) { valtmp = ini_GetValue( PassData ); strmid(PlayerInfo[playerid][pKey], valtmp, 0, strlen(valtmp)-1, 255); } if(strcmp(PlayerInfo[playerid][pKey],password, true ) == 0 ) { new key[ 256 ] , val[ 256 ]; new Data[ 256 ]; while ( fread( UserFile , Data , sizeof( Data ) ) ) { key = ini_GetKey( Data ); if( strcmp( key , "Kills" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pKills] = strval( val ); } if( strcmp( key , "Deaths" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pDeaths] = strval( val ); } if( strcmp( key , "Team" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pTeam] = strval( val ); } if( strcmp( key , "Joins" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pJoins] = strval( val ); } }//end while fclose(UserFile);//close the file after everything has been read in the while } } return 1; } public OnPlayerRegister(playerid, password[]) { if(IsPlayerConnected(playerid)) { new string3[32]; new var[32]; new playername3[MAX_PLAYER_NAME]; GetPlayerName(playerid, playername3, sizeof(playername3)); format(string3, sizeof(string3), "%s.ini", playername3); new File: hFile = fopen(string3, io_write); if (hFile) { format(var, 32, "Kills=%d\n",PlayerInfo[playerid][pKills]);fwrite(hFile, var); format(var, 32, "Deaths=%d\n",PlayerInfo[playerid][pDeaths]);fwrite(hFile, var); format(var, 32, "Team=%d\n",PlayerInfo[playerid][pTeam]);fwrite(hFile, var); format(var, 32, "Joins=%d\n",PlayerInfo[playerid][pJoins]);fwrite(hFile, var); fclose(hFile); new loginstring[128]; new loginname[64]; GetPlayerName(playerid,loginname,sizeof(loginname)); format(loginstring,sizeof(loginstring),"Welcome \n \nThat name is in use. Please enter your password",loginname); ShowPlayerDialog(playerid,LOGINMENU,DIALOG_STYLE_INPUT,"Login",loginstring,"Login","Exit"); } } return 1; } public Stats(playerid,targetid) { if(IsPlayerConnected(playerid)&&IsPlayerConnected(targetid)) { new deaths = PlayerInfo[targetid][pDeaths]; new kills = PlayerInfo[targetid][pKills]; new team = PlayerInfo[targetid][pTeam]; new joins = PlayerInfo[targetid][pJoins]; new name[MAX_PLAYER_NAME]; GetPlayerName(targetid, name, sizeof(name)); new Float:px,Float:py,Float:pz; GetPlayerPos(targetid, px, py, pz); new coordsstring[256]; SendClientMessage(playerid, LIGHTBLUE,"||-----PLAYER STATS--------||"); format(coordsstring, sizeof(coordsstring),"- Player Name: %s -",name); SendClientMessage(playerid, ORANGE,coordsstring); format(coordsstring, sizeof(coordsstring), "Info: Kills:[%d] || Deaths:[%d]", kills,deaths); SendClientMessage(playerid, ORANGE,coordsstring); format(coordsstring, sizeof(coordsstring), "Info: Team:[%s] || Joins:[%d]", team,joins); SendClientMessage(playerid, ORANGE,coordsstring); SendClientMessage(playerid, LIGHTBLUE,"||-------------------------||"); } } stock PlayerName(playerid) { new name[255]; GetPlayerName(playerid, name, 255); return name; } public SaveStats(playerid) { if(IsPlayerConnected(playerid)) { new string3[128]; format(string3, sizeof(string3), "%s.ini", PlayerName(playerid)); new File: hFile = fopen(string3, io_write); if (hFile) { new var[32]; format(var, 32, "Kills=%d\n",PlayerInfo[playerid][pKills]);fwrite(hFile, var); format(var, 32, "Deaths=%d\n",PlayerInfo[playerid][pDeaths]);fwrite(hFile, var); format(var, 32, "Team=%s\n",PlayerInfo[playerid][pTeam]);fwrite(hFile, var); format(var, 32, "Joins=%d\n",PlayerInfo[playerid][pJoins]);fwrite(hFile, var); fclose(hFile); } } return 1; } stock ini_GetKey( line[] ) { new keyRes[256]; keyRes[0] = 0; if ( strfind( line , "=" , true ) == -1 ) return keyRes; strmid( keyRes , line , 0 , strfind( line , "=" , true ) , sizeof( keyRes) ); return keyRes; } stock ini_GetValue( line[] ) { new valRes[256]; valRes[0]=0; if ( strfind( line , "=" , true ) == -1 ) return valRes; strmid( valRes , line , strfind( line , "=" , true )+1 , strlen( line ) , sizeof( valRes ) ); return valRes; }