Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <sscanf2>
- #include <a_mysql>
- // -------------------------------
- #define HOST "localhost"
- #define USER "root"
- #define SENHA ""
- #define DATABASE "samp"
- new MySQL: MYSQLConnected;
- // -------------------------------
- #define DIALOG_LOGIN 1
- #define DIALOG_REGISTRO 2
- // -------------------------------
- #define TEMPO_LOGIN 30
- #define DEFAULTPOSX 1139.4064
- #define DEFAULTPOSY -1761.9249
- #define DEFAULTPOSZ 13.5955
- #define DEFAULTPOSA 4.5833
- // -------------------------------
- enum E_PLAYERS{
- ID, // MYSQL ID, int
- Nome[MAX_PLAYER_NAME], // string
- Senha, // string
- Money, // int
- Skin, // int
- Score, // int
- Float: PosX, // float
- Float: PosY, // float
- Float: PosZ, // float
- Float: PosA, // float
- Interior, // int
- VirtualWorld, // int
- bool: pLogado, // se o player estiver logado
- }
- new Player[MAX_PLAYERS][E_PLAYERS];
- // --------------------------------
- main() {}
- public OnGameModeInit()
- {
- MySQLConnect(); // Verifica se o banco de dados está ligado
- CriarTabela(); // Crias as tabelas
- return 1;
- }
- public OnGameModeExit()
- {
- FecharServidor(); // Quando o servidor fechar todos os jogadores onlines vão sair como se fosse por contra propria
- 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)
- {
- MYSQLConnected = mysql_connect(HOST, USER, SENHA, DATABASE);
- GetPlayerName(playerid, Player[playerid][Nome], 20);
- new Query[90];
- mysql_format(MYSQLConnected, Query, sizeof(Query), "SELECT `ID`, `SENHA` FROM `Jogadores` WHERE `Player`='%s' ",Player[playerid][Nome]);
- mysql_tquery(MYSQLConnected, Query, "VerificarContas", "i", playerid);
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- SalvarDados(playerid);
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- return 1;
- }
- public OnVehicleSpawn(vehicleid)
- {
- return 1;
- }
- public OnVehicleDeath(vehicleid, killerid)
- {
- return 1;
- }
- public OnPlayerText(playerid, text[])
- {
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- if (strcmp("/mycommand", cmdtext, true, 10) == 0)
- {
- // Do something here
- return 1;
- }
- 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[])
- {
- new Dialog[240];
- if(dialogid == DIALOG_REGISTRO){
- if(!response) return Kick(playerid);
- if(strlen(inputtext) < 4 || strlen(inputtext) > 20){
- SendClientMessage(playerid, -1,"{0xFF0000AA}[ERRO]Apenas entre 4 a 20 Caracteres");
- format(Dialog, sizeof(Dialog), "{0xFFFFFFAA}%s\n{0x80FF00AA}STATUS: NÃO REGISTRADA", Player[playerid][Nome]);
- ShowPlayerDialog(playerid, DIALOG_REGISTRO, DIALOG_STYLE_INPUT, "Login", Dialog, "Confirmar", "Sair");
- }else{
- new Query[100];
- mysql_format(MYSQLConnected, Query, sizeof(Query), "INSERT INTO `Jogadores`(`Player`.`Senha`), VALUES('%s','%s')", Player[playerid][Nome], inputtext);
- mysql_tquery(MYSQLConnected, Query, "DadosRegistrados", "i", playerid);
- RegistrarDados(playerid);
- }
- }
- if(dialogid == DIALOG_LOGIN){
- if(!response) return Kick(playerid);
- if(!strcmp(Player[playerid][Senha], inputtext, true, 20)){
- new Query[70];
- mysql_format(MYSQLConnected, Query, sizeof(Query), "SELECT * FROM `Jogadores` Nome='%s'", Player[playerid][Nome]);
- mysql_tquery(MYSQLConnected, Query, "CarregarContas", "d", playerid);
- }else{
- SendClientMessage(playerid, -1,"{0xFF0000AA}[ERRO]Senha incorreta");
- format(Dialog, sizeof(Dialog), "{0xFFFFFFAA}%s\n{0xFF0000AA}STATUS: Registrado", Player[playerid][Nome]);
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", Dialog, "Confirmar", "Sair");
- }
- }
- // == //
- return 1;
- }
- public OnPlayerClickPlayer(playerid, clickedplayerid, source)
- {
- return 1;
- }
- //=========================
- forward MySQLConnect();
- public MySQLConnect(){
- MYSQLConnected = mysql_connect(HOST, USER, SENHA, DATABASE);
- if (MYSQLConnected == MYSQL_INVALID_HANDLE || mysql_errno(MYSQLConnected) != 0){
- printf("[MySQL]Conexão com o banco de dados falhou");
- SendRconCommand("exit");
- }else{
- printf("[MySQL]Conectado ao banco de dados com sucesso");
- }
- return 1;
- }
- // --------------------------
- forward FecharServidor();
- public FecharServidor(){
- for (new i = 0, j = GetPlayerPoolSize(); i <= j; i++){
- if (IsPlayerConnected(i)){
- OnPlayerDisconnect(i, 1);
- }
- }
- mysql_close(MYSQLConnected);
- return 1;
- }
- // -------------------------
- forward CriarTabela();
- public CriarTabela(){
- MYSQLConnected = mysql_connect(HOST, USER, SENHA, DATABASE);
- mysql_query(MYSQLConnected ,"CREATE TABLE IF NOT EXISTS Jogadores(ID INT AUTO_INCREMENT PRIMARY KEY,Player INT(20),Senha VARCHAR(15), Dinheiro INT(20), Skin INT(20), Score INT(20), PosX FLOAT(20), PosY FLOAT(20), PosZ FLOAT(20), PosA FLOAT(20), Interior INT(10), VirtualWorld INT(10))");
- return 1;
- }
- // -------------------------
- forward VerificarContas(playerid);
- public VerificarContas(playerid){
- new Dialog[240];
- if(cache_num_rows() > 0){
- cache_get_value(0, "Senha", Player[playerid][Senha]);
- format(Dialog, sizeof(Dialog), "{0xFFFFFFAA}%s\n{0xFF0000AA}STATUS: Registrado", Player[playerid][Nome]);
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", Dialog, "Confirmar", "Sair");
- }else{
- format(Dialog, sizeof(Dialog), "{0xFFFFFFAA}%s\n{0x80FF00AA}STATUS: NÃO REGISTRADA", Player[playerid][Nome]);
- ShowPlayerDialog(playerid, DIALOG_REGISTRO, DIALOG_STYLE_INPUT, "Login", Dialog, "Confirmar", "Sair");
- }
- return 1;
- }
- // --------------------------
- forward DadosRegistrados(playerid);
- public DadosRegistrados(playerid){
- Player[playerid][ID] = cache_insert_id();
- printf("CONTA ID %d REGISTRADA", Player[playerid][ID]);
- return 1;
- }
- // --------------------------
- forward CarregarContas(playerid);
- public CarregarContas(playerid){
- cache_get_value_int(0, "ID", Player[playerid][ID]);
- cache_get_value_int(0, "Skin", Player[playerid][Skin]);
- cache_get_value_int(0, "Score", Player[playerid][Score]);
- cache_get_value_int(0, "Dinheiro", Player[playerid][Money]);
- cache_get_value_int(0, "Interior", Player[playerid][Interior]);
- cache_get_value_int(0, "VirtualWorld", Player[playerid][VirtualWorld]);
- cache_get_value_float(0, "PosX", Player[playerid][PosX]);
- cache_get_value_float(0, "PosY", Player[playerid][PosY]);
- cache_get_value_float(0, "PosZ", Player[playerid][PosZ]);
- cache_get_value_float(0, "PosA", Player[playerid][PosA]);
- CarregarDados(playerid);
- return 1;
- }
- // ----------------------------
- stock RegistrarDados(playerid){
- Player[playerid][Skin] = 23;
- Player[playerid][Score] = 0;
- Player[playerid][Money] = 1500;
- Player[playerid][Interior] = 0;
- Player[playerid][VirtualWorld] = 0;
- Player[playerid][PosX] = DEFAULTPOSX;
- Player[playerid][PosY] = DEFAULTPOSY;
- Player[playerid][PosZ] = DEFAULTPOSZ;
- Player[playerid][PosA] = DEFAULTPOSA;
- CarregarDados(playerid);
- return 1;
- }
- // -----------------------------
- stock CarregarDados(playerid){
- Player[playerid][pLogado] = true;
- SetPlayerScore(playerid, Player[playerid][Score]);
- GivePlayerMoney(playerid, Player[playerid][Money]);
- SetPlayerInterior(playerid, Player[playerid][Interior]);
- SetPlayerVirtualWorld(playerid, Player[playerid][VirtualWorld]);
- SetSpawnInfo(playerid, 0, Player[playerid][Skin], Player[playerid][PosX], Player[playerid][PosY], Player[playerid][PosZ], Player[playerid][PosA], 0, 0, 0, 0, 0, 0);
- return 1;
- }
- // ------------------------------
- stock SalvarDados(playerid){
- Player[playerid][Score] = GetPlayerScore(playerid);
- Player[playerid][Skin] = GetPlayerSkin(playerid);
- Player[playerid][Money] = GetPlayerMoney(playerid);
- Player[playerid][Interior] = GetPlayerInterior(playerid);
- Player[playerid][VirtualWorld] = GetPlayerVirtualWorld(playerid);
- GetPlayerPos(playerid ,Player[playerid][PosX], Player[playerid][PosY], Player[playerid][PosZ]);
- GetPlayerFacingAngle(playerid, Player[playerid][PosA]);
- new Query[350];
- mysql_format(MYSQLConnected, Query, sizeof(Query), "UPDATE `Jogadores` SET `Player`='%s', `Dinheiro`='%d', `Skin`='%d', `Score`='%d', `PosY`='%f',`PosZ`='%f',`PosX`='%f',`PosA`='%f', `Interior`='%d', `VirtualWorld`='%d' WHERE `ID`='%d'",
- Player[playerid][Nome],
- Player[playerid][Money],
- Player[playerid][Skin],
- Player[playerid][Score],
- Player[playerid][PosX],
- Player[playerid][PosY],
- Player[playerid][PosZ],
- Player[playerid][PosA],
- Player[playerid][Interior],
- Player[playerid][VirtualWorld],
- Player[playerid][ID]);
- mysql_tquery(MYSQLConnected, Query, "DadosSalvos", "d", playerid);
- Player[playerid][Money] = 0;
- Player[playerid][Score] = 0;
- Player[playerid][Skin] = 0;
- Player[playerid][PosX] = 0;
- Player[playerid][PosY] = 0;
- Player[playerid][PosZ] = 0;
- Player[playerid][PosA] = 0;
- Player[playerid][Interior] = 0;
- Player[playerid][VirtualWorld] = 0;
- Player[playerid][pLogado] = false;
- return 1;
- }
- // --------------------------------------------------
- forward DadosSalvos(playerid);
- public DadosSalvos(playerid) return printf("-> Conta salva ID: %d", Player[playerid][ID]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement