22.06.2013, 19:36
Hello, I just started on my new script, and I just added a Register system/Login System, and a rank system. In the tutorial it tells you to put something in your script that will make any player that logs onto the server, a Private. It also states that you can some how save their ranks... Bellow is the quoted words in the tutorial I'm talking about.
How do I save my ranks using a Login/Register system?
Here's my script:
Quote:
pawn Code: pRank[playerid] = RANK_NEWBIE; |
Quote:
That means, each time the player connects, it will reset his rank back to newbie. (unless you use a register/login system to save and load his rank) |
Here's my script:
pawn Код:
//-----------------------------------------------------------------------------------------------------//
//---[Script Information]---//
// Script Start: 6/20/2013
// Script Owner: DJTunes (SA-MP Forum Name)
// Script Mode: Team Death Match
//---[Credits]---//
// Scripter(s): DJTunes
// Mapper(s):
// Tester(s):
// Helper(s):
//-----------------------------------------------------------------------------------------------------//
//---[Includes]---//
#include <a_samp>
#include <YSI\y_ini>
//---[Defines]---//
#define RANK_PVT 0
#define RANK_PFC 1
#define RANK_SPC 2
#define RANK_CPL 3
#define RANK_SGT 4
#define RANK_SSG 5
#define RANK_SFC 6
#define RANK_MSG 7
#define RANK_1SG 8
#define RANK_SGM 9
#define RANK_CSM 10
#define RANK_SMA 11
#define RANK_2LT 12
#define RANK_1LT 13
#define RANK_CPT 14
#define RANK_MAJ 15
#define RANK_LTC 16
#define RANK_COL 17
#define RANK_BG 18
#define RANK_MG 19
#define RANK_LTG 20
#define RANK_GEN 21
#define RANK_GA 22
#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
#define DIALOG_SUCCESS_1 3
#define DIALOG_SUCCESS_2 4
#define PATH "/Users/%s.ini"
#define COL_WHITE "{FFFFFF}"
#define COL_RED "{F81414}"
#define COL_GREEN "{00FF22}"
#define COL_LIGHTBLUE "{00CED1}"
//---[Enum]---//
//---[Login/Register System]---//
enum pInfo
{
pPass,
pCash,
pAdmin,
pKills,
pDeaths,
pXp
}
//---[Login/Register System]---//
new PlayerInfo[MAX_PLAYERS][pInfo];
//---[Login/Register System Functions]---//
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
INI_Int("Password",PlayerInfo[playerid][pPass]);
INI_Int("Cash",PlayerInfo[playerid][pCash]);
INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
INI_Int("Kills",PlayerInfo[playerid][pKills]);
INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
INI_Int("Experience",PlayerInfo[playerid][pXp]);
return 1;
}
//---[Variables]---//
new pRank[MAX_PLAYERS];
//---[Gamemode]---//
public OnPlayerConnect(playerid)
{
//---[Login/Register System]---//
if(fexist(UserPath(playerid)))
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_WHITE"Type your password below to login.","Login","Quit");
}
else
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""COL_WHITE"Registering...",""COL_WHITE"Type your password below to register a new account.","Register","Quit");
}
//---[Rank System]---//
pRank[playerid] = RANK_PVT;
return 1;
}
//---[Rank System Forward]---//
forward CheckPlayerRank(playerid);
public CheckPlayerRank(playerid)
{
new iScore = GetPlayerScore(playerid);
switch(iScore)
{
case 0..100:
{
pRank[playerid] = RANK_PVT;
// Info
}
case 101..200:
{
pRank[playerid] = RANK_PFC;
//Rest of the information here.
}
case 201..300:
{
pRank[playerid] = RANK_SPC;
//Rest of the information here.
}
case 301..400:
{
pRank[playerid] = RANK_CPL;
//Rest of the information here.
}
case 401..500:
{
pRank[playerid] = RANK_SGT;
//Info Here
}
case 501..600:
{
pRank[playerid] = RANK_SSG;
//Info Here
}
case 601..700:
{
pRank[playerid] = RANK_SFC;
//Info Here
}
case 701..800:
{
pRank[playerid] = RANK_MSG;
//Info Here
}
case 801..900:
{
pRank[playerid] = RANK_1SG;
//Info Here
}
case 901..1000:
{
pRank[playerid] = RANK_SGM;
//Info Here
}
case 1001..1100:
{
pRank[playerid] = RANK_CSM;
//Info Here
}
case 1101..1200:
{
pRank[playerid] = RANK_SMA;
//Info Here
}
case 1201..1300:
{
pRank[playerid] = RANK_2LT;
//Info Here
}
case 1301..1400:
{
pRank[playerid] = RANK_1LT;
//Info Here
}
case 1401..1500:
{
pRank[playerid] = RANK_CPT;
//Info Here
}
case 1501..1600:
{
pRank[playerid] = RANK_MAJ;
//Info Here
}
case 1601..1700:
{
pRank[playerid] = RANK_LTC;
//Info Here
}
case 1701..1800:
{
pRank[playerid] = RANK_COL;
//Info Here
}
case 1801..1900:
{
pRank[playerid] = RANK_BG;
//Info Here
}
case 1901..2000:
{
pRank[playerid] = RANK_MG;
//Info Here
}
case 2001..2100:
{
pRank[playerid] = RANK_LTG;
//Info Here
}
case 4000..10000:
{
pRank[playerid] = RANK_GEN;
//Info Here
}
default:
{
pRank[playerid] = RANK_GA;
//Info Here
}
}
return 1;
}
//---[Score System]---//
public OnPlayerDeath(playerid, killerid, reason)
{
SetPlayerScore(playerid, GetPlayerScore(playerid)-1);
CheckPlayerRank(playerid);
if(IsPlayerConnected(killerid))
{
SetPlayerScore(killerid, GetPlayerScore(killerid)+1);
CheckPlayerRank(killerid);
}
PlayerInfo[killerid][pXp]+= 1;
GivePlayerMoney(killerid, 100);
GivePlayerMoney(playerid, -50);
return 1;
}
//---[Register/Login System]---//
public OnPlayerDisconnect(playerid, reason)
{
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
INI_WriteInt(File,"Experience",PlayerInfo[playerid][pXp]);
INI_Close(File);
return 1;
}
//---[Login/Register System]---//
stock UserPath(playerid)
{
new string[128],playername[MAX_PLAYER_NAME];
GetPlayerName(playerid,playername,sizeof(playername));
format(string,sizeof(string),PATH,playername);
return string;
}
/*Credits to Dracoblue*/
stock udb_hash(buf[]) {
new length=strlen(buf);
new s1 = 1;
new s2 = 0;
new n;
for (n=0; n<length; n++)
{
s1 = (s1 + buf[n]) % 65521;
s2 = (s2 + s1) % 65521;
}
return (s2 << 16) + s1;
}
//---[Login/Register System]---//
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch( dialogid )
{
case DIALOG_REGISTER:
{
if (!response) return Kick(playerid);
if(response)
{
if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Password",udb_hash(inputtext));
INI_WriteInt(File,"Cash",0);
INI_WriteInt(File,"Admin",0);
INI_WriteInt(File,"Kills",0);
INI_WriteInt(File,"Deaths",0);
INI_WriteInt(File,"Experience",0);
INI_Close(File);
SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"To save your stats, please relog.","Ok","");
}
}
case DIALOG_LOGIN:
{
if ( !response ) return Kick ( playerid );
if( response )
{
if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
}
else
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Quit");
}
return 1;
}
}
}
return 1;
}