14.11.2015, 09:25
this "stock" for load database, in my opinioin.
And this for save database.
and i found this at mysql_log
Код:
stock MySQL_Login(playerid) { new query[300], pName[24], savingstring[20]; GetPlayerName(playerid, pName, 24); format(query, sizeof(query), "SELECT * FROM playerchar WHERE charname = '%s'", pName); mysql_query(query); mysql_store_result(); while(mysql_fetch_row_format(query,"|")) { mysql_fetch_field_row(savingstring, "level"); SetPlayerScore(playerid, strval(savingstring)); mysql_fetch_field_row(savingstring, "skin"); PlayerInfo[playerid][pSkin] = strval(savingstring); mysql_fetch_field_row(savingstring, "money"); MoneyGiven[playerid] = strval(savingstring); mysql_fetch_field_row(savingstring, "posx"); PlayerInfo[playerid][pPosX] = strval(savingstring); mysql_fetch_field_row(savingstring, "posy"); PlayerInfo[playerid][pPosY] = strval(savingstring); mysql_fetch_field_row(savingstring, "posz"); PlayerInfo[playerid][pPosZ] = strval(savingstring); mysql_fetch_field_row(savingstring, "posa"); PlayerInfo[playerid][pPosA] = strval(savingstring); mysql_fetch_field_row(savingstring, "logins"); PlayerInfo[playerid][pLogins] = strval(savingstring); mysql_fetch_field_row(savingstring, "gender"); PlayerInfo[playerid][pGender] = strval(savingstring); mysql_fetch_field_row(savingstring, "username"); PlayerInfo[playerid][pUname] = strval(savingstring); // this for load username mysql_fetch_field_row(savingstring, "admin"); PlayerInfo[playerid][pAdmin] = strval(savingstring); } JustLogged[playerid] = 1; Logged[playerid] = 1; PlayerInfo[playerid][pLogins]++; if(MoneyGiven[playerid] != -1) { GivePlayerMoney(playerid, MoneyGiven[playerid]); MoneyGiven[playerid] = -1; } format(query, sizeof(query), "SELECT logins FROM playerchar WHERE charname = '%s' AND logins='%i'", pName, 0); mysql_query(query); mysql_store_result(); new rows = mysql_num_rows(); if(!rows) { TogglePlayerSpectating(playerid, false); SetSpawnInfo(playerid, 0, PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ], PlayerInfo[playerid][pPosA], 0, 0, 0, 0, 0, 0 ); SpawnPlayer(playerid); new st[128]; format(st,128,"%s telah terkoneksi ke server IDRP!",GetName(playerid),GetName(playerid)); SendClientMessageToAll(0x33CCFFAA,st); new s[64]; format(s,64,"Selamat datang kembali! Semoga sehat selalu.",GetName(playerid)); SendClientMessage(playerid,0x33AA33AA,s); } else { ShowPlayerDialog(playerid, 15550, DIALOG_STYLE_LIST, "Sialhkan pilih mau dimana kamu mendarat!", "Stasiun Unity\nStasiun Market\nBandara Los Santos", "Oke", "Cancel"); } mysql_free_result(); return 1; }
Код:
stock SavePlayerAccount(playerid) { if(Logged[playerid] == 1) { new Float:x, Float:y, Float:z, Float:a; GetPlayerPos(playerid, x, y, z); GetPlayerFacingAngle(playerid, a); PlayerInfo[playerid][pPosX] = x; PlayerInfo[playerid][pPosY] = y; PlayerInfo[playerid][pPosZ] = z; PlayerInfo[playerid][pPosA] = a; PlayerInfo[playerid][pSkin] = GetPlayerSkin(playerid); new level = GetPlayerScore(playerid); new money = GetPlayerMoney(playerid); new query[300], pName[24], nquery[300]; GetPlayerName(playerid, pName, 24); format(query, sizeof(query), "UPDATE playerchar SET level='%d', money='%d' WHERE charname='%s'", level, money, pName); format(nquery, sizeof(nquery), "UPDATE playerchar SET username='%e', admin='%d', skin='%d', logins='%d', posx='%f', posy='%f', posz='%f', posa='%f' WHERE charname='%s'", PlayerInfo[playerid][pUname], // and this for save username PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pLogins], PlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ], PlayerInfo[playerid][pPosA], pName); mysql_query(query); mysql_query(nquery); } return 1; }
Код:
CMySQLHandler::Query(UPDATE playerchar SET username='e', admin='0', skin='0', logins='2', posx='0.000000', posy='1492.361206', posz='-1725.208374', posa='13.546875' WHERE charname='$') - Successfully executed.