Zmiana zapisu nVault na SQL - CODMOD
wacho
15.09.2017
Cześć,
zmieniam zapis z nVault na SQL w codmodzie (Przekładam zapis od R3X ) i napotkałem sie z pewna przeszkodą.
Mianowicie tworzą mi sie tylko 2 tabelki zamiast 3.
if(!gTuple){ gTuple = loadConnectionTuple(); return; } new error, szError[128]; new Handle:hConn = SQL_Connect(gTuple, error, szError, 127); if(error){ log_amx("Error: %s", szError); return; } new Handle:query; query = SQL_PrepareQuery(hConn, "CREATE TABLE IF NOT EXISTS `players`( \ pid INT UNSIGNED AUTO_INCREMENT, \ name VARCHAR(32) NOT NULL, \ steamid VARCHAR(32) NOT NULL, \ ip VARCHAR(32) NOT NULL, \ PRIMARY KEY(pid) \ )"); SQL_Execute(query); SQL_FreeHandle(query); query = SQL_PrepareQuery(hConn, "CREATE TABLE IF NOT EXISTS `classes`( \ cid INT UNSIGNED AUTO_INCREMENT, \ name VARCHAR(32), \ PRIMARY KEY(cid) \ )"); SQL_Execute(query); SQL_FreeHandle(query); copy(gszQuery, charsmax(gszQuery), "CREATE TABLE IF NOT EXISTS `player_data`( \ pid INT UNSIGNED NOT NULL, \ cid INT UNSIGNED NOT NULL, \ xp INT UNSIGNED NOT NULL DEFAULT 0, \ level INT UNSIGNED NOT NULL DEFAULT 1, \ PRIMARY KEY(pid, cid), "); add(gszQuery, charsmax(gszQuery), "intelligence INT UNSIGNED NOT NULL DEFAULT 0, \ health INT UNSIGNED NOT NULL DEFAULT 0, \ strength INT UNSIGNED NOT NULL DEFAULT 0, \ stamina INT UNSIGNED NOT NULL DEFAULT 0, \ dmg INT UNSIGNED NOT NULL DEFAULT 0, \ exp INT UNSIGNED NOT NULL DEFAULT 0, \ kasa INT UNSIGNED NOT NULL DEFAULT 0, \ kryt INT UNSIGNED NOT NULL DEFAULT 0, \ rege INT UNSIGNED NOT NULL DEFAULT 0, \ grav INT UNSIGNED NOT NULL DEFAULT 0, "); add(gszQuery, charsmax(gszQuery), "INDEX (pid), \ FOREIGN KEY (pid) \ REFERENCES `players`(pid) \ ON UPDATE CASCADE \ ON DELETE CASCADE, \ INDEX (cid), \ FOREIGN KEY (cid) \ REFERENCES `classes`(cid) \ ON UPDATE CASCADE \ ON DELETE CASCADE \ )"); query = SQL_PrepareQuery(hConn, gszQuery); SQL_Execute(query); SQL_FreeHandle(query); SQL_FreeHandle(hConn); //Mass cids load SQL_ThreadQuery(gTuple, "handleSelectClasses", "SELECT * FROM `classes`"); } stock SQL_PrepareString(const szQuery[], szOutPut[], size){ copy(szOutPut, size, szQuery); replace_all(szOutPut, size, "'", "\'"); replace_all(szOutPut,size, "`", "\`"); } stock SQL_FormatQuery(const szQuery[], ...){ vformat(gszQuery, charsmax(gszQuery), szQuery, 2); } Handle:loadConnectionTuple(){ static szFile[196]; get_configsdir(szFile, 195); add(szFile, 195, "/cod-mysql.ini"); new szHost[32] = "localhost"; new szUser[32] = "root"; new szPass[32] = "root" new szDB[32] = "codmod"; new szKey[32]; new fp = fopen(szFile, "rt"); if(fp) while(!feof(fp)){ fgets(fp, szFile, 195); trim(szFile); if(szFile[0] == ';') continue; parse(szFile, szKey, 31, szFile, 64); trim(szKey); trim(szFile); if(equali(szKey, "host")) copy(szHost, 31, szFile); else if(equali(szKey, "user")) copy(szUser, 31, szFile); else if(equali(szKey, "pass")) copy(szPass, 31, szFile); else if(equali(szKey, "db")) copy(szDB, 31, szFile); } return SQL_MakeDbTuple(szHost, szUser, szPass, szDB);
Nie powstaje tabelka player_data chyba że usune nowe statystyki wtedy owszem powstaje lecz jest pusta tylko tabela sie tworzy.
Czy ma ktoś jakiś pomysł ?
wacho
15.09.2017
SQL_FormatQuery("UPDATE `player_data` SET xp=%d, level=%d, intelligence=%d, health=%d, strength=%d, stamina=%d, dmg=%d, exp=%d, kasa=%d, kryt=%d, rege=%d, grav=%d WHERE pid=%d && cid=%d", doswiadczenie_gracza[id], poziom_gracza[id], inteligencja_gracza[id], zdrowie_gracza[id], wytrzymalosc_gracza[id], kondycja_gracza[id], obrazenia_gracza[id], wiecej_expa_gracza[id], wiecej_monet_gracza[id], szansa_gracza[id], regeneracjap_gracza[id], grawitacja_gracza[id], PID[id], cid_klas[klasa_gracza[id]]);
Taki ale to do UPDATE , przy CREATE jest:
copy(gszQuery, charsmax(gszQuery), "CREATE TABLE IF NOT EXISTS `player_data`( \ pid INT UNSIGNED NOT NULL, \ cid INT UNSIGNED NOT NULL, \ xp INT UNSIGNED NOT NULL DEFAULT 0, \ level INT UNSIGNED NOT NULL DEFAULT 1, \ PRIMARY KEY(pid, cid), "); add(gszQuery, charsmax(gszQuery), "intelligence INT UNSIGNED NOT NULL DEFAULT 0, \ health INT UNSIGNED NOT NULL DEFAULT 0, \ strength INT UNSIGNED NOT NULL DEFAULT 0, \ stamina INT UNSIGNED NOT NULL DEFAULT 0, \ dmg INT UNSIGNED NOT NULL DEFAULT 0, \ exp INT UNSIGNED NOT NULL DEFAULT 0, \ kasa INT UNSIGNED NOT NULL DEFAULT 0, \ kryt INT UNSIGNED NOT NULL DEFAULT 0, \ rege INT UNSIGNED NOT NULL DEFAULT 0, \ grav INT UNSIGNED NOT NULL DEFAULT 0, "); add(gszQuery, charsmax(gszQuery), "INDEX (pid), \ FOREIGN KEY (pid) \ REFERENCES `players`(pid) \ ON UPDATE CASCADE \ ON DELETE CASCADE, \ INDEX (cid), \ FOREIGN KEY (cid) \ REFERENCES `classes`(cid) \ ON UPDATE CASCADE \ ON DELETE CASCADE \ )");