16.08.2016, 17:25
Код:
//============================================================================== #include <a_samp> //============================================================================== #include <a_mysql> //============================================================================== #define COLOR_CYAN 0x80FFFFFF #define COLOR_TAN 0xFFDBA07D #define COLOR_CONNECT 0xFF969696 #define COLOR_MANAGEMENT 0xFF4853A4 #define COLOR_SENIORGREEN 0xFF009F00 #define COLOR_BRIGHTGREEN 0x0CF710FF #define COLOR_LIGHTGREEN 0x80A05CFF #define COLOR_WHITE 0xFFFFFFFF #define COLOR_LIGHTRED 0xFF6347FF #define COLOR_GOLD 0xD7BD52FF #define COLOR_PINK 0xBEA1D3FF #define COLOR_GREY 0xB5B5B5FF #define COLOR_FADE1 0xE6E6E6E6 #define COLOR_FADE2 0xC8C8C8C8 #define COLOR_FADE3 0xAAAAAAAA #define COLOR_FADE4 0x8C8C8C8C #define COLOR_FADE5 0x6E6E6E6E #define COLOR_BLUE 0x7E7EFCFF #define COLOR_FACTIONGREEN 0x7BDDA5FF #define COLOR_YELLOW 0xF0F000FF #define COLOR_DARKYELLOW 0xE5C43EFF #define COLOR_DEATHRED 0xAA3333AA #define COLOR_OOC 0xA9C4E4FF #define COLOR_ADVERT 0x00D900FF #define COLOR_CHAT 0x2D8289FF #define COLOR_COPBLUE 0x9291E7FF #define COLOR_EMTRED 0xE27979FF #define COLOR_ORANGE 0xE2A31DFF #define COLOR_MODERATORS 0x2587CEFF #define COLOR_LEADS 0xAA0000FF #define COLOR_ADMINS 0x009900FF #define COLOR_MODS 0x6f1919FF #define COLOR_OLD_RADIO 0xF9F57DFF #define COLOR_LIGHTBLUE 0x33CCFFAA #define COLOR_GREENISHGOLD 0xCCFFDD56 #define COLOR_BLUEGREEN 0x46BBAA00 #define COLOR_GREEN 0x33AA33AA #define COLOR_RADIO 0xFFFFCCAA #define COLOR_PURPLE 0x9b59b6AA #define COLOR_BROWN 0x8A3324AA #define COLOR_LIME 0x99FF00AA #define COLOR_BLACK 0x000000AA //============================================================================== #define SQL_HOST "localhost" #define SQL_USER "root" #define SQL_PASS "******" #define SQL_DB "server" //============================================================================== #define SPAWN_X 821.9599 #define SPAWN_Y -1356.0155 #define SPAWN_Z -0.5078 #define SPAWN_A 139.9992 //============================================================================== #define pub:%1(%2) forward %1(%2); public %1(%2) //============================================================================== new mysql; native WP_Hash(buffer[], len, const str[]); enum { FirstDialog, LoginDialogFelh, LoginDialogPass, RegisterDialogFelh, RegisterDialogName, RegisterDialogPass }; enum PlayerData { ID, username[50], name[MAX_PLAYER_NAME], password[129], skin, IP[16], admin, money, Float:PosX, Float:PosY, Float:PosZ, Float:PosA }; new Player[MAX_PLAYERS][PlayerData]; main() { print("\n----------------------------------"); print(" Roleplay gamemode init by Memphis"); print("----------------------------------\n"); } public OnGameModeInit() { SetNameTagDrawDistance(30.0); DisableInteriorEnterExits(); EnableStuntBonusForAll(0); ShowPlayerMarkers(PLAYER_MARKERS_MODE_OFF); mysql = mysql_connect(SQL_HOST,SQL_USER,SQL_DB,SQL_PASS); if(mysql_errno() != 0) { printf("[MySQL] Nem sikerьlt csatlakozni az adatbбzishoz."); } else { printf("[MySQL] Sikeresen kapcsolуdott a szerver az adatbбzishoz."); new stats[150]; mysql_stat(stats); print(stats); } } public OnGameModeExit() { mysql_close(); return 1; } public OnPlayerConnect(playerid) { ShowPlayerDialog(playerid, FirstDialog, DIALOG_STYLE_LIST, "Vбlassz", "Bejelentkezйs\nRegisztrбciу", "Kivбlaszt", "Kilйp"); return 1; } public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) { switch(dialogid) { case FirstDialog: { if(!response) Kick(playerid); switch(listitem) { case 0: ShowPlayerDialog(playerid, LoginDialogFelh, DIALOG_STYLE_INPUT, "Bejelentkezйs", "Ьdvцzlьnk a szerveren!\nKйrjьk add meg a felhasznбlуnevedet a bejelentkezйshez!", "Bejelentkezйs", "Vissza"); case 1: ShowPlayerDialog(playerid, RegisterDialogFelh, DIALOG_STYLE_INPUT, "Regisztrбciу", "Ьdvцzlьnk a szerveren!\nKйrjьk vбlassz egy tetszőleges felhasznбlуnevet magadnak!", "Regisztrбciу", "Vissza"); } } case LoginDialogFelh: { if(!response) ShowPlayerDialog(playerid, FirstDialog, DIALOG_STYLE_LIST, "Vбlassz", "Bejelentkezйs\nRegisztrбciу", "Kivбlaszt", "Kilйp"); new rows, fields; cache_get_data(rows, fields, mysql); new Query[128],string[164]; mysql_format(mysql, Query, sizeof(Query), "SELECT `username` FROM `accounts` WHERE `username` = '%s' LIMIT 1", inputtext); if(rows) { cache_get_field_content(0, "username", Player[playerid][username], mysql, 150); ShowPlayerDialog(playerid, LoginDialogPass, DIALOG_STYLE_INPUT, "Bejelentkezйs", "Kйrjьk add meg a felhasznбlуnevedhez tartozу jelszуt!", "Bejelentkezйs", "Vissza"); } else { format(string,sizeof(string),"Hiba: a(z) %s felhasznбlу nem talбlhatу az adatbбzisban, kйrjьk prуbбld ъjra!\nHa esetleg elfelejtetted valamelyik adatodat vedd fel velьnk a kapcsolatot fуrumon!\nDe ha esetleg nincs felhasznбlуd menj vissza йs regisztrбlj egyet!",inputtext); SendClientMessage(playerid, COLOR_LIGHTRED, string); ShowPlayerDialog(playerid, LoginDialogFelh, DIALOG_STYLE_INPUT, "Bejelentkezйs", "Ьdvцzlьnk a szerveren!\nKйrjьk add meg a felhasznбlуnevedet a bejelentkezйshez!", "Bejelentkezйs", "Vissza"); } } case LoginDialogPass: { if(!response) ShowPlayerDialog(playerid, LoginDialogFelh, DIALOG_STYLE_INPUT, "Bejelentkezйs", "Ьdvцzlьnk a szerveren!\nKйrjьk add meg a felhasznбlуnevedet a bejelentkezйshez!", "Bejelentkezйs", "Vissza"); new rows, fields; cache_get_data(rows, fields, mysql); new Query[160], hashpass[129]; WP_Hash(hashpass, sizeof(hashpass), inputtext); mysql_format(mysql, Query, sizeof(Query), "SELECT `password` FROM `accounts` WHERE `username` = '%s', `password` = '%e' LIMIT 1", Player[playerid][username], hashpass); if(rows) { OnAccountLogin(playerid); } else { SendClientMessage(playerid, COLOR_LIGHTRED, "Hiba: Elgйpelted a jelszavadat!"); ShowPlayerDialog(playerid, LoginDialogPass, DIALOG_STYLE_INPUT, "Bejelentkezйs", "Kйrjьk add meg a felhasznбlуnevedhez tartozу jelszуt!", "Bejelentkezйs", "Vissza"); } } case RegisterDialogFelh: { if(!response) ShowPlayerDialog(playerid, FirstDialog, DIALOG_STYLE_LIST, "Vбlassz", "Bejelentkezйs\nRegisztrбciу", "Kivбlaszt", "Kilйp"); new len = strlen(inputtext); if(len < 5) { SendClientMessage(playerid, COLOR_LIGHTRED, "Hiba: A felhasznбlу nйvnek 5 karakternйl hosszabbnak kell lennie!"); ShowPlayerDialog(playerid, RegisterDialogFelh, DIALOG_STYLE_INPUT, "Regisztrбciу", "Ьdvцzlьnk a szerveren!\nKйrjьk vбlassz egy tetszőleges felhasznбlуnevet magadnak!", "Regisztrбciу", "Vissza"); } else { SetPVarString(playerid,"username",inputtext); ShowPlayerDialog(playerid, RegisterDialogName, DIALOG_STYLE_INPUT, "Regisztrбciу", "Kйrjьk vбlassz egy RP-s karakternevet magadnak!", "Regisztrбciу", "Vissza"); } } case RegisterDialogName: { if(!response) ShowPlayerDialog(playerid, RegisterDialogFelh, DIALOG_STYLE_INPUT, "Regisztrбciу", "Ьdvцzlьnk a szerveren!\nKйrjьk vбlassz egy tetszőleges felhasznбlуnevet magadnak!", "Regisztrбciу", "Vissza"); new len = strlen(inputtext); if(len < 10 || len > 23) { SendClientMessage(playerid, COLOR_LIGHTRED, "Hiba: A karaktered nevйnek 10 karakternйl hosszabbnak йs 24 karakternйl rцvidebbnek kell lennie!"); ShowPlayerDialog(playerid, RegisterDialogName, DIALOG_STYLE_INPUT, "Regisztrбciу", "Kйrjьk vбlassz egy RP-s karakternevet magadnak!", "Regisztrбciу", "Vissza"); } else { new pos = strfind(inputtext, "_"); if(pos == -1) { SendClientMessage(playerid, COLOR_LIGHTRED, "Hiba: A karakter nйvnek az RP-s keretek kцzй kell tartoznia!\nVezetйknйv_Keresztnйv formбban."); ShowPlayerDialog(playerid, RegisterDialogName, DIALOG_STYLE_INPUT, "Regisztrбciу", "Kйrjьk vбlassz egy RP-s karakternevet magadnak!", "Regisztrбciу", "Vissza"); } else { SetPVarString(playerid,"name",inputtext); ShowPlayerDialog(playerid, RegisterDialogPass, DIALOG_STYLE_INPUT, "Regisztrбciу", "Mбr csak egy jelszуt kell megadni a felhasznбlуd mellй!", "Regisztrбciу", "Vissza"); } } } case RegisterDialogPass: { if(!response) ShowPlayerDialog(playerid, RegisterDialogName, DIALOG_STYLE_INPUT, "Regisztrбciу", "Kйrjьk vбlassz egy RP-s karakternevet magadnak!", "Regisztrбciу", "Vissza"); new len = strlen(inputtext); if(len < 5) { SendClientMessage(playerid, COLOR_LIGHTRED, "Hiba: A jelszavadnak 5 karakternйl hosszabbnak kell lennie!"); ShowPlayerDialog(playerid, RegisterDialogPass, DIALOG_STYLE_INPUT, "Regisztrбciу", "Mбr csak egy jelszуt kell megadni a felhasznбlуd mellй!", "Regisztrбciу", "Vissza"); } else { new hashpass[129], Query[256], playerip[16]; WP_Hash(hashpass, sizeof(hashpass), inputtext); GetPlayerIp(playerid, playerip, sizeof(playerip)); GetPVarString(playerid, "username", Player[playerid][username], 50); GetPVarString(playerid, "name", Player[playerid][name], 24); mysql_format(mysql, Query, sizeof(Query), "INSERT INTO `accounts` (skin, admin) VALUES ('23', '0')"); printf("[Regisztrбciу] Ъj felhasznбlу regisztrбlt"); SendClientMessage(playerid,COLOR_GREEN,"Sikeresen regisztrбltбl a szerverre!"); Player[playerid][skin] = 23; Player[playerid][admin] = 0; Player[playerid][money] = 5000; Player[playerid][PosX] = SPAWN_X; Player[playerid][PosY] = SPAWN_Y; Player[playerid][PosZ] = SPAWN_Z; Player[playerid][PosA] = SPAWN_A; SetSpawnInfo(playerid, 0, 23, SPAWN_X, SPAWN_Y, SPAWN_Z, SPAWN_A, 0, 0, 0, 0, 0, 0); SpawnPlayer(playerid); SetPlayerColor(playerid, COLOR_WHITE); SetPlayerName(playerid, Player[playerid][name]); GivePlayerMoney(playerid,5000); } } } return false; } pub:OnAccountLogin(playerid) { new Query[256]; new rows, fields; cache_get_data(rows, fields, mysql); mysql_format(mysql, Query, sizeof(Query), "SELECT * FROM `accounts` WHERE `username` = '%s' LIMIT 1", Player[playerid][username]); if(rows) { SendClientMessage(playerid,COLOR_GREEN,"Sikeresen bejelentkeztйl!"); LoadStats(playerid); } return 1; } pub:LoadStats(playerid) { new Query[256]; mysql_format(mysql, Query, sizeof(Query), "SELECT `name`, `skin`, `admin`, `money`, `PosX`, `PosY`, `PosZ`, `PosA` FROM `accounts` WHERE `username` = '%s' ", Player[playerid][username]); cache_get_field_content(0, "name", Player[playerid][name], mysql, 24); Player[playerid][skin] = cache_get_field_content_int(0, "skin"); Player[playerid][admin] = cache_get_field_content_int(0, "admin"); Player[playerid][money] = cache_get_field_content_int(0, "money"); Player[playerid][PosX] = cache_get_field_content_float(0, "PosX"); Player[playerid][PosY] = cache_get_field_content_float(0, "PosY"); Player[playerid][PosZ] = cache_get_field_content_float(0, "PosZ"); Player[playerid][PosA] = cache_get_field_content_float(0, "PosA"); SetSpawnInfo(playerid, 0, Player[playerid][skin], Player[playerid][PosX], Player[playerid][PosY], Player[playerid][PosZ], Player[playerid][PosA], 0, 0, 0, 0, 0, 0); SpawnPlayer(playerid); SetPlayerColor(playerid, COLOR_WHITE); SetPlayerName(playerid, Player[playerid][name]); GivePlayerMoney(playerid,Player[playerid][money]); return 1; }
Please anyone help me. (Sorry bad english.)
Edit: I have R33 MySQL plugin and i use xampp.