Vocкs poderiam me ajuda em um problema? -
vitinhosamp - 20.07.2018
Meu sistema de salvamento esta errado, de alguma maneira, quando o player spawna ele fica sem vida as vezes ou quando nao, o dinheiro nao e setado na mao dele, alguem me ajuda?
PHP код:
public OnPlayerDisconnect(playerid, reason)
{
new string[64], Float:health, Float:armour;
format(string, sizeof(string), "O player %s se conectou ao servidor!", Pname(playerid));
SendClientMessageToAll(-1, string);
format(gfile, sizeof(gfile), "Contas/%s.txt", Pname(playerid));
if(DOF2_FileExists(gfile))
{
DOF2_SetInt(gfile, "Dinheiro", GetPlayerMoney(playerid));
DOF2_SetFloat(gfile, "Vida", GetPlayerHealth(playerid, health));
DOF2_SetFloat(gfile, "Colete", GetPlayerArmour(playerid, armour));
DOF2_SetInt(gfile, "Level", GetPlayerScore(playerid));
DOF2_SetInt(gfile, "Ajudante", aInfo[playerid][Ajudante]);
DOF2_SetInt(gfile, "Moderador", aInfo[playerid][Moderador]);
DOF2_SetInt(gfile, "Corregedor", aInfo[playerid][Corregedor]);
DOF2_SetInt(gfile, "Administrador", aInfo[playerid][Administrador]);
DOF2_SetInt(gfile, "Master", aInfo[playerid][Master]);
DOF2_SaveFile();
}
return 1;
}
PHP код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
format(gfile, sizeof(gfile), "Contas/%s.txt", Pname(playerid));
switch(dialogid) {
case Registro: {
if(!strlen(inputtext))
{
SendClientMessage(playerid, -1, "[ {FFFFFF}ERRO ]Digite uma senha para se registrar!");
format(str, sizeof(str), "Ola, seja bem vindo pela primeira vez Sr.%s !", Pname(playerid));
ShowPlayerDialog(playerid, Registro, DIALOG_STYLE_PASSWORD, "{FFFFFF}REGISTRO", str, "Registro", "Cancelar");
}
else
{
DOF2_CreateFile(gfile);
DOF2_SetString(gfile, "Senha", inputtext);
DOF2_SetInt(gfile, "Dinheiro", 1000);
DOF2_SetFloat(gfile, "Vida", 100);
DOF2_SetFloat(gfile, "Colete", 0);
DOF2_SetInt(gfile, "Level", 0);
DOF2_SetInt(gfile, "Ajudante", 0);
DOF2_SetInt(gfile, "Moderador", 0);
DOF2_SetInt(gfile, "Corregedor", 0);
DOF2_SetInt(gfile, "Administrador", 0);
DOF2_SetInt(gfile, "Master", 0);
DOF2_SaveFile();
format(str, sizeof(str), "Ola, seja bem vindo ao servidor novamente!");
ShowPlayerDialog(playerid, Login, DIALOG_STYLE_PASSWORD, "{FFFFFF}LOGIN", str, "Login", "Cancelar");
}
}
case Login: {
if(!strlen(inputtext))
{
SendClientMessage(playerid, -1, "[{FFFFFF}ERRO ] Digite Sua senha para logar no servidor!");
format(str, sizeof(str), "Ola, seja bem vindo ao servidor novamente!");
ShowPlayerDialog(playerid, Login, DIALOG_STYLE_PASSWORD, "{FFFFFF}LOGIN", str, "Login", "Cancelar");
}
if(strcmp(inputtext, DOF2_GetString(gfile, "Senha"), true) == 0)
{
GivePlayerMoney(playerid, DOF2_GetInt(gfile, "Dinheiro"));
SetPlayerHealth(playerid, DOF2_GetFloat(gfile, "Vida"));
SetPlayerArmour(playerid, DOF2_GetFloat(gfile, "Colete"));
SetPlayerScore(playerid, DOF2_GetInt(gfile, "Level"));
SpawnPlayer(playerid);
SendClientMessage(playerid, -1, "{FFFFFF}Login efeituado com sucesso!");
}
else
{
format(str, sizeof(str), "Ola, seja bem vindo ao servidor novamente!");
ShowPlayerDialog(playerid, Login, DIALOG_STYLE_PASSWORD, "{FFFFFF}LOGIN", str, "Login", "Cancelar");
}
}
}
return 1;
}
Re: Vocкs poderiam me ajuda em um problema? -
AutoMatic2 - 20.07.2018
Para setar o dinheiro quando ele Registrar usa o GivePlayerMoney, o DOF2_SetInt(gfile, "Dinheiro", 1000); nao funciona
PHP код:
GivePlayerMoney(playerid, 1000);
Seu poblema quando nascer sem vida eu nгo sei o que й, mas tenta mudar seu Registro assim:
PHP код:
DOF2_SetFloat(gfile, "Vida", 100.0);
DOF2_SetFloat(gfile, "Colete", 0.0);
Eu aconselho usar
enum em seu sistema
PHP код:
enum pInfo
{
pDinheiro,
pLevel,
pAdministrador,
pCorregedor,
pModerador,
pAjudante,
pMaster,
Float:pVida,
Float:pColete
};
new PlayerInfo[ MAX_PLAYERS ][ pInfo ];
Re: Vocкs poderiam me ajuda em um problema? -
Santso - 20.07.2018
PHP код:
//fiz o sistema de login para vc tenta entender e adiciona oque quer salvar ai
//coloca isso no topo da gm
enum pInfo
{
pAdmin[5],
pDinheiro,
pSkin
}
#define DIALOG_REGISTRO 0
#define DIALOG_LOGIN 1
new PlayerInfo[MAX_PLAYERS][pInfo];
new Float: SaveX;
new Float: SaveY;
new Float: SaveZ;
new Float: Vida;
//-----------------------------------
public OnPlayerConnect(playerid)
{
new gfile[100];
new name[24];
GetPlayerName(playerid, name, sizeof(name));
format(gfile, sizeof(gfile), "Contas/%s.txt", name)
if(!DOF2_FileExists(gfile))
{
ShowPlayerDialog(playerid, DIALOG_REGISTRO, DIALOG_STYLE_PASSWORD, "Registro", "Digite uma senha para se registrar", "Registrar", "Sair");
}
else
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "LOGIN", "Digite sua senha para logar", "Logar", "Sair");
}
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
new gfile[100];//tu nгo crio a variavel local do file, ela tem que ser local nгo global!
new name[24];//tu nгo crio a variavel do nome!
GetPlayerName(playerid, name, sizeof(name));//tu nгo pego o nome do player!
format(gfile, sizeof(gfile), "Contas/%s.txt", name);
if(dialogid == DIALOG_REGISTRO)
{
if(response)
{
DOF2_CreateFile(gfile, inputtext);//aqui ja coloca a senha que ele digitou no arquivo
DOF2_SetInt(gfile,"Admin",PlayerInfo[playerid][pAdmin] = 0);//aqui йo level de adm do player comeзa em 0
DOF2_SetInt(gfile,"Skin",PlayerInfo[playerid][pSkin] = 163);//aqui йa skin o player vai comeзa com a 163, muda para que vc quiser
DOF2_SetInt(gfile,"Dinheiro",PlayerInfo[playerid][pDinheiro] = 6000);//aqui o dinheiro o player vai comeзar com 6 mil
DOF2_SetFloat(file,"SaveX",SaveX);//aqui as coordenadas onde ele saiu
DOF2_SetFloat(file,"SaveY",SaveY);
DOF2_SetFloat(file,"SaveZ",SaveZ);
DOF2_SaveFile();
SetSpawnInfo(playerid, 0, PlayerInfo[playerid][pSkin], 1516.1222, -1633.0979, 14.0469, 0, 0, 0, 0, 0, 0, 0);//aqui spawna o player mude para coordenada que vc quer
SpawnPlayer(playerid);
GivePlayerMoney(playerid, PlayerInfo[playerid][pDinheiro]);//aqui da o dinheiro
}
}
if(dialogid == DIALOG_LOGIN)
{
if(response)
{
if(DOF2_CheckLogin(file,inputtext))
{
PlayerInfo[playerid][pAdmin] = DOF2_GetInt(file, "Admin");
PlayerInfo[playerid][pDinheiro] = DOF2_GetInt(file, "Dinheiro");
PlayerInfo[playerid][pSkin] = DOF2_GetInt(file, "Skin");
SaveX = DOF2_GetFloat(file, "SaveX");
SaveY = DOF2_GetFloat(file, "SaveY");
SaveZ = DOF2_GetFloat(file, "SaveZ");
SetPlayerPos(playerid, SaveX, SaveY, SaveZ);
SetPlayerSkin(playerid,PlayerInfo[playerid][pSkin]);
GivePlayerMoney(playerid,PlayerInfo[playerid][pDinheiro]);
}
}
else
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "LOGIN", "Digite sua senha", "Logar", "Sair");
SendClientMessage(playerid, -1, "Digite a senha correta para logar!");
}
}
//vamos criar uma stock para salvar os dados quando ele sair.
stock salvardados(playerid)
{
new name[24];
GetPlayerName(playerid, name, sizeof(name));
new gfile[100];
format(gfile, sizeof(gfile), "Contas/%s.txt", name);
GetPlayerPos(playerid, SaveX, SaveY, SaveZ);
DOF2_SetInt(file,"Admin",PlayerInfo[playerid][pAdmin]);
DOF2_SetInt(file,"Skin",GetPlayerSkin(playerid));
DOF2_SetInt(file,"Dinheiro",GetPlayerMoney(playerid));
DOF2_SetFloat(file,"SaveX",SaveX);
DOF2_SetFloat(file,"SaveY",SaveY);
DOF2_SetFloat(file,"SaveZ",SaveZ);
DOF2_SaveFile();
return 1;
}
// quando ele desconectar chama a stock
public OnPlayerDisconnect(playerid, reason)
{
salvardados(playerid);
return 1;
}
Re: Vocкs poderiam me ajuda em um problema? -
Santso - 20.07.2018
bom fiz o sistema para vc alinha tudo ai pq nгo fiz no pwn vai dar erro de loose identation, agr pega essa base e adiciona oque mais quiser salvar ai, se ajudei +rep
Re: Vocкs poderiam me ajuda em um problema? -
FerrariL - 20.07.2018
O erro estб aqui:
PHP код:
DOF2_SetFloat(gfile, "Vida", GetPlayerHealth(playerid, health));
DOF2_SetFloat(gfile, "Colete", GetPlayerArmour(playerid, armour));
Vocк estб usando as funзхes
GetPlayerHealth e
GetPlayerArmour de forma errada.
Elas nгo retorna o valor da vida ou valor do colete e sim outros valores que a prуpria Wiki explica, vocк deve passar as variбveis health e armour e elas ira adquirir o valor da vida e colete do player, pois ambas funзхes usa passagem por referкncia.
Antes de usar o DOF2_SetFloat vocк deve usar ambas as funзхes:
PHP код:
GetPlayerHealth(playerid, health);
GetPlayerArmour(playerid, armour);
pois caso contrбrio a vida e colete do player serб setado como 0, pois й o valor que toda variбvel se inicia em pawn.
O correto a se fazer:
PHP код:
DOF2_SetFloat(gfile, "Vida", health);
DOF2_SetFloat(gfile, "Colete", armour);