29.03.2014, 10:47
I have set everything correctly but it still showing thins...
Error:
CODE:
With best regards Scrillex.
Error:
pawn Код:
[06:43:04] [DEBUG] mysql_format - connection: 1, len: 1200, format: "SELECT `Password`, `ID` FROM `playerdata` WHERE `Username` = '%e' LIMIT 1"
[06:43:04] [DEBUG] mysql_tquery - connection: 1, query: "SELECT `Password`, `ID` FROM `playerdata` WHERE `Username` = 'Ja", callback: "OnAccountCheck", format: "i"
[06:43:04] [DEBUG] CMySQLQuery::Execute[OnAccountCheck] - starting query execution
[06:43:04] [DEBUG] CMySQLQuery::Execute[OnAccountCheck] - query was successfully executed within 3.142 milliseconds
[06:43:04] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[06:43:04] [DEBUG] Calling callback "OnAccountCheck"..
[06:43:04] [DEBUG] cache_get_data - connection: 1
[06:43:04] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[06:43:18] [DEBUG] mysql_format - connection: 1, len: 1200, format: "INSERT INTO `playerdata` (`Username`, `Password`, `IP`, `Admin`, `VIP`, `Level`, `Rank`, `Groupid`, `PosX` ,`PosY`, `PosZ`, `Hou..."
[06:43:18] [DEBUG] mysql_tquery - connection: 1, query: "INSERT INTO `playerdata` (`Username`, `Password`, `IP`, `Admin`,", callback: "OnAccountRegister", format: "i"
[06:43:18] [DEBUG] CMySQLQuery::Execute[OnAccountRegister] - starting query execution
[06:43:18] [DEBUG] CMySQLQuery::Execute[OnAccountRegister] - query was successfully executed within 76.351 milliseconds
[06:43:18] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[06:43:18] [DEBUG] Calling callback "OnAccountRegister"..
[06:43:18] [DEBUG] cache_insert_id - connection: 1
[06:43:18] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[06:43:37] [DEBUG] mysql_format - connection: 1, len: 1200, format: "UPDATE `playerdata` SET `Admin`=%d, `VIP`=%d, `Level`=%d, `Rank`=%d,`Group`=%d, `posX`=%f, `posY`=%f, `posZ`=%f, `Hours`=%d, `Mi..."
[06:43:37] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE `playerdata` SET `Admin`=0, `VIP`=0, `Level`=0, `Rank`=11", callback: "(null)", format: "(null)"
[06:43:37] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[06:43:37] [ERROR] CMySQLQuery::Execute[] - (error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `ID`=0' at line 1
CODE:
pawn Код:
#include <a_samp>
#include <a_mysql>
#include <zcmd>
#include <sscanf2>
#include <streamer>
//Defines
#define host "localhost" //This will be your mysql host. Default for xampp is localhost
#define user "root" //This will be your mysql username. Default for xampp is root
#define db "roleplay" //This is your database name. Remember we have created a database called server before.
#define pass "" //This is your mysql password. In xampp, the password didn't set. So leave it empty.
//Defines
//dialogs
#define dregister 1 //dialog register id
#define dlogin 2 // ^
//dialogs
//statics
static
mysql, //This variable will be used to manage our database
Name[MAX_PLAYERS][24], //We will use this variable to store player's name.
IP[MAX_PLAYERS][16] //We will use this variable to store player's ip.
;
//statics
native WP_Hash(buffer[], len, const str[]);
//Enums
enum PDATA //We name our enumerator as PDATA (which stands for PlayerDATA). You can name it however you want.
{
ID, //Will be used later to store player's ID from database so we can use it anywhere later
Password[129], //We will load player's password into this varible from database
Admin, //We will load player's admin level from database into this variable so we can use it anywhere later.
VIP,
Level,
Groupid,
Rank,
Money, //We will load player's money from database into this variable so we can use it anywhere later.
Float:posX, //We will load player's X position from database into this variable so we can use it anywhere later.
Float:posY, //We will load player's Y position from database into this variable so we can use it anywhere later.
Float:posZ, //We will load player's Z from database into this variable so we can use it anywhere later.
Hours,
Minutes,
Respect,
StreetRespect,
PhoneNummber,
}
new pInfo[MAX_PLAYERS][PDATA ];
main()
{
print("\n----------------------------------");
print(" Blank Gamemode by your name here");
print("----------------------------------\n");
}
public OnGameModeInit()
{
// Don't use these lines if it's a filterscript
SetGameModeText("Blank Script");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
mysql_log(LOG_ERROR | LOG_WARNING | LOG_DEBUG); //Let's enable debugging so we can detect a problem(if there is)
mysql = mysql_connect(host, user, db, pass); //This function will connect your server to database. Remember we have defined our host, username, database and password. It's time to use it here.
if(mysql_errno(mysql) != 0) print("Could not connect to database!");
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)
{
new query[1200];
GetPlayerName(playerid, Name[playerid], 24);
GetPlayerIp(playerid, IP[playerid], 16);
mysql_format(mysql, query, sizeof(query),"SELECT `Password`, `ID` FROM `playerdata` WHERE `Username` = '%e' LIMIT 1", Name[playerid]);
mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
new query[1200], Float:pos[3];
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
mysql_format(mysql, query, sizeof(query), "UPDATE `playerdata` SET `Admin`=%d, `VIP`=%d, `Level`=%d, `Rank`=%d,\
`Group`=%d, `posX`=%f, `posY`=%f, `posZ`=%f, `Hours`=%d, `Minutes`=%d, `Respect`=%d, `StreetRespect`=%d,\
`PhoneNummber`=%d, `Money`=%d, WHERE `ID`=%d",\
pInfo[playerid][Admin], pInfo[playerid][VIP], pInfo[playerid][Money], pos[0], pos[1], pos[2],
pInfo[playerid][Rank], pInfo[playerid][Groupid], pInfo[playerid][posX], pInfo[playerid][posY],
pInfo[playerid][posZ], pInfo[playerid][Hours], pInfo[playerid][Minutes],pInfo[playerid][Respect],
pInfo[playerid][StreetRespect], pInfo[playerid][PhoneNummber], pInfo[playerid][ID]);
mysql_tquery(mysql, query, "", "");
return 1;
}
public OnPlayerSpawn(playerid)
{
SetPlayerPos(playerid, pInfo[playerid][posX], pInfo[playerid][posZ], pInfo[playerid][posZ]);
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 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[])
{
switch(dialogid)
{
case dlogin:
{
if(!response) Kick(playerid);
new hpass[129];
new query[1200];
WP_Hash(hpass, 129, inputtext);
if(!strcmp(hpass, pInfo[playerid][Password]))
{
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `playerdata` WHERE `Username` = '%e' LIMIT 1", Name[playerid]);
mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid);
}
else
{
ShowPlayerDialog(playerid, dlogin, DIALOG_STYLE_INPUT, "Login", "In order to play, you need to login\nWrong password!", "Login", "Quit");
}
}
case dregister:
{
if(!response) return Kick(playerid);
if(strlen(inputtext) < 6) return ShowPlayerDialog(playerid, dregister, DIALOG_STYLE_INPUT, "Register", "In order to play, you need to register.\nYour password must be at least 6 characters long!", "Register", "Quit");
new query[1200];
WP_Hash(pInfo[playerid][Password], 129, inputtext);
mysql_format(mysql, query, sizeof(query), "INSERT INTO `playerdata` (`Username`, `Password`, `IP`, `Admin`, `VIP`, `Level`, `Rank`, `Groupid`, `PosX` ,`PosY`, `PosZ`, `Hours`, `Minutes`, `Respect`, `StreetRespect`, `PhoneNummber`, `Money` ) VALUES ('%e', '%s', '%s', 0, 0, 0, 0, 0, 0.0, 0.0, 0.0, 0, 0, 0, 0, 0, 0)", Name[playerid], pInfo[playerid][Password], IP[playerid]);
mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid);
}
}
return 1;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}
//Publics
forward OnAccountCheck(playerid);
public OnAccountCheck(playerid)
{
new rows, fields; //a variable that will be used to retrieve rows and fields in the database.
cache_get_data(rows, fields, mysql);//let's get the rows and fields from the database.
if(rows) //if there is row
{//then
cache_get_field_content(0, "PASS", pInfo[playerid][Password], mysql, 129);
pInfo[playerid][ID] = cache_get_field_content_int(0, "ID");
printf("%s", pInfo[playerid][Password]);
ShowPlayerDialog(playerid, dlogin, DIALOG_STYLE_INPUT, "Login", "In order to play, you need to login", "Login", "Quit"); //And since we found a result from the database, which means, there is an account; we will show a login dialog
}
else
{
ShowPlayerDialog(playerid, dregister, DIALOG_STYLE_INPUT, "Register", "In order to play, you need to register.", "Register", "Quit");
}
return 1;
}
forward OnAccountLoad(playerid);
forward OnAccountRegister(playerid);
//let's load player's information
public OnAccountLoad(playerid)
{
pInfo[playerid][Admin] = cache_get_field_content_int(0, "Admin"); //we're getting a field 4 from row 0. And since it's an integer, we use cache_get_row_int
pInfo[playerid][VIP] = cache_get_field_content_int(0, "VIP"); //Above
pInfo[playerid][Level] = cache_get_field_content_int(0, "Level");
pInfo[playerid][Rank] = cache_get_field_content_int(0, "Rank");
pInfo[playerid][Groupid] = cache_get_field_content_int(0, "Group");
pInfo[playerid][posX] = cache_get_field_content_float(0, "PosX");//Above. Since player's position is a float, we use cache_get_field_content_float
pInfo[playerid][posY] = cache_get_field_content_float(0, "PosY");//Above
pInfo[playerid][posZ] = cache_get_field_content_float(0, "PosZ");//Above
pInfo[playerid][Hours] = cache_get_field_content_int(0, "Hours");
pInfo[playerid][Minutes] = cache_get_field_content_int(0, "Minutes");
pInfo[playerid][Respect] = cache_get_field_content_int(0, "Respect");
pInfo[playerid][StreetRespect] = cache_get_field_content_int(0, "StreetRespect");
pInfo[playerid][PhoneNummber] = cache_get_field_content_int(0, "PhoneNummber");
pInfo[playerid][Money] = cache_get_field_content_int(0, "Money");//Above
GivePlayerMoney(playerid, pInfo[playerid][Money]);
SendClientMessage(playerid, -1, "Successfully logged in"); //tell them that they have successfully logged in
return 1;
}
public OnAccountRegister(playerid)
{
pInfo[playerid][ID] = cache_insert_id(); //loads the ID of the player in the variable once they registered.
printf("New account registered. ID: %d", pInfo[playerid][ID]); //just for debugging.
return 1;
}
//Publics