#define mysql_host "YourHostIp"
#define mysql_user "YourMysqlUser"
#define mysql_password "YourUserPassword"
#define mysql_database "YourDatabaseName"
public OnGameModeInit()
{
mysql_connect(mysql_host,mysql_user,mysql_database ,mysql_password);
return 1;
}
public OnPlayerConnect(playerid)
{
new Query[80],pName[24],string[164];
GetPlayerName(playerid,pName,24);
format(Query,sizeof(Query),"SELECT `Username` FROM `Users` WHERE `Username` = '%s' LIMIT 1;",pName);
mysql_query(Query);
mysql_store_result();
return 1;
}
public OnPlayerConnect(playerid)
{
new Query[80],pName[24],string[164];
GetPlayerName(playerid,pName,24);
format(Query,sizeof(Query),"SELECT `Username` FROM `Users` WHERE `Username` = '%s' LIMIT 1;",pName);
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() != 0)//if number of rows is different from 0 then continue
{
format(string,sizeof(string),"Hey, %s! \nYour account is registered.\nPlease enter the password to log in!",pName);
ShowPlayerDialog(playerid,0,DIALOG_STYLE_INPUT,"Lo g in",string,"Login","");
}
else
{
format(string,sizeof(string),"Hey, %s! \nYour account is not registered. \nPlease register to continue!",pName);
ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Re gister",string,"Register","");
}
mysql_free_result();
return 1;
}
if(dialogid == 1)
{
if(strlen(inputtext) == 0)
{
ShowPlayerDialog(playerid,Regdialog,DIALOG_STYLE_I NPUT,"Register - Enter your password","You are about to register a new account! \nPlease choose the password"cblue" for it! \n","Register!","");
}
else
{
new EscapedText[60];
mysql_real_escape_string(inputtext, EscapedText);
format(Query,sizeof(Query),"INSERT INTO `Users` (Username,Password,Money) VALUES ('%s','%s,'0')",GetPName(playerid),EscapedText);
mysql_query(Query);
SendClientMessage(playerid,green,"You have been successfully registered!");
GivePlayerMoney(playerid,5000);
SetPlayerScore(playerid,100);
}
}
stock LoginPlayer(playerid,const password[])
{
new EscapedText[60];
mysql_real_escape_string(password, EscapedText);
format(Query,sizeof(Query),"SELECT * FROM `Users` WHERE `Username` = '%s' AND `Password` = '%s'",GetPName(playerid),EscapedText);
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() != 0)
{
SendClientMessage(playerid,green,"You have been logged in!");
LoadStats(playerid);
}
else
{
SendClientMessage(playerid,red,"Wrong password!");
Kick(playerid);
}
mysql_free_result();
return 1;
}
if(dialogid == Logindialog)
{
if(strlen(inputtext) == 0)
{
ShowPlayerDialog(playerid,Regdialog,DIALOG_STYLE_I NPUT,"Register - Enter your password","You are about to register a new account! \nPlease choose the password for it! \n","Register!","");
}
else
{
LoginPlayer(playerid,inputtext);
}
}
enum PlayerInfo
{
Username[23],
Password[24],
Money
}
new PInfo[MAX_PLAYERS][PlayerInfo]
stock LoadStats(playerid)
{
new pName[24],Query[80];
GetPlayerName(playerid,pName,24);
format(Query, sizeof(Query), "SELECT * FROM `Users` WHERE `Username` = '%s' ", pName);
mysql_query(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;
}
#define mysql_host "YourHostIp"
#define mysql_user "YourMysqlUser"
#define mysql_password "YourUserPassword"
#define mysql_database "YourDatabaseName"
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(21) : error 001: expected token: ";", but found "new"
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(52) : error 017: undefined symbol "GetPName"
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(57) : error 017: undefined symbol "green"
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(62) : error 017: undefined symbol "red"
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(63) : warning 217: loose indentation
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(50) : warning 204: symbol is assigned a value that is never used: "string"
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(76) : error 017: undefined symbol "sscanf"
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(104) : error 017: undefined symbol "string"
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(104) : error 017: undefined symbol "string"
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(104) : error 029: invalid expression, assumed zero
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(104) : fatal error 107: too many error messages on one line
Compilation aborted.Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
9 Errors.
new Query[200],pName[24];
GetPlayerName(playerid,pName,24);
format(Query,sizeof(Query),"SELECT `Username` = '%s' FROM `Users`",pName);
#include <a_samp>
#include <streamer>
#include <a_mysql>
#include <sscanf2>
#define mysql_host "YourHostIp"
#define mysql_user "YourMysqlUser"
#define mysql_password "YourUserPassword"
#define mysql_database "YourDatabaseName"
main()
{
printf("Hi");
}
enum PlayerInfo
{
Username[23],
Password[24],
Money
}
new PInfo[MAX_PLAYERS][PlayerInfo]
public OnGameModeInit()
{
mysql_connect(mysql_host,mysql_user,mysql_database,mysql_password);
SetGameModeText("Motel RP");
CreateDynamicObject(14783,2217.31860352,-1143.14697266,1023.42614746,0.00000000,0.00000000,358.00000000); //object(int3int_kbsgarage) (1)
CreateDynamicObject(14834,2214.42968750,-1155.06799316,1025.02209473,0.00000000,0.00000000,0.00000000); //object(lm_stripplant) (1)
CreateDynamicObject(977,2243.01464844,-1160.77770996,1029.68249512,0.00000000,0.00000000,101.75000000); //object(newtowerdoor1) (1)
CreateDynamicObject(977,2239.39501953,-1160.78808594,1029.68249512,0.00000000,0.00000000,101.74987793); //object(newtowerdoor1) (2)
CreateDynamicObject(977,2239.33544922,-1171.72338867,1029.68249512,0.00000000,0.00000000,101.74987793); //object(newtowerdoor1) (3)
CreateDynamicObject(977,2226.59301758,-1186.72668457,1030.40075684,0.00000000,0.00000000,191.74987793); //object(newtowerdoor1) (4)
CreateDynamicObject(977,2210.59814453,-1190.60839844,1030.40075684,0.00000000,0.00000000,191.74438477); //object(newtowerdoor1) (5)
CreateDynamicObject(977,2195.11621094,-1174.09912109,1030.30810547,0.00000000,0.00000000,101.24438477); //object(newtowerdoor1) (6)
CreateDynamicObject(977,2195.09887695,-1158.02233887,1030.30810547,0.00000000,0.00000000,101.23901367); //object(newtowerdoor1) (7)
CreateDynamicObject(977,2191.23999023,-1157.99169922,1030.30810547,0.00000000,0.00000000,101.23901367); //object(newtowerdoor1) (8)
CreateDynamicObject(1723,2217.68945312,-1155.00512695,1024.79687500,0.00000000,0.00000000,180.00000000); //object(mrk_seating1) (1)
CreateDynamicObject(1723,2219.15283203,-1152.37744141,1024.79687500,0.00000000,0.00000000,269.99450684); //object(mrk_seating1) (2)
CreateDynamicObject(1723,2215.73437500,-1152.02197266,1024.79687500,0.00000000,0.00000000,359.98901367); //object(mrk_seating1) (3)
CreateDynamicObject(2008,2215.69946289,-1144.85717773,1025.42248535,0.00000000,0.00000000,180.00000000); //object(officedesk1) (1)
CreateDynamicObject(2166,2215.11059570,-1140.28161621,1025.14624023,0.00000000,0.00000000,0.00000000); //object(med_office_desk_2) (1)
CreateDynamicObject(1670,2216.16308594,-1153.43225098,1025.35156250,0.00000000,0.00000000,0.00000000); //object(propcollecttable) (1)
CreateDynamicObject(18028,2240.63012695,-1154.72802734,1024.30493164,0.00000000,0.00000000,90.00000000); //object(smllbarinterior) (1)
CreateDynamicObject(14651,2241.39306641,-1163.84631348,1024.21655273,0.00000000,0.00000000,88.00000000); //object(trukstp05) (1)
return 1;
}
stock LoginPlayer(playerid,const password[])
{
new string[165],EscapedText[60];
new Query[200],pName[24];
GetPlayerName(playerid,pName,24);
mysql_real_escape_string(password, EscapedText);
format(Query,sizeof(Query),"SELECT * FROM `Users` WHERE `Username` = '%s' AND `Password` = '%s'",pName,EscapedText);
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() != 0)
{
SendClientMessage(playerid,green,"You have been logged in!");
LoadStats(playerid);
}
else
{
SendClientMessage(playerid,red,"Wrong password!");
Kick(playerid);
}
mysql_free_result();
return 1;
}
stock LoadStats(playerid)
{
new pName[24];
GetPlayerName(playerid,pName,24);
format(Query, sizeof(Query), "SELECT `Username` = '%s' FROM `Users`", pName);
mysql_query(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;
}
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 pName[24];
GetPlayerName(playerid,pName,24);
format(Query,sizeof(Query),"SELECT `Username` = '%s' FROM `Users`",pName);
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() != 0)//if number of rows is different from 0 then continue
{
format(string,sizeof(string),"Hey, %s! \nYour account is registered.\nPlease enter the password to log in!",pName);
ShowPlayerDialog(playerid,0,DIALOG_STYLE_INPUT,"Log in",string,"Login","");
}
else
{
format(string,sizeof(string),"Hey, %s! \nYour account is not registered. \nPlease register to continue!",pName);
ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Register",string,"Register","");
}
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)
{
new string[220];
if(strlen(inputtext) == 0)
{
ShowPlayerDialog(playerid,Regdialog,DIALOG_STYLE_INPUT,"Register - Enter your password","You are about to register a new account! \nPlease choose the password"cblue" for it! \n","Register!","");
}
else
{
new EscapedText[60];
mysql_real_escape_string(inputtext, EscapedText);
format(Query,sizeof(Query),"INSERT INTO `Users` (Username,Password,Money) VALUES ('%s','%s,'0')",GetPName(playerid),EscapedText);
mysql_query(Query);
SendClientMessage(playerid,green,"You have been successfully registered!");
GivePlayerMoney(playerid,5000);
SetPlayerScore(playerid,100);
}
}
if(dialogid == Logindialog)
{
if(strlen(inputtext) == 0)
{
ShowPlayerDialog(playerid,Regdialog,DIALOG_STYLE_INPUT,"Register - Enter your password","You are about to register a new account! \nPlease choose the password for it! \n","Register!","");
}
else
{
LoginPlayer(playerid,inputtext);
}
}
return 1;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(24) : error 001: expected token: ";", but found "public"
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(60) : error 017: undefined symbol "green"
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(65) : error 017: undefined symbol "red"
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(66) : warning 217: loose indentation
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(51) : warning 204: symbol is assigned a value that is never used: "string"
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(75) : error 017: undefined symbol "Query"
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(75) : error 017: undefined symbol "Query"
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(75) : error 029: invalid expression, assumed zero
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(75) : fatal error 107: too many error messages on one line
Compilation aborted.Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
7 Errors.
pawn Код:
|
I never knew that you could use a where clause in the selection for the column name. Maybe I learnt something new?
|
SELECT ColumnName FROM TableName WHERE ColumnName = value
SELECT columns, ... FROM tablename WHERE something = some value
SELECT column = some value FROM tablename
format(Query,sizeof(Query),"SELECT `Username` = '%s' FROM `Users` LIMIT 1;",pName);
format(Query,sizeof(Query),"SELECT * FROM `Users` WHERE `Username` = '%s'",pName);
public OnPlayerConnect(playerid) { new Query[80],pName[24]; GetPlayerName(playerid,pName,24); format(Query,sizeof(Query),"SELECT FROM `Users` WHERE `Username` = '%s' LIMIT 1;",pName); mysql_query(Query); mysql_store_result(); return 1; } |
hmmmmmmmmmmm
You Missed something U using string there in format and sending dialog , but u havent defined string so new string[128]; after line new Query[80],pName[24]; or as new Query[80],pName[24] , string[128]; :P I mentioned this cause some new ppl will get confused/o: []_[] ____ still nice tutorial |
format(Query,sizeof(Query),"SELECT FROM `Users` WHERE `Username` = '%s' LIMIT 1;",pName);
format(Query,sizeof(Query),"SELECT `Username` FROM `Users` WHERE `Username` = '%s' LIMIT 1",pName);
pawn Code:
pawn Code:
|