Posted by ShadowMcFartPants on Sun 20 Sep 13:33 (modification of post by ShadowMcFartPants view diff)
report abuse | View followups from ShadowMcFart | download | new post
- /*
- ShadowMcFartPant's Account System!
- Credits:-
- YSF - Encrypt
- Spilot - Some Minor Warnings
- Creator of PEN:LS
- ShadowMcFartPant's - Scripting
- */
- #include <a_samp>
- #define FILTERSCRIPT
- #define COLOR_GREY 0xBEBEBEAA
- #define COLOR_WHITE 0xFFFFFFAA
- #define COLOR_GREEN 0x33AA33AA
- #define COLOR_GRAD5 0xE3E3E3FF
- #define COLOR_GRAD1 0xB4B5B7FF
- #define COLOR_YELLOW 0xFFFF00AA
- forward ShowStats(playerid,targetid);
- forward OnPlayerUpdate(playerid);
- forward Encrypt(string[]);
- forward OnPlayerLogin(playerid,const string[]);
- forward GetPlayerID(string[]);
- forward IsStringAName(string[]);
- enum pInfo
- {
- pPassword[128],
- pKills,
- pDeaths,
- pCash,
- pAdmin
- };
- new PlayerInfo[MAX_PLAYERS][pInfo];
- new gPlayerLogged[MAX_PLAYERS];
- new gPlayerAccount[MAX_PLAYERS];
- public OnFilterScriptInit()
- {
- print("ShadowMcFartPant's First Ever Account System");
- print("Fully Loaded and ready too goo.");
- return 1;
- }
- public OnFilterScriptExit()
- {
- print("ShadowMcFartPant's First ever Account System");
- print("Fully Un-Loaded and ready too not goo ? ");
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- PlayerInfo[playerid][pKills] = 0;
- PlayerInfo[playerid][pAdmin] = 0;
- PlayerInfo[playerid][pDeaths] = 0;
- new pName[MAX_PLAYER_NAME];
- new cnt[128];
- GetPlayerName(playerid,pName,sizeof(pName));
- format(cnt,sizeof(cnt),"%s.cer",pName);
- if(fexist(cnt))
- {
- gPlayerAccount[playerid] = 1;
- SendClientMessage(playerid, COLOR_YELLOW, "You have already registerd an account, please /login with your unique password");
- return 1;
- }
- else
- {
- gPlayerAccount[playerid] = 0;
- SendClientMessage(playerid, COLOR_YELLOW, "You have never played here before, please register an account with /register password");
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- OnPlayerUpdate(playerid);
- gPlayerLogged[playerid] = 0;
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- new Kills = PlayerInfo[playerid][pKills];
- SetPlayerScore(playerid, Kills);
- new Float:Health;
- GetPlayerHealth(playerid, Health);
- if(Health == 0.0)
- {
- PlayerInfo[playerid][pDeaths] += 1;
- }
- PlayerInfo[killerid][pKills] = PlayerInfo[killerid][pKills] + 1;
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- new giveplayer[MAX_PLAYER_NAME];
- new sendername[MAX_PLAYER_NAME];
- new string[256];
- //----------------------------------------------------------------------------
- new cmd[256];
- new idx;
- cmd = strtok(cmdtext, idx);
- new tmp[256];
- new pName[MAX_PLAYER_NAME];
- if (strcmp(cmd, "/login", true) == 0)
- {
- if(IsPlayerConnected(playerid))
- {
- new tmppass[64];
- if(gPlayerLogged[playerid] == 1)
- {
- SendClientMessage(playerid, COLOR_GREY, "You have already logged in.");
- return 1;
- }
- tmp = strtok(cmdtext, idx);
- if(!strlen(tmp))
- {
- SendClientMessage(playerid, COLOR_GREY, "ERROR: /login [password]");
- return 1;
- }
- strmid(tmppass, tmp, 0, strlen(cmdtext), 255);
- Encrypt(tmppass);
- OnPlayerLogin(playerid,tmppass);
- }
- return 1;
- }
- if (strcmp(cmd, "/register", true) == 0)
- {
- new string[256];
- tmp = strtok(cmdtext, idx);
- if(!strlen(tmp))
- {
- SendClientMessage(playerid, COLOR_GREY, "ERROR: /register [password]");
- return 1;
- }
- if (gPlayerAccount[playerid] == 1)
- {
- SendClientMessage(playerid, COLOR_GREY, "Sorry but that name has been previously registerd");
- return 1;
- }
- strmid(PlayerInfo[playerid][pPassword], tmp, 0, strlen(cmdtext), 255);
- Encrypt(PlayerInfo[playerid][pPassword]);
- GetPlayerName(playerid, pName, sizeof(pName));
- format(string, sizeof(string), "%s.cer", pName);
- new File: file = fopen(string, io_read);
- if (file)
- {
- SendClientMessage(playerid, COLOR_GREY, "Sorry but that name has been previously registerd");
- fclose(file);
- return 1;
- }
- new File:hFile;
- hFile = fopen(string, io_append);
- new var[32];// var
- format(var, 32, "%s\n", PlayerInfo[playerid][pPassword]);fwrite(hFile, var);
- format(var, 32, "Kills=%d\n",PlayerInfo[playerid][pKills]);fwrite(hFile, var);
- format(var, 32, "Deaths=%d\n",PlayerInfo[playerid][pDeaths]);fwrite(hFile, var);
- PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
- format(var, 32, "Money=%d\n",PlayerInfo[playerid][pCash]);fwrite(hFile, var);
- format(var, 32, "pAdmin=%d\n",PlayerInfo[playerid][pAdmin]);fwrite(hFile, var);
- fclose(hFile);
- SendClientMessage(playerid, COLOR_WHITE, "Succesfully Registered!");
- SendClientMessage(playerid, COLOR_WHITE, "Next time you connect, remember too /login [password]");
- OnPlayerLogin(playerid,PlayerInfo[playerid][pPassword]);
- return 1;
- }
- if (strcmp(cmd, "/mystats", true) == 0)
- {
- if(IsPlayerConnected(playerid))
- {
- if (gPlayerLogged[playerid] != 0)
- {
- ShowStats(playerid,playerid);
- }
- else
- {
- SendClientMessage(playerid, COLOR_GRAD1, "You are not logged in!");
- }
- }
- return 1;
- }
- if(strcmp(cmd, "/Promoteplayer", true) == 0)
- {
- tmp = strtok(cmdtext, idx);
- if(!strlen(tmp))
- {
- SendClientMessage(playerid, COLOR_WHITE, "ERROR: /promoteplayer [playerid] [level]");
- return 1;
- }
- new reg1;
- new level;
- if(IsStringAName(tmp))
- {
- reg1 = GetPlayerID(tmp);
- }
- else
- {
- reg1 = strval(tmp);
- }
- tmp = strtok(cmdtext, idx);
- level = strval(tmp);
- if ((IsPlayerAdmin(playerid)) || PlayerInfo[playerid][pAdmin] >= 5)
- {
- GetPlayerName(reg1, giveplayer, sizeof(giveplayer));
- GetPlayerName(playerid, sendername, sizeof(sendername));
- PlayerInfo[reg1][pAdmin] = level;
- format(string, sizeof(string), "You have been Promoted to level %d By %s", level, sendername);
- SendClientMessage(reg1, COLOR_WHITE, string);
- format(string, sizeof(string), "You have Promoted %s to level %d",giveplayer,level);
- SendClientMessage(playerid,COLOR_WHITE,string);
- }
- else
- {
- SendClientMessage(playerid, COLOR_WHITE, "You are not authorized to use that command.");
- }
- return 1;
- }
- return 0;
- }
- public OnPlayerLogin(playerid,const string[])
- {
- new pName1[MAX_PLAYER_NAME];
- new pName2[MAX_PLAYER_NAME];
- new String1[64];
- new String2[128];
- GetPlayerName(playerid, pName1, sizeof(pName1));
- format(String1, sizeof(String1), "%s.cer", pName1);
- new File: UserFile = fopen(String1, 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 , "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 , "Money" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pCash] = strval( val ); }
- if( strcmp( key , "pAdmin" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pAdmin] = strval( val ); }
- GivePlayerMoney(playerid,PlayerInfo[playerid][pCash]);
- }
- fclose(UserFile);
- gPlayerLogged[playerid] = 1;
- gPlayerAccount[playerid] = 1;
- new kills = PlayerInfo[playerid][pKills];
- SetPlayerScore(playerid, kills);
- GetPlayerName(playerid, pName2, sizeof(pName2));
- format(String2, sizeof(String2), "Welcome %s You have logged in successfully.",pName2);
- SendClientMessage(playerid, COLOR_WHITE,String2);
- }
- else
- {
- SendClientMessage(playerid, COLOR_GREY, "Incorrect Password, 2 Attempts Remaining.");
- fclose(UserFile);
- }
- }
- return 1;
- }
- 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, "Kills=%d\n",PlayerInfo[playerid][pKills]);fwrite(hFile, var);
- format(var, 32, "Deaths=%d\n",PlayerInfo[playerid][pDeaths]);fwrite(hFile, var);
- format(var, 32, "Money=%d\n",PlayerInfo[playerid][pCash]);fwrite(hFile, var);
- format(var, 32, "pAdmin=%d\n",PlayerInfo[playerid][pAdmin]);fwrite(hFile, var);
- fclose(hFile);
- }
- }
- }
- return 1;
- }
- public ShowStats(playerid,targetid)
- {
- if(IsPlayerConnected(playerid)&&IsPlayerConnected(targetid))
- {
- new Cash = GetPlayerMoney(targetid);
- new Deaths = PlayerInfo[targetid][pDeaths];
- new Kills = PlayerInfo[targetid][pKills];
- new pName[MAX_PLAYER_NAME];
- GetPlayerName(targetid, pName, sizeof(pName));
- new Float:pX,Float:pY,Float:pZ;
- GetPlayerPos(targetid, pX,pY,pZ);
- new CoordString[256];
- SendClientMessage(playerid, COLOR_GREEN,"----------------------------------------");
- format(CoordString, sizeof(CoordString),"** %s Stats **",pName);
- SendClientMessage(playerid, COLOR_WHITE,CoordString);
- format(CoordString, sizeof(CoordString),"Admin Level:[%d]",pAdmin);
- SendClientMessage(playerid, COLOR_GRAD5,CoordString);
- format(CoordString, sizeof(CoordString),"Kills:[%d] |-| Deaths:[%d] |-| Cash[£%d]",Kills,Deaths,Cash);
- SendClientMessage(playerid, COLOR_GRAD5,CoordString);
- SendClientMessage(playerid, COLOR_GREEN,"----------------------------------------");
- }
- }
- public Encrypt(string[])
- {
- for(new x=0; x < strlen(string); x++)
- {
- string[x] += (3^x) * (x % 15);
- if(string[x] > (0xff))
- {
- string[x] -= 64;
- }
- }
- 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;
- }
- strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
- public IsStringAName(string[])
- {
- for(new i = 0; i <= MAX_PLAYERS; i++)
- {
- if(IsPlayerConnected(i) == 1)
- {
- new testname[MAX_PLAYER_NAME];
- GetPlayerName(i, testname, sizeof(testname));
- //printf("IsS:testname = %s : string = %s",testname,string);
- if(strcmp(testname, string, true, strlen(string)) == 0)
- {
- //printf("TRUE IsS:testname = %s : string = %s",testname,string);
- return 1;
- }
- }
- }
- return 0;
- }
- public GetPlayerID(string[])
- {
- for(new i = 0; i <= MAX_PLAYERS; i++)
- {
- if(IsPlayerConnected(i) == 1)
- {
- new testname[MAX_PLAYER_NAME];
- GetPlayerName(i, testname, sizeof(testname));
- //printf("GetP:testname = %s : string = %s",testname,string);
- if(strcmp(testname, string, true, strlen(string)) == 0)
- {
- //printf("TRUE GetP:testname = %s : string = %s playerid %d",testname,string, i);
- return i;
- }
- }
- }
- return INVALID_PLAYER_ID;
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.