Lots of bugs with Register/Login... - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Lots of bugs with Register/Login... (
/showthread.php?tid=401885)
Lots of bugs with Register/Login... -
jNkk - 24.12.2012
Hey... I tried to make this register/login system from a tutorial, did exact same things but it won't work.
Here are both commands.
Код:
//====[INCLUDES]====//
#include <a_samp>
#include <sscanf2>
#include <zcmd>
#include <strtok>
#include <sii>
//===[ACCOUNTS]===//
enum PlayerInfo
{
Logged,
Level,
}
//=====[NEW]=====//
new PInfo[MAX_PLAYERS][PlayerInfo];
Код:
public OnPlayerConnect(playerid)
{
new file[64],
PlayerName[25];
GetPlayerName(playerid,PlayerName,sizeof PlayerName);
format(file,sizeof file,"Admin/%s.ini",PlayerName);
if(!fexist(file))
{
SendClientMessage(playerid, COLOR_ERROR, "[ERROR] You aren't registered! Use /register <password>!");
}
else
{
SendClientMessage(playerid, COLOR_ERROR, "[ERROR] You are registered! Use /login <password>!");
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
PInfo[playerid][Logged] = 0;
return 1;
}
Код:
CMD:register(playerid, params[])
{
if(PInfo[playerid][Logged] == 1) return SendClientMessage(playerid, COLOR_ERROR, "[ERROR] You are already logged in!");
new password[23];
if(sscanf(params,"s[23]",password)) return SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /register <password>");
new file[64],
PlayerName[24];
GetPlayerName(playerid,PlayerName,sizeof PlayerName);
format(file,sizeof file,"Admin/%s.ini",PlayerName);
if(fexist(file)) return SendClientMessage(playerid, COLOR_ERROR, "[ERROR] Somehow you're already registered!");
INI_Open(file);
INI_WriteString("Password",password);
INI_WriteInt("Level",PInfo[playerid][Level]);
INI_Save();
INI_Close();
SendClientMessage(playerid, COLOR_ACHIEVEMENT, "[REGISTER] You have successfully registered!");
PInfo[playerid][Logged] = 1;
return 1;
}
CMD:login(playerid, params[])
{
if(PInfo[playerid][Logged] == 1) return SendClientMessage(playerid, COLOR_ERROR, "[ERROR] You are already logged in!");
new password[23],
password2[23];
if(sscanf(params,"s[23]",password)) return SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /login <password>");
new file[64],
PlayerName[24];
GetPlayerName(playerid,PlayerName,sizeof PlayerName);
format(file,sizeof file,"Admin/%s.ini",PlayerName);
if(!fexist(file)) return SendClientMessage(playerid, 0xFFFFFFFF, "[ERROR] You aren't registered! Use /register!");
INI_Open(file);
INI_ReadString(password2,"Password");
if(strcmp(password,password2) != 0) return SendClientMessage(playerid, COLOR_ERROR,"[ERROR] Wrong password! Try again!"),
INI_Close();
PInfo[playerid][Level] = INI_ReadInt("Level");
INI_Close();
SendClientMessage(playerid, COLOR_ACHIEVEMENT, "[LOGIN] You have succefully logged in!");
PInfo[playerid][Logged] = 1;
return 1;
}
The problem is that I get errors like "USAGE:" when I actually type the correct thing, or when I somehow manage to register it tells me that I am not, or if I try to login it will tell me that I am already logged in.. many other things I guess... I didn't know how to fix these so I would really need some help on them, if you can please help me.
Thank you very much!