Code:
#include <a_samp>
#include <float>
#include <zcmd>
#include <sscanf2>
#include <streamer>
#include <YSI\y_ini>
native WP_Hash(buffer[],len,const str[]);
//------------------------------------------------------------------------------
#define COLOR_YELLOW 0xFFFF00AA
#define dregister 401
#define dlogin 402
#define Userpath "Accounts/%s.ini"
//------------------------------------------------------------------------------
enum pInfo
{
pPass[129],
pScore,
pCash,
pAdmin,
pVIP,
pKills,
pDeaths,
pWantedLvl,
pMoneybag,
pReactionTest,
pMathTest,
pWarnings,
pKicks,
pBans,
pBanned
}
new PlayerInfo[MAX_PLAYERS][pInfo];
//------------------------------------------------------------------------------
public OnPlayerConnect(playerid)
{
SendClientMessage(playerid,COLOR_YELLOW,"New here? Use /REGISTER to create a new account.");
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
if(fexist(Path(playerid)))
{
INI_ParseFile(Path(playerid),"loadaccount_%s", .bExtra = true, .extra = playerid);
ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","This account is registered. \nWrite your password please.","Login","Quit");
}
return 1;
}
//------------------------------------------------------------------------------
public OnPlayerDisconnect(playerid,reason)
{
if(fexist(Path(playerid)))
{
new INI:File = INI_Open(Path(playerid));
INI_SetTag(File,"Player's Data");
INI_WriteInt(File,"Score",GetPlayerScore(playerid));
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
INI_WriteInt(File,"VIP",PlayerInfo[playerid][pVIP]);
INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
INI_WriteInt(File,"Wanted Level",GetPlayerWantedLevel(playerid));
INI_WriteInt(File,"Moneybags",PlayerInfo[playerid][pMoneybag]);
INI_WriteInt(File,"Reaction Tests",PlayerInfo[playerid][pReactionTest]);
INI_WriteInt(File,"Math Tests",PlayerInfo[playerid][pMathTest]);
INI_WriteInt(File,"Total Warnings",PlayerInfo[playerid][pWarnings]);
INI_WriteInt(File,"Total Kicks",PlayerInfo[playerid][pKicks]);
INI_WriteInt(File,"Total Bans",PlayerInfo[playerid][pBans]);
INI_WriteInt(File,"Total Bans",PlayerInfo[playerid][pBanned]);
INI_Close(File);
}
return 1;
}
//------------------------------------------------------------------------------
forward loadaccount_user(playerid, name[], value[]);
public loadaccount_user(playerid, name[], value[])
{
INI_String("Password",PlayerInfo[playerid][pPass],129);
INI_Int("Score",PlayerInfo[playerid][pPass]);
INI_Int("Cash",PlayerInfo[playerid][pCash]);
INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
INI_Int("VIP",PlayerInfo[playerid][pVIP]);
INI_Int("Kills",PlayerInfo[playerid][pKills]);
INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
INI_Int("Wanted Level",PlayerInfo[playerid][pWantedLvl]);
INI_Int("Moneybags",PlayerInfo[playerid][pMoneybag]);
INI_Int("Reaction Tests",PlayerInfo[playerid][pReactionTest]);
INI_Int("Math Tests",PlayerInfo[playerid][pMathTest]);
INI_Int("Total Warnings",PlayerInfo[playerid][pWarnings]);
INI_Int("Total Kicks",PlayerInfo[playerid][pKicks]);
INI_Int("Total Bans",PlayerInfo[playerid][pBans]);
INI_Int("Banned",PlayerInfo[playerid][pBanned]);
return 1;
}
//------------------------------------------------------------------------------
CMD:register(playerid,params[])
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
if(fexist(Path(playerid)))
{
SendClientMessage(playerid,COLOR_YELLOW,"INFO: This account does already excist.");
}
else
{
ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Register","Enter your password below to create a new account.","Register","Quit");
return 1;
}
return 1;
}
//------------------------------------------------------------------------------
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == dregister)
{
if(!response) return Kick(playerid);
if(response)
{
if(!strlen(inputtext))
{
ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Register","Enter your password below to create a new account.","Register","Quit");
return 1;
}
new hashpass[129];
WP_Hash(hashpass,sizeof(hashpass),inputtext);
new INI:File = INI_Open(Path(playerid));
INI_SetTag(File,"Player's Data");
INI_WriteString(File,"Password",hashpass);
INI_WriteInt(File,"Cash",0);
INI_WriteInt(File,"Admin",0);
INI_WriteInt(File,"VIP",0);
INI_WriteInt(File,"Kills",0);
INI_WriteInt(File,"Deaths",0);
INI_WriteInt(File,"Wanted Level",0);
INI_WriteInt(File,"Moneybags",0);
INI_WriteInt(File,"Reaction Tests",0);
INI_WriteInt(File,"Math Tests",0);
INI_WriteInt(File,"Total Warnings",0);
INI_WriteInt(File,"Total Kicks",0);
INI_WriteInt(File,"Total Bans",0);
INI_WriteInt(File,"Banned",0);
INI_Close(File);
SendClientMessage(playerid,COLOR_YELLOW,"INFO: You have been successfully registered.");
GivePlayerMoney(playerid,50000);
return 1;
}
}
if(dialogid == dlogin)
{
if(!response) return Kick(playerid);
if(response)
{
new hashpass[129];
WP_Hash(hashpass,sizeof(hashpass),inputtext);
if(!strcmp(hashpass, PlayerInfo[playerid][pPass], false))
{
INI_ParseFile(Path(playerid),"loadaccount_%s",.bExtra = true, .extra = playerid);
SetPlayerScore(playerid,PlayerInfo[playerid][pScore]);
GivePlayerMoney(playerid,PlayerInfo[playerid][pCash]);
SendClientMessage(playerid,COLOR_YELLOW,"INFO: You have successfully logged in.");
}
else
{
ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","This account is registered. \nWrite your password please.","Login","Quit");
return 1;
}
}
}
return 0;
}
//------------------------------------------------------------------------------
stock Path(playerid)
{
new str[128],name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
format(str,sizeof(str),Userpath,name);
return str;
}
the account is registered when i do /register but when i set my admin lvl to any level its not saved , only the money is saved
Code:
CMD:makeadmin(playerid,params[])
{
if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid,0xFF0000FF,"<!>You are not authorized to use this command!");
new pID,rank,string1[128],string2[128],string3[128];
if(sscanf(params,"ui",pID,rank))return SendClientMessage(playerid,COL_GREEN,"/makeadmin [id] [level]");
if(rank<0||rank>8)return SendClientMessage(playerid,COL_GREEN,"Please write an acceptable level.");
SetPVarInt(pID,"Admin",rank);
format(string1,sizeof(string1),"You promoted %s to level %i",PlayerName(pID),rank);
format(string2,sizeof(string2),"* You are promoted to level %i. Try /admincommands [%i] to see the commands you can use now.",rank,rank);
for(new i=0;i<GetMaxPlayers();i++)
{
if(IsPlayerConnected(i))
{
if(IsPlayerAnAdmin(i,1))
{
format(string3,sizeof(string3),"A: %s [LEVEL: %i] used the MAKEADMIN command.",PlayerName(playerid),GetPVarInt(playerid,"Admin"));
SendClientMessage(i,COLOR_ORANGE,string3);
}
}
}
SendClientMessage(playerid,COLOR_LIGHTBLUE,string1);
SendClientMessage(pID,COLOR_ORANGE,string2);
return 1;
}
Code:
CMD:makeadmin(playerid,params[])
{
if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid,0xFF0000FF,"<!>You are not authorized to use this command!");
new pID,rank,string1[128],string2[128],string3[128];
if(sscanf(params,"ui",pID,rank))return SendClientMessage(playerid,COL_GREEN,"/makeadmin [id] [level]");
if(rank<0||rank>8)return SendClientMessage(playerid,COL_GREEN,"Please write an acceptable level.");
PlayerInfo[pID][pAdmin] = rank;
format(string1,sizeof(string1),"You promoted %s to level %i",PlayerName(pID),rank);
format(string2,sizeof(string2),"* You are promoted to level %i. Try /admincommands [%i] to see the commands you can use now.",rank,rank);
for(new i=0;i<GetMaxPlayers();i++)
{
if(IsPlayerConnected(i))
{
if(IsPlayerAnAdmin(i,1))
{
format(string3,sizeof(string3),"A: %s [LEVEL: %i] used the MAKEADMIN command.",PlayerName(playerid),GetPVarInt(playerid,"Admin"));
SendClientMessage(i,COLOR_ORANGE,string3);
}
}
}
SendClientMessage(playerid,COLOR_LIGHTBLUE,string1);
SendClientMessage(pID,COLOR_ORANGE,string2);
return 1;
}