05.01.2011, 14:42
(
Последний раз редактировалось Michael@Belgium; 05.01.2011 в 20:03.
Причина: SOLVED !
)
I have a problem, it's saving everything except the points ...
PLZ help me
... or give me a other working account system ..
SOLVED
Код:
#include <a_samp> forward RegisterPlayer(playerid, password[]); forward LoginPlayer(playerid, password[]); forward SavePlayer(playerid); enum aAcc { aPassword[128], aScore, aCash, Float:aX, Float:aY, Float:aZ, Float:aA, aLogged, } new AccountInfo[MAX_PLAYERS][aAcc]; public RegisterPlayer(playerid, password[]) { if(IsPlayerConnected(playerid)) { new name[MAX_PLAYER_NAME], str[128]; GetPlayerName(playerid, name, sizeof name); format(str, sizeof str, "%s.ini", name); new File:account = fopen(str, io_write); if (account) { strmid(AccountInfo[playerid][aPassword], password, 0, strlen(password), 128); AccountInfo[playerid][aCash] = GetPlayerMoney(playerid); AccountInfo[playerid][aScore] = GetPlayerScore(playerid); GetPlayerPos(playerid, AccountInfo[playerid][aX], AccountInfo[playerid][aY], AccountInfo[playerid][aZ]); GetPlayerFacingAngle(playerid, AccountInfo[playerid][aA]); new file[128]; { format(file, sizeof file, "Password: %s\n", AccountInfo[playerid][aPassword]); { fwrite(account, file); } format(file, sizeof file, "Cash: %d\n",AccountInfo[playerid][aCash]); { fwrite(account, file); } format(file, sizeof file, "Score: %d\n", AccountInfo[playerid][aScore]); { fwrite(account, file); } format(file, sizeof file, "X: %f\n",AccountInfo[playerid][aX]); { fwrite(account, file); } format(file, sizeof file, "Y: %f\n",AccountInfo[playerid][aY]); { fwrite(account, file); } format(file, sizeof file, "Z: %f\n",AccountInfo[playerid][aZ]); { fwrite(account, file); } format(file, sizeof file, "Angle: %f\n",AccountInfo[playerid][aA]); { fwrite(account, file); } } fclose(account); SendClientMessage(playerid, 0x21DD00FF, "You have successfully registered an account. You may now /login."); } } return 1; } public LoginPlayer(playerid, password[]) { new name[MAX_PLAYER_NAME], str[128]; GetPlayerName(playerid, name, sizeof name); format(str, sizeof str, "%s.ini", name); new File:account = fopen(str, io_read); if (account) { new pass[256]; new passres[128], value[128]; fread(account, pass, sizeof pass); passres = GetFileString(pass); if (!strcmp("Password", passres)) { value = GetFileValue(pass); strmid(AccountInfo[playerid][aPassword], value, 0, strlen(value)-1, 128); // -1 to remove the extra space(\n) } if (!strcmp(AccountInfo[playerid][aPassword], password, true)) { while (fread(account, pass, 256)) { passres = GetFileString(pass); if (strfind(passres, "Cash") != -1) { value = GetFileValue(pass); AccountInfo[playerid][aCash] = strval(value); } if (strfind(passres, "Score") != -1) { value = GetFileValue(pass); AccountInfo[playerid][aScore] = strval(value); } if (strfind(passres, "X") != -1) { value = GetFileValue(pass); AccountInfo[playerid][aX] = floatstr(value); } if (strfind(passres, "Y") != -1) { value = GetFileValue(pass); AccountInfo[playerid][aY] = floatstr(value); } if (strfind(passres, "Z") != -1) { value = GetFileValue(pass); AccountInfo[playerid][aZ] = floatstr(value); } if (strfind(passres, "Angle") != -1) { value = GetFileValue(pass); AccountInfo[playerid][aA] = floatstr(value); } } fclose(account); AccountInfo[playerid][aLogged] = 1; } else { SendClientMessage(playerid, 0xE60000FF, "Incorrect Password."); fclose(account); return 1; } GivePlayerMoney(playerid, AccountInfo[playerid][aCash]); SetPlayerScore(playerid, AccountInfo[playerid][aScore]); SetPlayerPos(playerid, AccountInfo[playerid][aX], AccountInfo[playerid][aY], AccountInfo[playerid][aZ]); SetPlayerFacingAngle(playerid, AccountInfo[playerid][aA]); SendClientMessage(playerid, 0x21DD00FF, "Password correct! You have logged in successfully"); printf("%s has logged in", name); } return 1; } public SavePlayer(playerid) { if(IsPlayerConnected(playerid)) { if(AccountInfo[playerid][aLogged] == 1) // If he's logged in { new name[MAX_PLAYER_NAME], str[128]; GetPlayerName(playerid, name, sizeof name); format(str, sizeof str, "%s.ini", name); new File:account = fopen(str, io_write); if (account) { AccountInfo[playerid][aCash] = GetPlayerMoney(playerid); AccountInfo[playerid][aScore] = GetPlayerScore(playerid); GetPlayerPos(playerid, AccountInfo[playerid][aX], AccountInfo[playerid][aY], AccountInfo[playerid][aZ]); GetPlayerFacingAngle(playerid, AccountInfo[playerid][aA]); new file[128]; { format(file, sizeof file, "Password: %s\n", AccountInfo[playerid][aPassword]); { fwrite(account, file); } format(file, sizeof file, "Cash: %d\n",AccountInfo[playerid][aCash]); { fwrite(account, file); } format(file, sizeof file, "Score: %d\n", AccountInfo[playerid][aScore]); { fwrite(account, file); } format(file, sizeof file, "X: %f\n",AccountInfo[playerid][aX]); { fwrite(account, file); } format(file, sizeof file, "Y: %f\n",AccountInfo[playerid][aY]); { fwrite(account, file); } format(file, sizeof file, "Z: %f\n",AccountInfo[playerid][aZ]); { fwrite(account, file); } format(file, sizeof file, "Angle: %f\n",AccountInfo[playerid][aA]); { fwrite(account, file); } } fclose(account); } } } return 1; } stock GetFileString(string[]) { new result[128]; result[0] = 0; if (strfind(string, ":", true) == -1) return result; new id = strfind(string, ":", true); strmid(result, string, 0, id, 128); return result; } stock GetFileValue(string[]) { new val[128]; val[0] = 0; if (strfind(string , ":", true) == -1) return val; new id = strfind(string, ":", true); strmid(val, string, id+2, strlen(string), 128); return val; } stock Encrypt(string[]) // Made by ****** { for(new x=0; x < strlen(string); x++) { string[x] += (3^x) * (x % 15); if(string[x] > (0xff)) { string[x] -= 256; } } } stock strtok(const string[], &index,seperator=' ') { new length = strlen(string); new offset = index; new result[128]; while ((index < length) && (string[index] != seperator) && ((index - offset) < (sizeof(result) - 1))) { result[index - offset] = string[index]; index++; } result[index - offset] = EOS; if ((index < length) && (string[index] == seperator)) { index++; } return result; } public OnPlayerConnect(playerid) { AccountInfo[playerid][aCash] = 0; AccountInfo[playerid][aScore] = 0; AccountInfo[playerid][aX] = 0; AccountInfo[playerid][aY] = 0; AccountInfo[playerid][aZ] = 0; AccountInfo[playerid][aA] = 0; strmid(AccountInfo[playerid][aPassword], "-", 0, 1, 1); return 1; } public OnPlayerCommandText(playerid, cmdtext[]) { new cmd[128], tmp[128], idx; cmd = strtok(cmdtext, idx); if (!strcmp(cmd, "/login", true)) { new tmppass[128]; if(AccountInfo[playerid][aLogged] == 1) return SendClientMessage(playerid, 0xE60000FF, "You are already logged in."); tmp = strtok(cmdtext, idx); if(!strlen(tmp)) return SendClientMessage(playerid, 0xF97804FF, "USAGE: /login [password]"); new plname[MAX_PLAYER_NAME]; GetPlayerName(playerid, plname, sizeof plname); format(plname, sizeof plname, "%s.ini", plname); if(!fexist(plname)) return SendClientMessage(playerid, 0xE60000FF, "That account isn't registered! Please register: /register [password]"); strmid(tmppass, tmp, 0, strlen(cmdtext), 128); Encrypt(tmppass); LoginPlayer(playerid, tmppass); return 1; } if (!strcmp(cmd, "/register", true)) { if(AccountInfo[playerid][aLogged] == 1) return SendClientMessage(playerid, 0xE60000FF, "You are already logged in."); new plname[MAX_PLAYER_NAME]; GetPlayerName(playerid, plname, sizeof plname); format(plname, sizeof plname, "%s.ini", plname); new File: hFile = fopen(plname, io_read); if (hFile) { SendClientMessage(playerid, 0xE60000FF, "That name is already taken. Please re-connect using a different username."); fclose(hFile); return 1; } new tmppass[128]; tmp = strtok(cmdtext, idx); if(!strlen(tmp)) return SendClientMessage(playerid, 0xF97804FF, "USAGE: /register [password]"); strmid(tmppass, tmp, 0, strlen(cmdtext), 128); Encrypt(tmppass); RegisterPlayer(playerid, tmppass); return 1; } return 0; }

SOLVED