10.03.2012, 13:10
i have made an MySQL saving system but it doesnt save i have PHP admin it creates the tables and it saves my admin level and my faction but not the password money and score so i hoped you maby saw the problem . .
Thanks.
Код:
#include <a_samp> #include <a_mysql> #include <zcmd> #include <sscanf2> ////////////////////////////////////// #define mysql_host "Localhost" //Has to be a string #define mysql_user "root" //Has to be a string #define mysql_password "" //There is none for wamp unless you set one. #define mysql_database "combinationparty" / ///////////////////////////////////// #define COLOR_TEAMS 0xC229BEC8 #define COLOR_HUMAN 0x00820FAA//team #define COLOR_ZOMBIE 0x003DF5AA//team #define COLOR_DENIE 0xC4090DC4 #define COLOR_ADMIN 0x54C2CF84 //////////////////////////////////// new IsRegistered[MAX_PLAYERS]; new Logged[MAX_PLAYERS]; new MoneyGiven[MAX_PLAYERS]; ////////////////////////////// new gTeam[MAX_PLAYERS]; new Faction[MAX_PLAYERS]; new FactionLeader[MAX_PLAYERS]; new AdminLevel[MAX_PLAYERS]; main() { print("\n----------------------------------"); print(" Blank Gamemode by your name here"); print("----------------------------------\n"); } public OnGameModeInit() { mysql_connect(mysql_host, mysql_user, mysql_database, mysql_password); mysql_query("CREATE TABLE IF NOT EXISTS playerdata(user VARCHAR(24)NOT NULL, password VARCHAR(41) NOT NULL, score INT(20) NULL, money INT(20) NULL,Faction INT(20) NULL, FactionLeader INT(20) NULL, IP VARCHAR(16) NULL )"); ConnectMysql(); mysql_debug(1); SetGameModeText("Blank Script"); AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0); 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) { MoneyGiven[playerid] = -1; new query[200], pname[24]; GetPlayerName(playerid, pname, 24); format(query, sizeof(query), "SELECT user FROM `playerdata` WHERE user = '%s'", pname); mysql_query(query); mysql_store_result(); new rows = mysql_num_rows(); if(rows != 0) { ShowPlayerDialog(playerid, 2, DIALOG_STYLE_PASSWORD,"Login","Welcome to Los Santos Zombie Roleplay server\nPlease log in: ", "Log in","Leave"); IsRegistered[playerid] = 1; } else { ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "Register","Welcome to Los Santos Zombie Roleplay server\nIt seems you dont have an account yet Please register :","Register","Cancel"); } mysql_free_result(); return 1; } public OnPlayerDisconnect(playerid, reason) { if(Logged[playerid] == 1) { new score = GetPlayerScore(playerid); new money = GetPlayerMoney(playerid); new faction = Faction[playerid]; new fLeader = FactionLeader[playerid]; new Adminlvl = AdminLevel[playerid]; new query[200], pname[24]; GetPlayerName(playerid, pname, 24); format(query, sizeof(query), "UPDATE playerdata SET score= '%d', money= '%d' Faction= '%d' FactionLeader= '%d' Adminlvl= '%d' WHERE user='%s'", score, money, faction, fLeader, Adminlvl, pname); mysql_query(query); } 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[]) { if(dialogid == 1) { if(response) { if(!strlen(inputtext) || strlen(inputtext) > 32) { SendClientMessage(playerid, 0xFF0000, "You must insert a password between 1-32 characters!"); ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "Register","Welcome to Los Santos \nIt seems you dont have an account yet Please register :\n ERROR:Please choose a password between 1-32 characters!","Register","Cancel"); //Shows our register dialog :). } else if(strlen(inputtext) > 0 && strlen(inputtext) < 100) { new escpass[100]; mysql_real_escape_string(inputtext, escpass); MySQL_Register(playerid, escpass); } } if(!response) { SendClientMessage(playerid, 0xFF0000, "You must register before logging in!"); ShowPlayerDialog(playerid, 15000, DIALOG_STYLE_INPUT, "Register","Welcome to Los Santos \n It seems you dont have an account yet Plese register :\n ERROR:Please enter a password !","Register","Cancel"); //Shows our register dialog :). } } if(dialogid == 2) //Dialog login { if(!response) { SendClientMessage(playerid, 0xFF0000, "You must login before you spawn!"); ShowPlayerDialog(playerid, 15500, DIALOG_STYLE_PASSWORD, "Login","Welcome to Los Santos \nPlease log in:\n You must login before you spawn!","Login","Cancel"); //Shows our login dialog :). } if(response) { new query[200], pname[24], escapepass[100]; GetPlayerName(playerid, pname, 24); mysql_real_escape_string(inputtext, escapepass); format(query, sizeof(query), "SELECT `user` FROM playerdata WHERE user = '%s' AND password = SHA1('%s')", pname, escapepass); mysql_query(query); mysql_store_result(); new numrows = mysql_num_rows(); if(numrows == 1) MySQL_Login(playerid); if(!numrows) { ShowPlayerDialog(playerid, 15500, DIALOG_STYLE_PASSWORD, "Login","Welcome to Los Santos !\n Please login :\n The password you typed was incorrect!","Login","Cancel"); //Shows our login dialog :). SendClientMessage(playerid, 0xFF0000, "Incorrect password!"); } mysql_free_result(); } } return 1; } public OnPlayerClickPlayer(playerid, clickedplayerid, source) { return 1; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// stock MySQL_Register(playerid, passwordstring[]) { new query[200], pname[24], IP[16]; GetPlayerName(playerid, pname, 24); GetPlayerIp(playerid, IP, 16); format(query, sizeof(query), "INSERT INTO playerdata (user, password, score, money, Faction, FactionLeader,Adminlvl, IP) VALUES('%s', SHA1('%s'), 0, 0, 0, 0, 0, '%s')", pname, passwordstring, IP); mysql_query(query); SendClientMessage(playerid, -1, "[System] : Registration Completed!"); Logged[playerid] = 1; return 1; } stock MySQL_Login(playerid) { new query[300], pname[24], savingstring[20]; GetPlayerName(playerid, pname, 24); format(query, sizeof(query), "SELECT * FROM playerdata WHERE user = '%s'", pname); mysql_query(query); mysql_store_result(); while(mysql_fetch_row_format(query,"|")) { mysql_fetch_field_row(savingstring, "score"); SetPlayerScore(playerid, strval(savingstring)); mysql_fetch_field_row(savingstring, "money"); MoneyGiven[playerid] = strval(savingstring); mysql_fetch_field_row(savingstring, "Faction"); Faction[playerid] = strval(savingstring); mysql_fetch_field_row(savingstring, "FactionLeader"); FactionLeader[playerid] = strval(savingstring); mysql_fetch_field_row(savingstring, "Adminlvl"); AdminLevel[playerid] = strval(savingstring); } mysql_free_result(); SendClientMessage(playerid, -1, "[System] : Login Complete!"); ShowPlayerDialog(playerid, 3, DIALOG_STYLE_LIST,"Choose your class!"," Civillian \n Zombie \n Evo\n CIA \n MIFCS ","Select","Leave Game"); Logged[playerid] = 1; return 1; } ConnectMysql() { if(mysql_connect(mysql_host, mysql_user, mysql_password, mysql_database)) print("[MySQL] Connection established."); else print("[MySQL] Connection failed."); }