01.12.2009, 12:47
Well, basicly it dont save the money a player earns.
I tried to put GivePlayerMoney to see if it really works or not, it gave me the cash and updated it into the .ini file etc.
When I tested to reconnect, the money was gone...
Here is my Register System:
I got the rest of the functions like String and strtok.
I tried to put GivePlayerMoney to see if it really works or not, it gave me the cash and updated it into the .ini file etc.
When I tested to reconnect, the money was gone...
Here is my Register System:
Код:
enum Info { pPassword[128], pCash, }; new PlayerInfo[MAX_PLAYERS][Info]; new gPlayerLogged[MAX_PLAYERS]; new gPlayerAccount[MAX_PLAYERS]; forward OnPlayerLogin(playerid,const string[]); forward OnPlayerUpdate(playerid); forward ShowStats(playerid,targetid); public OnPlayerDisconnect(playerid, reason) { gPlayerLogged[playerid] = 0; OnPlayerUpdate(playerid); return 1; } public OnPlayerCommandText(playerid, cmdtext[]) { new cmd[256]; new idx; new string[256]; cmd = strtok(cmdtext, idx); new tmp[256]; new playername[MAX_PLAYER_NAME]; new sendername[MAX_PLAYER_NAME]; if (strcmp(cmd, "/login", true) ==0) { if(IsPlayerConnected(playerid)) { new tmppass[64]; if(gPlayerLogged[playerid] == 1) { SendClientMessage(playerid, 0xC0C0C0FF, " You are already logged in"); return 1; } tmp = strtok(cmdtext, idx); if(!strlen(tmp)) { SendClientMessage(playerid, 0xC0C0C0FF, " USAGE: /login [password]"); return 1; } strmid(tmppass, tmp, 0, strlen(cmdtext), 255); String(tmppass); OnPlayerLogin(playerid,tmppass); SpawnPlayer(playerid); } return 1; } if (strcmp(cmd, "/register", true) ==0) { tmp = strtok(cmdtext, idx); if(!strlen(tmp)) { SendClientMessage(playerid, 0xC0C0C0FF, " USAGE: /register [password]"); return 1; } if (gPlayerAccount[playerid] == 1) { SendClientMessage(playerid, 0xC0C0C0FF, " That nickname is already registered"); return 1; } strmid(PlayerInfo[playerid][pPassword], tmp, 0, strlen(cmdtext), 255); String(PlayerInfo[playerid][pPassword]); GetPlayerName(playerid, playername, sizeof(playername)); format(string, sizeof(string), "%s.cer", playername); new File: file = fopen(string, io_read); if (file) { SendClientMessage(playerid, 0xC0C0C0FF, " That name is already registered"); fclose(file); return 1; } new File:hFile; hFile = fopen(string, io_append); new var[32];// format(var, 32, "%s\n", PlayerInfo[playerid][pPassword]);fwrite(hFile, var); PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid); format(var, 32, "Cash:%d\n",PlayerInfo[playerid][pCash]);fwrite(hFile, var); fclose(hFile); SendClientMessage(playerid, 0xFFFFFFFF, "You have been successfully registered, you will now be sent to the tutorial, please pay attenton."); GivePlayerMoney(playerid,PlayerInfo[playerid][pCash]); OnPlayerLogin(playerid,PlayerInfo[playerid][pPassword]); SpawnPlayer(playerid); return 1; } if (strcmp(cmd, "/stats", true) == 0) { if(IsPlayerConnected(playerid)) { if (gPlayerLogged[playerid] != 0) { ShowStats(playerid,playerid); } else { SendClientMessage(playerid, 0xC0C0C0FF, " You are not logged in."); } } return 1; } public OnPlayerLogin(playerid,const string[]) { new pname2[MAX_PLAYER_NAME]; new pname3[MAX_PLAYER_NAME]; new string2[64]; new string3[128]; GetPlayerName(playerid, pname2, sizeof(pname2)); format(string2, sizeof(string2), "%s.cer", pname2); new File: UserFile = fopen(string2, io_read); if (UserFile) { new valtmp[128]; fread(UserFile, valtmp);strmid(PlayerInfo[playerid][pPassword], valtmp, 0, strlen(valtmp)-1, 255); if ((strcmp(PlayerInfo[playerid][pPassword], string, true, strlen(valtmp)-1) == 0)) { new key[128],val[128]; new Data[128]; while(fread(UserFile,Data,sizeof(Data))) { key = ini_GetKey(Data); if( strcmp( key , "Cash" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pCash] = strval( val ); } GivePlayerMoney(playerid,PlayerInfo[playerid][pCash]); } fclose(UserFile); gPlayerLogged[playerid] = 1; gPlayerAccount[playerid] = 1; GetPlayerName(playerid, pname3, sizeof(pname3)); format(string3, sizeof(string3), "You have been successfully logged in"); SendClientMessage(playerid, 0xFFFFFFFF,string3); } else { SendClientMessage(playerid, 0xC0C0C0FF, " Invalid Password"); fclose(UserFile); } } return 1; } stock ini_GetKey( line[] ) { new keyRes[128]; 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[128]; valRes[0]=0; if ( strfind( line , "=" , true ) == -1 ) return valRes; strmid( valRes , line , strfind( line , "=" , true )+1 , strlen( line ) , sizeof( valRes ) ); return valRes; } public OnPlayerUpdate(playerid) { if(IsPlayerConnected(playerid)) { if(gPlayerLogged[playerid]) { new string3[32]; new pname3[MAX_PLAYER_NAME]; GetPlayerName(playerid, pname3, sizeof(pname3)); format(string3, sizeof(string3), "%s.cer", pname3); new File: pFile = fopen(string3, io_write); if (pFile) { new var[32]; format(var, 32, "%s\n", PlayerInfo[playerid][pPassword]);fwrite(pFile, var); fclose(pFile); new File: hFile = fopen(string3, io_append); PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid); format(var, 32, "Cash:%d\n",PlayerInfo[playerid][pCash]);fwrite(hFile, var); fclose(hFile); } } } return 1; } public ShowStats(playerid,targetid) { if(IsPlayerConnected(playerid)&&IsPlayerConnected(targetid)) { new cash = GetPlayerMoney(targetid); 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]; format(coordsstring, sizeof(coordsstring),"------------------- %s -------------------",name); SendClientMessage(playerid, 0xFFFFFFFF,coordsstring); format(coordsstring, sizeof(coordsstring), "Cash: [$%d]",cash); SendClientMessage(playerid, 0xC0C0C0FF,coordsstring); SendClientMessage(playerid, 0xFFFFFFFF,"-------------------------------------------------------------"); } }