Код:
#include <a_samp>
#include <a_mysql>
eu queria o de winrace dinheiro score
enum {
DIALOG_REGISTER,
DIALOG_LOGIN
}
forward jig_OnPlayerConnect(playerid);
forward jig_OnPlayerLogin(playerid);
new
jDB,
jString[256],
jName[MAX_PLAYERS][24],
bool:jLogged[MAX_PLAYERS],
jTries[MAX_PLAYERS]
;
public OnFilterScriptInit() {
jDB = mysql_connect("localhost", "root", "jigRegister", "123");
if(mysql_ping(jDB) < 1)
return SendRconCommand("unloadfs jigRegister");
print("Connected!");
mysql_function_query(jDB, "CREATE TABLE IF NOT EXISTS `jUsers` (`Name` VARCHAR(24) NOT NULL,`Password` VARCHAR(32) NOT NULL, `Skin` INT(11) NOT NULL DEFAULT '299',`Money` INT(11) NOT NULL DEFAULT '5000',`Score` INT(11) NOT NULL DEFAULT '0')", false, "", "");
return 1;
}
public OnFilterScriptExit() {
mysql_close(jDB);
return 1;
}
public OnPlayerConnect(playerid) {
jTries[playerid] = 0;
GetPlayerName(playerid, jName[playerid], 24);
mysql_format(jDB, jString, "SELECT * FROM `jUsers` WHERE `Name` = '%s'", jName[playerid]);
mysql_function_query(jDB, jString, true, "jig_OnPlayerConnect", "i", playerid);
return 1;
}
public jig_OnPlayerConnect(playerid) {
new
jRows,
jFields
;
cache_get_data(jRows, jFields, jDB);
if(!jRows) {
format(jString, sizeof(jString), "{FFFFFF}Olб {1E90FF}%s{FFFFFF}\nVocк ainda nгo й registrado no servidor.\nDigite uma senha para se registrar.", jName[playerid]);
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{FFFFFF}Registro", jString, "Registrar", "Cancelar");
return 1;
}
format(jString, sizeof(jString), "{FFFFFF}Olб denovo {1E90FF}%s{FFFFFF}\nDigite sua senha para fazer login no servidor.", jName[playerid]);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Login", jString, "Login", "Cancelar");
return 1;
}
public OnPlayerDisconnect(playerid, reason) {
#pragma unused reason
if(jLogged[playerid]) {
mysql_format(jDB, jString,
"UPDATE `jUsers` SET WinRace = %d,`Skin` = %d, `Money` = %d, Score = %d WHERE `Name` = '%s'",
winsr[playerid],
GetPlayerSkin(playerid),
GetPlayerMoney(playerid),
GetPlayerScore(playerid),
jName[playerid]
);
mysql_function_query(jDB, jString, false, "", "");
jLogged[playerid] = false;
}
return 1;
}
public OnPlayerSpawn(playerid)
{
return (jLogged[playerid]) ? (1) : (Kick(playerid));
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
switch(dialogid) {
case DIALOG_REGISTER: {
if(!response)
Kick(playerid);
else {
if(1 < strlen(inputtext) > 32) {
format(jString, sizeof(jString), "{FFFFFF}Olб {1E90FF}%s{FFFFFF}\nVocк ainda nгo й registrado no servidor.\nDigite uma senha para se registrar.\n\n{E31919}Erro: Sua senha deve conter entre 1 e 32 caracteres.", jName[playerid]);
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{FFFFFF}Registro", jString, "Registrar", "Cancelar");
} else {
mysql_format(jDB, jString, "INSERT INTO `jUsers` (`Name`,`Password`) VALUES ('%s','%s')", jName[playerid], inputtext);
mysql_function_query(jDB, jString, false, "", "");
format(jString, sizeof(jString), "{FFFFFF}Muito bem {1E90FF}%s{FFFFFF}\nConta registrada com sucesso.\nDigite sua senha para fazer login.", jName[playerid]);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Login", jString, "Login", "Cancelar");
}
}
}
case DIALOG_LOGIN: {
if(!response)
Kick(playerid);
else {
mysql_format(jDB, jString, "SELECT * FROM `jUsers` WHERE `Name` = '%s' AND `Password` = '%s'", jName[playerid], inputtext);
mysql_function_query(jDB, jString, true, "jig_OnPlayerLogin", "i", playerid);
}
}
}
return 1;
}
public jig_OnPlayerLogin(playerid) {
new
jRows,
jFields
;
cache_get_data(jRows, jFields, jDB);
if(!jRows)
{
++ jTries[playerid];
if(jTries[playerid] == 5)
return BanEx(playerid, "5 erros de senha");
format(jString, sizeof(jString), "{FFFFFF}Senha incorreta {1E90FF}%s{FFFFFF}\nDigite sua verdadeira senha.\nChances: {E31919}%d", jName[playerid], (5 - jTries[playerid]));
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Login", jString, "Login", "Cancelar");
return 1;
}
jLogged[playerid] = true;
//Carregamento
winsr[playerid] = cache_get_field_content_int(0,"WinRace ");
cache_get_field_content(0, "Money", jString, jDB);
ResetPlayerMoney(playerid); GivePlayerMoney(playerid, strval(jString));
cache_get_field_content(0, "Score", jString, jDB);
SetPlayerScore(playerid, strval(jString));
cache_get_field_content(0, "Skin", jString, jDB);
SetSpawnInfo(playerid, 0, strval(jString), 1568.2737, -1892.3541, 13.5595, 0.8003, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
return 1;
}