Got it fixed, but for some reason the user won't save when registering..
Here is the code if you think you can fix it. Thanks.
Код:
#include <a_samp>
#include <a_mysql>
#include <zcmd>
#include <sscanf2>
new connectionGG;
#define MYSQL_HOST "localhost"
#define MYSQL_USER "root"
#define MYSQL_DB "maxzone"
#define MYSQL_PASS ""
#define COLOR_MAXZONE 0xFF2788C4FF
#define COLOR_ERROR 0xFFFF4040FF
#undef MAX_PLAYERS
#define MAX_PLAYERS 50
#define LOGIN_DIALOG 0
#define REGISTER_DIALOG 1
enum pEnum
{
Name[MAX_PLAYER_NAME],
Password[32],
Money
}
new pInfo[MAX_PLAYERS][pEnum];
main()
{
print("\n----------------------------------");
print(" Blank Gamemode by your name here");
print("----------------------------------\n");
}
public OnGameModeInit()
{
connectionGG = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DB ,MYSQL_PASS);
SetGameModeText("MXZ v0.1");
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)
{
return 1;
}
public OnPlayerConnect(playerid)
{
new szDestination[100],pName[24],string[164];
GetPlayerName(playerid,pName,24);
mysql_format(connectionGG, szDestination, sizeof(szDestination),"SELECT `Name` FROM `accounts` WHERE `Name` = '%s' LIMIT 1;",pName);
mysql_query(connectionGG, szDestination);
mysql_store_result();
if(mysql_num_rows() != 0)//if number of rows is different from 0 then continue
{
format(string,sizeof(string),"Bun venit %s!\n\nAcest cont este deja inregistrat.\n\nIntrodu parola.",pName);
ShowPlayerDialog(playerid,0,DIALOG_STYLE_INPUT,"{2788C4}L{A9C4E4}ogin",string,"Login","Cancel");
}
else
{
format(string,sizeof(string),"Bun venit %s!\n\nAcest cont este deja inregistrat.\n\nIntrodu parola.",pName);
ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"{2788C4}R{A9C4E4}egister",string,"Register","Cancel");
}
mysql_free_result();
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
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(strlen(inputtext) == 0)
{
new pName[MAX_PLAYER_NAME], string[256];
GetPlayerName(playerid, pName, sizeof(pName));
format(string,sizeof(string),"Bun venit %s!\n\nAcest cont este deja inregistrat.\n\nIntrodu parola.",pName);
ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"{2788C4}R{A9C4E4}egister",string,"Register","Cancel");
}
else
{
new EscapedText[60];
new Query[80];
mysql_real_escape_string(inputtext, EscapedText);
mysql_format(connectionGG, Query, sizeof(Query),"INSERT INTO `accounts` (Name,Password,Money) VALUES ('%s','%s,'0')",GetPName(playerid),EscapedText);
mysql_query(connectionGG, Query);
SendClientMessage(playerid,COLOR_MAXZONE,"[MaxZone]: {FFFFFF}You have been registered successfully!");
GivePlayerMoney(playerid,5000);
SetPlayerScore(playerid,100);
}
}
if(dialogid == LOGIN_DIALOG)
{
if(strlen(inputtext) == 0)
{
new string[256];
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
format(string,sizeof(string),"Bun venit %s!\n\nAcest cont este deja inregistrat.\n\nIntrodu parola.",pName);
ShowPlayerDialog(playerid,0,DIALOG_STYLE_INPUT,"{2788C4}L{A9C4E4}ogin",string,"Login","Cancel");
}
else
{
LoginPlayer(playerid,inputtext);
}
}
return 1;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}
stock LoginPlayer(playerid,const password[])
{
new EscapedText[60], string[256];
new Query[80];
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
mysql_real_escape_string(password, EscapedText);
mysql_format(connectionGG, Query, sizeof(Query),"SELECT * FROM `accounts` WHERE `Name` = '%s' AND `Password` = '%s'",GetPName(playerid),EscapedText);
mysql_query(connectionGG, Query);
mysql_store_result();
if(mysql_num_rows() != 0)
{
SendClientMessage(playerid,COLOR_MAXZONE,"[MaxZone]: {FFFFFF}You have been logged in!");
LoadStats(playerid);
}
else
{
SendClientMessage(playerid, COLOR_ERROR, "Ai introdus o parola gresita. Va rugam sa incercati din nou.");
format(string,sizeof(string),"Bun venit %s!\n\nAcest cont este deja inregistrat.\n\nIntrodu parola.",pName);
ShowPlayerDialog(playerid,0,DIALOG_STYLE_INPUT,"{2788C4}L{A9C4E4}ogin",string,"Login","Cancel");
}
mysql_free_result();
return 1;
}
stock LoadStats(playerid)
{
new pName[24],Query[80];
GetPlayerName(playerid,pName,24);
mysql_format(connectionGG, Query, sizeof(Query), "SELECT * FROM `accounts` WHERE `Name` = '%s' ", pName);
mysql_query(connectionGG, Query);
mysql_store_result();
mysql_fetch_row_format(Query, "|");
sscanf(Query, "e<p<|>s[24]s[23]i>", pInfo[playerid]);
mysql_free_result();
GivePlayerMoney(playerid,pInfo[playerid][Money]);
return 1;
}
stock GetPName(playerid)
{
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
return pName;
}