Can't spawn -
saffierr - 27.09.2015
I can't spawn after I register...
PHP код:
enum PlayerData
{
ID,
Name[MAX_PLAYER_NAME],
Password[35],
IP[20],
Admin,
VIP,
Money,
Float:posX,
Float:posY,
Float:posZ,
Float:posA,
}
new Player[MAX_PLAYERS][PlayerData];
PHP код:
#define mysql_host "localhost"
#define mysql_user "root"
#define mysql_password ""
#define mysql_db "xg"
#define SPAWN_X 10.0
#define SPAWN_Y 10.0
#define SPAWN_Z 14.0
#define SPAWN_A 0.0
#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
PHP код:
public OnGameModeInit()
{
// MySQL
mysql_log(LOG_ALL);
mysql = mysql_connect(mysql_host, mysql_user, mysql_db, mysql_password);
if(mysql_errno() != 0)
{
printf("[MySQL] The connection is failed");
}
else
{
printf("[MySQL] The connection is succesfull");
}
PHP код:
forward OnAccountCheck(playerid);
public OnAccountCheck(playerid)
{
new rows, fields;
cache_get_data(rows, fields, mysql);
if(rows)
{
cache_get_field_content(0, "Password", Player[playerid][Password], mysql, 35);
Player[playerid][ID] = cache_get_field_content_int(0, "ID");
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login Xtreme Gaming", "Enter your password to login.", "Login", "Leave");
}
else
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register to Xtreme Gaming", "Fill in a password to create a account.", "Register", "Leave");
}
return 1;
}
PHP код:
forward OnAccountLoad(playerid);
public OnAccountLoad(playerid)
{
Player[playerid][Admin] = cache_get_field_content_int(0, "Admin");
Player[playerid][VIP] = cache_get_field_content_int(0, "VIP");
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");
TogglePlayerSpectating(playerid, 0);
GivePlayerMoney(playerid, Player[playerid][Money]);
SetSpawnInfo(playerid, 0, 23, Player[playerid][posX], Player[playerid][posY], Player[playerid][posZ], Player[playerid][posA], 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
SendClientMessage(playerid, COLOR_WHITE, "Your account has been restored!");
return 1;
}
PHP код:
forward OnAccountRegister(playerid);
public OnAccountRegister(playerid)
{
Player[playerid][ID] = cache_insert_id(mysql);
printf("[Registration] New account has been registered. Database ID: [%d]", Player[playerid][ID]);
TogglePlayerSpectating(playerid, 0);
SetSpawnInfo(playerid, 0, 23, SPAWN_X, SPAWN_Y, SPAWN_Z, SPAWN_A, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
new string[75], pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
format(string, sizeof string, "%s has been succesfully registered to the server!", pName);
SendClientMessageToAll(COLOR_GREEN, string);
return 1;
}
PHP код:
public OnPlayerConnect(playerid)
{
// MySQL Login / Register
TogglePlayerSpectating(playerid, true);
new query[128], pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
mysql_format(mysql, query, sizeof query, "SELECT `Password`, `ID`, FROM `accounts` WHERE `Name` = `%e` LIMIT 1", pName);
mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
OnAccountCheck(playerid);
PHP код:
public OnPlayerDisconnect(playerid, reason)
{
new query[129], Float:pos[4];
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
GetPlayerFacingAngle(playerid, pos[3]);
mysql_format(mysql, query, sizeof query, "UPDATE `accounts` SET `Money` = `%d`, `PosX` = `%f`, `PosY` = `%f`, `PosZ` = `%f`, `PosA` = `%f` WHERE `ID` = %d", GetPlayerMoney(playerid), pos[0], pos[1], pos[2], pos[3], Player[playerid][ID]);
mysql_tquery(mysql, query, "", "");
PHP код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid==DIALOG_LOGIN)
{
if(!response) Kick(playerid);
{
new hashpass[35], query[129], pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
WP_Hash(hashpass, sizeof hashpass, inputtext);
if(!strcmp(hashpass, Player[playerid][Password]))
{
mysql_format(mysql, query, sizeof query, "SELECT * FROM `accounts` WHERE `Name` = `%e` LIMIT 1", pName);
mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
}
else
{
SendClientMessage(playerid, COLOR_RED, "Error: Incorrect password!");
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login Xtreme Gaming", "Enter your password to login.", "Login", "Leave");
}
}
}
if(dialogid==DIALOG_REGISTER)
{
if(!response) Kick(playerid);
if(strlen(inputtext) < 3)
{
SendClientMessage(playerid, COLOR_RED, "Error: Create a password with atleast 3 characters!");
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register Xtreme Gaming", "Create a password to register.", "Register", "Leave");
}
new query[129], pName[MAX_PLAYER_NAME], playerip[20];
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
GetPlayerIp(playerid, playerip, sizeof(playerip));
WP_Hash(Player[playerid][Password], 35, inputtext);
mysql_format(mysql, query, sizeof query, "INSERT INTO 'accounts' (`Name`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `PosX`, `PosY`, `PosZ`, `PosA') VALUES (`%e`, `%e`, `%e`, `0`, `0`, `0`, `%f`, `%f`, `%f`, `%f`", pName, Player[playerid][Password], playerip, SPAWN_X, SPAWN_Y, SPAWN_Z, SPAWN_A);
mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
}
Conclusion: 1 - The registered account does not save in the database.
2 - After entering a password I cannot spawn.
Rep+
Re: Can't spawn -
Jefff - 27.09.2015
1. If you are using %s or %e it must be in ' ' so '%e'
2. In register is "OnAccountCheck" should be "OnAccountRegister"
Re: Can't spawn -
saffierr - 27.09.2015
How am I supposed to do that? Since I took this from a tutorial and new to mysql?
Help would be appreciated.