PHP Code:
#include DOF2
//===================
#define DIALOG_REGISTER 0
#define DIALOG_LOGIN 1
main(){}
enum pInfo
{
pAdmin,
pSkin,
pScore,
pMoney,
Float:pPosX,
Float:pPosY,
Float:pPosZ,
Float:pPosA,
pInterior,
pVW,
bool:pLogado
}
new
Player[MAX_PLAYERS][pInfo],reset[pInfo],
Conta[256]
;
//========================================
public OnPlayerRequestClass(playerid, classid)
{
IsPlayerLogged(playerid);
return false;
}
//========================================
public OnPlayerRequestSpawn(playerid) return IsPlayerLogged(playerid);
IsPlayerLogged(playerid)
{
if(Player[playerid][pLogado] == true)
{
SetSpawnInfo(playerid,-1,Player[playerid][pSkin],Player[playerid][pPosX],Player[playerid][pPosY],Player[playerid][pPosZ],Player[playerid][pPosA],0,0,0,0,0,0);
SpawnPlayer(playerid);
SetPlayerInterior(playerid, 0);
SetCameraBehindPlayer(playerid);
}
return 1;
}
//========================================
public OnPlayerConnect(playerid)
{
Player[playerid][pLogado]=false;
//=================================[ LOGIN/REGISTRO ]===============================||
format(Conta, sizeof(Conta), "Contas/%s.ini", Name(playerid));
if(!DOF2_FileExists(Conta))
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", "Escreva uma senha, para se registrar!", "Registrar", "Sair");
}
else
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "LOGIN", "Bem vindo ! \nEscreva uma senha abaixo para entrar em sua conta.", "Entrar", "Sair");
}
//==================================================================================||
return 1;
}
//========================================
public OnPlayerDisconnect(playerid, reason)
{
SalvarConta(playerid);
Player[playerid] = reset;
return 1;
}
//========================================
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
//=================================[ DIALOG_REGISTER ]==============================||
if(dialogid == DIALOG_REGISTER)
{
if(!response) return Kick(playerid);
if(strlen(inputtext) < 4) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", "Escreva uma senha, para se registrar!", "registrar", "sair");
if(response)
{
if(strlen(inputtext))
{
format(Conta, sizeof(Conta), "Contas/%s.ini", Name(playerid));
DOF2_CreateFile(Conta);
DOF2_SetString(Conta, "Password", inputtext);
DOF2_SaveFile();
CriarConta(playerid);
CarregarConta(playerid);
}
else ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", "Escreva uma senha, para se registrar!", "registrar", "Sair");
}
return 1;
}
//=================================[ DIALOGO LOGIN ]==============================||
if(dialogid == DIALOG_LOGIN)
{
if(!response) return Kick(playerid);
if(response)
{
if(!strlen(inputtext))
{
return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "LOGIN", "Bem vindo ! \nEscreva uma senha abaixo para entrar em sua conta.","entrar", "sair");
}
format(Conta, sizeof(Conta), "Contas/%s.ini", Name(playerid));
if(strcmp(inputtext, DOF2_GetString(Conta, "Password"), true))
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "LOGIN", "Bem vindo ! \nEscreva uma senha abaixo para entrar em sua conta.","entrar", "sair");
SendClientMessage(playerid, -1, "[ SERVER ] a senha estб errada!");
}
else //se acertar a senha
{
CarregarConta(playerid);
}
}
return 1;
}
return 1;
}
//========================================
public OnPlayerSpawn(playerid)
{
SetPlayerSkin(playerid, Player[playerid][pSkin]);
DarMoney(playerid,Player[playerid][pMoney]);
TogglePlayerControllable(playerid,true);
return 1;
}
//=====================================================================================||
CriarConta(playerid)
{
format(Conta, sizeof(Conta), "Contas/%s.ini", Name(playerid));
DOF2_SetInt(Conta, "Admin", 0);
DOF2_SetInt(Conta, "Skin", 98);
DOF2_SetInt(Conta, "Money", 500);
DOF2_SetInt(Conta, "Score", 0);
DOF2_SetFloat(Conta, "PosX", 2069.8767);
DOF2_SetFloat(Conta, "PosY", -1766.6870);
DOF2_SetFloat(Conta, "PosZ", 13.5621);
DOF2_SetFloat(Conta, "PosA", 90.0);
DOF2_SetInt(Conta, "Interior", 0);
DOF2_SetInt(Conta, "VW", 0);
DOF2_SaveFile();
}
CarregarConta(playerid)
{
format(Conta, sizeof(Conta), "Contas/%s.ini", Name(playerid));
Player[playerid][pAdmin] = DOF2_GetInt(Conta, "Admin");
Player[playerid][pSkin] = DOF2_GetInt(Conta, "Skin");
Player[playerid][pMoney] = DOF2_GetInt(Conta, "Money");
Player[playerid][pScore] = DOF2_GetInt(Conta, "Score");
Player[playerid][pPosX] = DOF2_GetInt(Conta, "PosX");
Player[playerid][pPosY] = DOF2_GetInt(Conta, "PosY");
Player[playerid][pPosZ] = DOF2_GetInt(Conta, "PosZ");
Player[playerid][pPosA] = DOF2_GetInt(Conta, "PosA");
Player[playerid][pInterior] = DOF2_GetInt(Conta, "Interior");
Player[playerid][pVW] = DOF2_GetInt(Conta, "VW");
Player[playerid][pLogado]=true;
SetPlayerScore(playerid, Player[playerid][pScore]);
DarMoney(playerid, Player[playerid][pMoney]);
SetPlayerInterior(playerid, Player[playerid][pInterior]);
SetPlayerVirtualWorld(playerid, Player[playerid][pVW]);
SetSpawnInfo(playerid, -1, Player[playerid][pSkin], Player[playerid][pPosX], Player[playerid][pPosY], Player[playerid][pPosZ], Player[playerid][pPosA],0,0,0,0,0,0);
SpawnPlayer(playerid);
}
SalvarConta(playerid)
{
format(Conta, sizeof(Conta), "Contas/%s.ini", Name(playerid));
GetPlayerPos(playerid, Player[playerid][pPosX], Player[playerid][pPosY], Player[playerid][pPosZ]);
GetPlayerFacingAngle(playerid,Player[playerid][pPosA]);
DOF2_SetInt(Conta, "Admin", Player[playerid][pAdmin]);
DOF2_SetInt(Conta, "Skin", Player[playerid][pSkin]);
DOF2_SetInt(Conta, "Money", Player[playerid][pMoney]);
DOF2_SetInt(Conta, "Score", Player[playerid][pScore]);
DOF2_SetFloat(Conta, "PosX", Player[playerid][pPosX]);
DOF2_SetFloat(Conta, "PosY", Player[playerid][pPosY]);
DOF2_SetFloat(Conta, "PosZ", Player[playerid][pPosZ]);
DOF2_SetFloat(Conta, "PosA", Player[playerid][pPosA]);
DOF2_SetInt(Conta, "Interior", GetPlayerInterior(playerid));
DOF2_SetInt(Conta, "VW", GetPlayerVirtualWorld(playerid));
DOF2_SaveFile();
}
Name(playerid)
{
new pNome[MAX_PLAYER_NAME];
GetPlayerName(playerid, pNome, 24);
return pNome;
}