[FS] Login e registro com Salvamento
Autor: Samu | Publicado: 2012-05-07T16:08:00-07:00

NFORMAÇÕES:
Salvamento em DOF2
Salva:
Nome,
Dinheiro (que pode ser editado na pasta scriptfiles),
Matou(Aqui e quantos o player matou, sem ser editado na scriptfiles),
Morreu (Aqui e quantas vezes o player morreu, sem ser editado na scriptfiles),
Score (Score que pode ser editado na pasta scriptfiles).

#include
#include

//----
new Nome[24];
//----
new Logado[MAX_PLAYERS];
new Registrado[MAX_PLAYERS];
//----
new Matou[MAX_PLAYERS];
new Morreu[MAX_PLAYERS];
//----
#define dregister 100
#define dlogin 101

main()
{
print("\n----------------------------------");
print(" [SS] Salvamento de Dados");
print("----------------------------------\n");
}

public OnGameModeInit()
{
AddPlayerClass(230, 1958.3783, 1343.1572, 15.3746, 269.1425, 26, 8888, 32, 8888, 31, 8888);
return 1;
}

public OnGameModeExit()
{
return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
return 1;
}

public OnPlayerConnect(playerid)
{
Logado[playerid] = 0;
Registrado[playerid] = 0;
carregar(playerid);
new log[32];
new regstring[256];
format(log,sizeof log,"Contas/%s.ini",Nome(playerid));
if(!fexist(log))
{
format(regstring,sizeof(regstring),"{FFFFFF}Bem vindo ao server!!\nNick: {FF0000}%s\n{FFFFFF}Estado: {FF0000}Não registrado\n{FFFFFF}Digite uma senha para registrar",Nome(playerid));
ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Registrando-se",regstring,"Registrar","Sair");
}
else
{
format(regstring,sizeof(regstring),"{FFFFFF}Bem vindo ao server!!\nNick: {99FF00}%s\n{FFFFFF}Estado: {99FF00}Registrado\n{FFFFFF}Digite sua senha para entrar",Nome(playerid));
ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Logar-se",regstring,"Logar","Sair");
}
return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
Logado[playerid] = 0;
salvar(playerid);
DOF2_Exit();
return 1;
}

public OnPlayerSpawn(playerid)
{

if(Registrado[playerid] == 1)
{
return 1;
} else return 0;
}

public OnPlayerDeath(playerid, killerid, reason)
{
Matou[killerid] += 1;
Morreu[playerid] += 1;
return 1;
}

public OnVehicleSpawn(vehicleid)
{
return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
return 1;
}

public OnPlayerText(playerid, text[])
{
return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
return 1;
}

public OnRconCommand(cmd[])
{
return 1;
}

public OnPlayerRequestSpawn(playerid)
{
return 1;
}

public OnObjectMoved(objectid)
{
return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
return 1;
}

public OnPlayerExitedMenu(playerid)
{
return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
return 1;
}

public OnPlayerUpdate(playerid)
{
return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == dregister)
{
new str[200],arq[50];
format(arq,sizeof arq,"Contas/%s.ini",Nome(playerid));
if(!response) Kick(playerid);
DOF2_CreateFile(arq);
if(!strlen(inputtext)) return ShowPlayerDialog (playerid, dregister,DIALOG_STYLE_INPUT, "Registrando-se", "{FF0000}[ERRO]: {FFFFFF}É preciso digitar uma senha para se registrar-se!","Registrar","Sair");
SendClientMessage(playerid,Verde,"[INFO]: Registrado com Sucesso!");
DOF2_SetString(arq,"Senha",inputtext);
DOF2_SetInt(arq,"Registrado",1);
DOF2_SaveFile();
format(str,sizeof(str),"Você Foi Registrador, Agora Logue-se:");
ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Logar",str,"Logar","Sair");
return 1;
}

if(dialogid == dlogin)
{
new arq[50];
format(arq,sizeof arq,"Contas/%s.ini",Nome(playerid));
if(!response) Kick(playerid);
if(!strlen(inputtext)) return ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Logar","{FF0000}Senha incorreta!.","Logar","Sair");
if(strcmp(inputtext,DOF2_GetString(arq,"Senha"),false) == 0)
{
SendClientMessage(playerid,Verde,"[INFO]: Logado com Sucesso!");
Logado[playerid] = 1;
Registrado[playerid] = DOF2_GetInt(arq,"Registrado");
if(Registrado[playerid] == 1)
{
carregar(playerid);
OnPlayerSpawn(playerid);
}
else
{
ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Logando-se","{FF0000}[ERRO]: {FFFFFF}É preciso digitar uma senha para logar-se!","Logar","Sair");
}
}
else
{
ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Logar","{FF0000}Senha incorreta!","Logar","Sair");
}
return 1;
}

return 1;
}

salvar(playerid)
{
new arq[50];
format(arq,sizeof arq,"Contas/%s.ini",Nome(playerid));
DOF2_SetInt(arq,"Score",GetPlayerScore(playerid));
DOF2_SetInt(arq,"Dinheiro",GetPlayerMoney(playerid));
DOF2_SetInt(arq,"Matou",Matou[playerid]);
DOF2_SetInt(arq,"Morreu",Morreu[playerid]);
DOF2_SetInt(arq,"Skin",GetPlayerSkin(playerid));
DOF2_SaveFile();
Matou[playerid] = 0;
Morreu[playerid] = 0;
ResetPlayerMoney(playerid);

}

carregar(playerid)
{
new arq[50];
format(arq,sizeof arq,"Contas/%s.ini",Nome(playerid));
if(fexist(arq))
{
ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, DOF2_GetInt(arq,"Dinheiro"));
SetPlayerScore(playerid, DOF2_GetInt(arq,"Score"));
SetPlayerSkin(playerid, DOF2_GetInt(arq,"Skin"));
Matou[playerid] = DOF2_GetInt(arq,"Matou");
Morreu[playerid] = DOF2_GetInt(arq,"Morreu");
printf("%i",DOF2_GetInt(arq,"Dinheiro")),printf("%i",DOF2_GetInt(arq,"Score")),printf("%i",DOF2_GetInt(arq,"Skin"));
} else print("arquivo nao existe"),print(arq);
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}