23.08.2010, 11:31
(
Последний раз редактировалось Bumbis; 23.08.2010 в 12:03.
)
Hi, all. So i want a little help from you, who knows something about MySQL. I tried to make some simple GM with MySQL database, i looked all tutorials and that stuff, but it didn't save, and it shows that i'm registred, but i'm not. I don't know where is problem, so i am asking for help here. My gamemode down here.
If someone isn't lazy, then please look at my script and tell me where is the problem or problems. I don't know almost anything about MySQL. Thanks. And, it didn't save anything i guess. Typed /reg [password], it showed that i was successfully registred and all that. But when i looked in database theres nothing.
pawn Код:
#include <a_samp>
//Gstyles include
#include <a_mysql>
#include <sscanf2>
//DCMD (Will be used for our register and login commands later in the tutorial
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
//The following information is only for our wamp server, when we are ready to upload it to our server for use you will need to change it
#define SQL_HOST "IP adress" //Standard wamp host
#define SQL_USER "root" //Standard wamp user
#define SQL_PASS "password" //Standard wamp password (Nothing)
#define SQL_DB "sa-mp" //This is the database we are going to use (I'll show you how to set it up later :) )
#define mysql_fetch_row(%1) mysql_fetch_row_format(%1,"|")
#include <zcmd>
//-------------COLORS---------------------------
#define COLOR_GRAD1 0xB4B5B7FF
#define COLOR_GRAD2 0xBFC0C2FF
#define COLOR_GRAD3 0xCBCCCEFF
#define COLOR_GRAD4 0xD8D8D8FF
#define COLOR_GRAD5 0xE3E3E3FF
#define COLOR_GRAD6 0xF0F0F0FF
#define COLOR_GREY 0xAFAFAFAA
#define INVALID_PLAYER_IDD 0xAFAFAFAA
#define COLOR_GREEN 0x9EC73DAA
#define COLOR_GROVE 0x00FF00FF
#define COLOR_RED 0xAA3333AA
#define COLOR_LIGHTRED 0xFF6347AA
#define COLOR_LIGHTBLUE 0x33CCFFAA
#define COLOR_LIGHTGREEN 0x9ACD32AA
#define COLOR_YELLOW 0xDABB3EAA
#define COLOR_YELLOW2 0xF5DEB3AA
#define COLOR_WHITE 0xFFFFFFAA
#define COLOR_FADE1 0xE6E6E6E6
#define COLOR_FADE2 0xC8C8C8C8
#define COLOR_FADE3 0xAAAAAAAA
#define COLOR_FADE4 0x8C8C8C8C
#define COLOR_FADE5 0x6E6E6E6E
#define COLOR_PURPLE 0x9459FEE7
#define COLOR_PURPLE2 0x9459FEFF
#define COLOR_DBLUE 0x2641FEAA
#define COLOR_ALLDEPT 0xFF8282AA
#define COLOR_NEWS 0x458E1DAA
#define COLOR_OOC 0xB1C8FBAA
#define TEAM_CYAN 1
#define TEAM_BLUE 2
#define TEAM_GREEN 3
#define TEAM_ORANGE 4
#define TEAM_COR 5
#define TEAM_BAR 6
#define TEAM_TAT 7
#define TEAM_CUN 8
#define TEAM_STR 9
#define TEAM_HIT 10
#define TEAM_ADMIN 11
#define OBJECTIVE_COLOR 0x64000064
#define TEAM_GREEN_COLOR 0xFFFFFFAA
#define TEAM_JOB_COLOR 0xFFB6C1AA
#define TEAM_HIT_COLOR 0xFFFFFF00
#define TEAM_BLUE_COLOR 0x8D8DFF00
#define TEAM_RADIO_COLOR 0xF2D068FF
#define COLOR_ADD 0x63FF60AA
#define TEAM_GROVE_COLOR 0x00D900C8
#define TEAM_VAGOS_COLOR 0xFFC801C8
#define TEAM_AZTECAS_COLOR 0x01FCFFC8
#define TEAM_CYAN_COLOR 0xFF8282AA
#define COLOR_INVIS 0xAFAFAF00
#define COLOR_SPEC 0xBFC0C200
#pragma tabsize 0
#define COLOR_BLUE 0x2641FEAA
#define COLOR_DARKNICERED 0x9D000096
#define COLOR_LIGHT_BLUE 0x9FB1EEAA
//-------------------[Forwards]------------------------
forward SaveStats(playerid);
forward SetPlayerSpawn(playerid);
//-----------------------------------------------------
main()
{
print("\n----------------------------------");
print("||-------[MySQL Testing]-----------||");
print("|||__|||_|||__|||__|||__|||__|||__|||");
print("___||___||___||___||___||___||___||__");
print("----------------------------------\n");
}
public OnGameModeInit()
{
DisableInteriorEnterExits();
SetNameTagDrawDistance(10.0);
AllowAdminTeleport(true);
SetGameModeText("MySQL test");
if(mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS))
{
print("MySQL veiksmigi iesledzas!");
}
else
{
print("MySQL neveiksmigi iesledzas!");
}
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 name[MAX_PLAYER_NAME];
new query[256];
GetPlayerName(playerid,name,sizeof(name));
format(query, sizeof(query), "SELECT * FROM 'users' WHERE 'name' = '%s'", name);
mysql_query(query);
mysql_store_result();
if(mysql_num_rows() != 0)
{
SendClientMessage(playerid, COLOR_YELLOW, "Sveicināts! Tu esi reģistrējies, lieto /login [parole]");
}
else
{
SendClientMessage(playerid, COLOR_YELLOW, "Sveicināts nGames! Tu neesi reģistrējies, lieto /register [parole]");
}
mysql_free_result();
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
if(GetPVarInt(playerid, "Logged") == 1)
{
new query[128];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name,sizeof(name));
format(query,sizeof(query), "UPDATE 'users' SET 'money' = '%d' WHERE 'name' = '%s'", GetPlayerMoney(playerid), name);
mysql_query(query);
mysql_free_result();
}
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 OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
if (strcmp("/help", cmdtext, true, 10) == 0)
{
SendClientMessage(playerid, COLOR_WHITE, "TEST");
return 1;
}
return success;
}
public OnPlayerCommandReceived(playerid, cmdtext[]) return 1;
CMD:money(playerid, params[])
{
new money;
new givep;
if(sscanf(params,"ui",givep,money)) SendClientMessage(playerid, COLOR_GREY, "Lietojums: /money [playerid][Nauda]");
else if(!IsPlayerConnected(givep)) return SendClientMessage(playerid, COLOR_GREY, "Nezināms ID");
else
{
GivePlayerMoney(givep,money);
SaveStats(playerid);
return 1;
}
return 1;
}
CMD:reg(playerid, params[])
{
new pass[128];
new query[200];
new name[MAX_PLAYER_NAME];
new string[256];
if(sscanf(params,"s",pass)) SendClientMessage(playerid, COLOR_GREY, "Lietojums: /register [parole]");
else
{
GetPlayerName(playerid, name,sizeof(name));
format(query,sizeof(query), "INSERT INTO 'users' ('name', 'money', 'password') VALUES ('%s',0,%s)",name,pass);
mysql_query(query);
format(string,sizeof(string),"Veiksmīgi reģistrējies! Parole: %s. Ielogojies ar /login [parole]!");
SendClientMessage(playerid, COLOR_YELLOW, string);
return 1;
}
return 1;
}
CMD:login(playerid, params[])
{
if(GetPVarInt(playerid, "Logged")==1)
{
new pass[80];
new query[200];
new name[MAX_PLAYER_NAME];
if(sscanf(params,"s",pass)) SendClientMessage(playerid, COLOR_GREY, "Lietojums: /login [parole]");
else
{
GetPlayerName(playerid, name,sizeof(name));
format(query,sizeof(query), "SELECT * FROM 'users' WHERE 'name' = '%s' AND 'password' = '%s'", name,pass);
mysql_query(query);
mysql_store_result();
if(!mysql_num_rows())
{
SendClientMessage(playerid, COLOR_GREEN,"Ievadītā parole nav pareiza!");
return 1;
}
else
{
new line[750];
if(mysql_fetch_row(line))
{
new data[2][50];
new data2[1];
sscanf(line,"p|sds",data[0],data2[0],data[1]);
SetPVarInt(playerid, "Logged",1);
SetPVarInt(playerid, "Money",data2[0]);
GivePlayerMoney(playerid,data2[0]);
SetPlayerSpawn(playerid);
mysql_free_result();
SendClientMessage(playerid, COLOR_YELLOW, "Veiksmigi ielogojies!");
return 1;
}
}
}
return 1;
}
else
{
SendClientMessage(playerid, COLOR_GREY, "Tu jau esi ielogojies!");
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[])
{
return 1;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}
public SaveStats(playerid)
{
if(GetPVarInt(playerid, "Logged") == 1)
{
new query[128];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name,sizeof(name));
format(query,sizeof(query), "UPDATE 'users' SET 'money' = '%d' WHERE 'name' = '%d'",GetPlayerMoney(playerid),name);
mysql_query(query);
mysql_free_result();
return 1;
}
return 1;
}
public SetPlayerSpawn(playerid)
{
if(IsPlayerConnected(playerid))
{
if(GetPlayerSkin(playerid)==1)
{
SetPlayerInterior(playerid, 0);
SetPlayerPos(playerid, 1257.5063,-785.3929,92.0302);
}
else
{
SetPlayerPos(playerid,-1971.9481,146.7149,27.6875);
SetPlayerFacingAngle(playerid, 0);
SetPlayerInterior(playerid,0);
}
}
return 1;
}