Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.11 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <fakemeta>
  4. #include <fakemeta_util>
  5. #include <hamsandwich>
  6. #include <engine>
  7. #include <cstrike>
  8. #include <sqlx>
  9.  
  10. #define PLUGIN "Weapon DB"
  11. #define VERSION "#1.0"
  12. #define AUTHOR "ko2"
  13.  
  14. #define MYTASK 100
  15. #define ID_MYTASK (taskid - MYTASK)
  16.  
  17. #define is_valid_weapon(%1,%2) ((pev(%1, pev_impulse)) == %2)
  18.  
  19. new Handle:g_hDBTuple;
  20. new cvar_dbHost, cvar_dbUser, cvar_dbPass, cvar_dbName, cvar_roundActive;
  21. new const g_wModel[30][] =
  22. {
  23. "p228",
  24. "shield",
  25. "scout",
  26. "hegren",
  27. "xm1014",
  28. "c4",
  29. "mac10",
  30. "aug",
  31. "sgren",
  32. "elites",
  33. "fn57",
  34. "ump45",
  35. "sg550",
  36. "galil",
  37. "famas",
  38. "usp",
  39. "glock",
  40. "awp",
  41. "mp5",
  42. "m249",
  43. "m3",
  44. "m4a1",
  45. "tmp",
  46. "g3sg1",
  47. "flash",
  48. "deagle",
  49. "sg552",
  50. "ak47",
  51. "knife",
  52. "p90"
  53. }
  54.  
  55. new const g_wName[30][] =
  56. {
  57. "weapon_p228",
  58. "weapon_shield",
  59. "weapon_scout",
  60. "weapon_hegrenade",
  61. "weapon_xm1014",
  62. "weapon_c4",
  63. "weapon_mac10",
  64. "weapon_aug",
  65. "weapon_smokegrenade",
  66. "weapon_elite",
  67. "weapon_fiveseven",
  68. "weapon_ump45",
  69. "weapon_sg550",
  70. "weapon_galil",
  71. "weapon_famas",
  72. "weapon_usp",
  73. "weapon_glock18",
  74. "weapon_awp",
  75. "weapon_mp5navy",
  76. "weapon_m249",
  77. "weapon_m3",
  78. "weapon_m4a1",
  79. "weapon_tmp",
  80. "weapon_g3sg1",
  81. "weapon_flashbang",
  82. "weapon_deagle",
  83. "weapon_sg552",
  84. "weapon_ak47",
  85. "weapon_knife",
  86. "weapon_p90"
  87. };
  88.  
  89. stock const g_MaxAmmo[CSW_P90+1] = {
  90. -1, 52, -1, 90, -1, 32, 0, 100, 90, 0, 120,
  91. 100, 100, 90, 90, 90, 100, 120, 30, 120, 200,
  92. 32, 90, 120, 90, -1, 35, 90, 90, -1, 100}
  93.  
  94. enum Data
  95. {
  96. ID_REL,
  97. WEAPON_NAME[32],
  98. MODEL_ID,
  99. WEAPON_ID,
  100. POWER,
  101. KEY,
  102. MESSAGE[128]
  103. }
  104.  
  105. enum Model
  106. {
  107. ID,
  108. MODEL_P[32],
  109. MODEL_V[32],
  110. MODEL_W[32],
  111. }
  112.  
  113. new g_weaponRelationCount;
  114. new g_weaponRelation[1024][Data];
  115.  
  116. new g_weaponModelCount;
  117. new g_weaponModel[1024][Model];
  118.  
  119. enum User
  120. {
  121. NAME[32],
  122. ID_WR,
  123. HP,
  124. ARMOR
  125. }
  126.  
  127. new g_User[32][User]
  128.  
  129. new Array:weapon_id;
  130. new Array:model_id;
  131. new g_maxUser;
  132. new countRound;
  133.  
  134. public plugin_init()
  135. {
  136. register_plugin(PLUGIN, VERSION, AUTHOR);
  137. new item;
  138. g_maxUser = get_maxplayers();
  139. register_forward(FM_SetModel, "Fakemeta_SetModel");
  140. for(new i = 0; i < sizeof(weapon_id); i++)
  141. {
  142. item = ArrayGetCell(weapon_id, i);
  143. RegisterHam(Ham_Item_Deploy, g_wName[item-1], "ham_item_deploy_post", 1);
  144. RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage");
  145. }
  146. RegisterHam(Ham_Spawn, "player", "player_respawn", 1)
  147. register_event("HLTV", "event_new_round", "a", "1=0", "2=0")
  148. register_clcmd("say /get", "cmdGive")
  149. }
  150.  
  151. public event_new_round()
  152. {
  153. countRound++;
  154. }
  155.  
  156. public player_respawn(id)
  157. {
  158. if(g_User[id - 1][HP] != 0) fm_set_user_health(id, g_User[id - 1][HP])
  159. if(g_User[id - 1][ARMOR] != 0) cs_set_user_armor(id, g_User[id - 1][ARMOR], CS_ARMOR_KEVLAR);
  160. }
  161.  
  162. public cmdGive(id)
  163. {
  164. if(countRound < get_pcvar_num(cvar_roundActive))
  165. {
  166. client_print(id, print_chat, "Команда будет доступна через %d раунда(-ов)", get_pcvar_num(cvar_roundActive) - countRound);
  167. return PLUGIN_HANDLED;
  168. }
  169. new name[32];
  170. get_user_name(id, name, 31)
  171. for(new i = 0; i < g_maxUser; i++)
  172. {
  173. if(is_user_alive(i + 1))
  174. if(equal(g_User[i][NAME], name))
  175. if(g_User[i][ID_WR])
  176. for(new j = 0; j < g_weaponRelationCount; j++)
  177. {
  178. if(g_User[i][ID_WR] == g_weaponRelation[j][ID_REL])
  179. {
  180. static item;
  181. item = g_weaponRelation[j][WEAPON_ID];
  182. give_weapon(id, g_weaponRelation[j][KEY], g_wName[item-1]);
  183. cs_set_user_bpammo(id, item, g_MaxAmmo[item]);
  184. if(g_weaponRelation[j][MESSAGE][0]) client_print(id, print_chat, "%s", g_weaponRelation[j][MESSAGE]);
  185. }
  186. }
  187. }
  188. return PLUGIN_HANDLED
  189. }
  190.  
  191. public fw_TakeDamage ( victim, weapon, attacker, Float:damage, damagebits )
  192. {
  193. if (!is_user_alive(attacker) || !is_user_alive(victim)) return HAM_IGNORED;
  194. static weapon_ent;
  195. weapon_ent = get_pdata_cbase(attacker, 373, 5);
  196. for(new w = 0; w < g_weaponRelationCount; w++)
  197. {
  198. if(is_valid_weapon(weapon_ent, g_weaponRelation[w][KEY]))
  199. {
  200. SetHamParamFloat(4, damage * g_weaponRelation[w][POWER] / 100)
  201. return HAM_IGNORED;
  202. }
  203. }
  204. return HAM_IGNORED;
  205. }
  206.  
  207. // модель в руках у человека
  208. public ham_item_deploy_post(weapon_ent)
  209. {
  210. if(!pev_valid(weapon_ent)) return;
  211. static id;
  212. id = get_pdata_cbase(weapon_ent, 41, 4);
  213. if(!is_user_connected(id)) return;
  214. new name[32];
  215. get_user_name(id, name, 31);
  216. for(new w = 0; w < g_weaponRelationCount; w++)
  217. {
  218. if(is_valid_weapon(weapon_ent, g_weaponRelation[w][KEY]))
  219. for(new z = 0; z < g_maxUser; z++)
  220. {
  221. if(is_user_alive(z + 1))
  222. if(g_User[z][ID_WR])
  223. if(equal(g_User[z][NAME], name))
  224. {
  225. if(g_weaponRelation[w][ID_REL] == g_User[z][ID_WR])
  226. {
  227. for(new j = 0; j < g_weaponModelCount; j++)
  228. {
  229. if(g_weaponModel[j][ID] == g_weaponRelation[w][MODEL_ID])
  230. {
  231. set_pev(id, pev_viewmodel2, g_weaponModel[j][MODEL_V]);
  232. set_pev(id, pev_weaponmodel2, g_weaponModel[j][MODEL_P]);
  233. }
  234. }
  235. }
  236. }
  237. }
  238. if(is_valid_weapon(weapon_ent, g_weaponRelation[w][KEY]))
  239. {
  240. for(new j = 0; j < g_weaponModelCount; j++)
  241. {
  242. if(g_weaponModel[j][ID] == g_weaponRelation[w][MODEL_ID])
  243. {
  244. set_pev(id, pev_viewmodel2, g_weaponModel[j][MODEL_V]);
  245. set_pev(id, pev_weaponmodel2, g_weaponModel[j][MODEL_P]);
  246. }
  247. }
  248. }
  249. }
  250. }
  251.  
  252. public plugin_precache()
  253. {
  254. new file[128];
  255. new szError[64];
  256. new iErrorCode;
  257. new szHost[32], szUser[32], szPass[32], szDBname[32];
  258.  
  259. cvar_dbHost = register_cvar("weapon_dbHost", "localhost");
  260. cvar_dbUser = register_cvar("weapon_dbUser", "root");
  261. cvar_dbPass = register_cvar("weapon_dbPass", "");
  262. cvar_dbName = register_cvar("weapon_dbName", "weapon_db");
  263. cvar_roundActive = register_cvar("weapon_roundActive", "4");
  264.  
  265. get_configsdir(file, charsmax(file));
  266. format(file, 127, "%s/weapon_db.cfg", file);
  267. if(file_exists(file)) server_cmd("exec %s", file);
  268. else set_fail_state("Конфигурационный файл БД weapon_db не загружен.")
  269.  
  270. get_pcvar_string(cvar_dbHost, szHost, 31);
  271. get_pcvar_string(cvar_dbUser, szUser, 31);
  272. get_pcvar_string(cvar_dbPass, szPass, 31);
  273. get_pcvar_string(cvar_dbName, szDBname, 31);
  274.  
  275. g_hDBTuple = SQL_MakeDbTuple(szHost, szUser, szPass, szDBname);
  276.  
  277. // Проверка соединения с БД
  278. new Handle:hConnection = SQL_Connect(g_hDBTuple, iErrorCode, szError, 63);
  279. if( hConnection == Empty_Handle ) set_fail_state(szError);
  280.  
  281. // Create table if not exist
  282. new Handle:hQuery = SQL_PrepareQuery(hConnection, "CREATE TABLE IF NOT EXISTS weapon_name(id INT(11), name varchar(32))");
  283.  
  284. if( !SQL_Execute(hQuery) )
  285. {
  286. SQL_QueryError(hQuery, szError, 63);
  287. set_fail_state(szError);
  288. }
  289.  
  290. hQuery = SQL_PrepareQuery(hConnection, "SELECT * FROM weapon_name");
  291. if( !SQL_Execute(hQuery) )
  292. {
  293. SQL_QueryError(hQuery, szError, 63);
  294. set_fail_state(szError);
  295. }
  296. new rows = SQL_NumResults(hQuery);
  297.  
  298. if(!rows)
  299. {
  300. for (new i = 0; i < sizeof g_wName; i++)
  301. {
  302. hQuery = SQL_PrepareQuery(hConnection,"INSERT INTO weapon_name(id, name) VALUES('%d','%s')", i+1, g_wName[i])
  303. if( !SQL_Execute(hQuery) )
  304. {
  305. SQL_QueryError(hQuery, szError, 63);
  306. set_fail_state(szError);
  307. }
  308. }
  309. }
  310.  
  311. hQuery = SQL_PrepareQuery(hConnection, "CREATE TABLE IF NOT EXISTS weapon_model(id INT(11), model_p varchar(32), model_v varchar(32), model_w varchar(32))");
  312.  
  313. if( !SQL_Execute(hQuery) )
  314. {
  315. SQL_QueryError(hQuery, szError, 63);
  316. set_fail_state(szError);
  317. }
  318.  
  319. hQuery = SQL_PrepareQuery(hConnection, "CREATE TABLE IF NOT EXISTS weapon_relation(name varchar(32), id_model INT(11), id_weapon INT(11), power INT(11)), message varchar(128)");
  320.  
  321. if( !SQL_Execute(hQuery) )
  322. {
  323. SQL_QueryError(hQuery, szError, 63);
  324. set_fail_state(szError);
  325. }
  326.  
  327. hQuery = SQL_PrepareQuery(hConnection, "CREATE TABLE IF NOT EXISTS user_weapon(name varchar(32), id_weapon_relation INT(11))");
  328. if( !SQL_Execute(hQuery) )
  329. {
  330. SQL_QueryError(hQuery, szError, 63);
  331. set_fail_state(szError);
  332. }
  333.  
  334. hQuery = SQL_PrepareQuery(hConnection, "CREATE TABLE IF NOT EXISTS user_hparm(name varchar(32), hp INT(11), armor INT(11))");
  335. if( !SQL_Execute(hQuery) )
  336. {
  337. SQL_QueryError(hQuery, szError, 63);
  338. set_fail_state(szError);
  339. }
  340.  
  341. hQuery = SQL_PrepareQuery(hConnection, "SELECT * FROM weapon_relation");
  342. if( !SQL_Execute(hQuery) )
  343. {
  344. SQL_QueryError(hQuery, szError, 63);
  345. set_fail_state(szError);
  346. }
  347. new szData[32];
  348. new count;
  349. while(SQL_MoreResults(hQuery))
  350. {
  351. g_weaponRelation[count][ID_REL] = SQL_ReadResult(hQuery, 0);
  352. SQL_ReadResult(hQuery, 1, szData, 31)
  353. copy(g_weaponRelation[count][WEAPON_NAME], 31, szData);
  354. g_weaponRelation[count][MODEL_ID] = SQL_ReadResult(hQuery, 2);
  355. g_weaponRelation[count][WEAPON_ID] = SQL_ReadResult(hQuery, 3);
  356. g_weaponRelation[count][POWER] = SQL_ReadResult(hQuery, 4);
  357. g_weaponRelation[count][KEY] = engfunc(EngFunc_AllocString, g_weaponRelation[count][WEAPON_NAME]);
  358. SQL_ReadResult(hQuery, 5, szData, 31)
  359. copy(g_weaponRelation[count][MESSAGE], 127, szData);
  360. SQL_NextRow(hQuery)
  361. count++;
  362. }
  363. g_weaponRelationCount = count;
  364. new item;
  365. count = 0;
  366. new bool:empty;
  367. model_id = ArrayCreate(1);
  368. for(new i = 0; i < g_weaponRelationCount; i++)
  369. {
  370. empty = true;
  371. for(new j = 0; j < ArraySize(model_id); j++)
  372. {
  373. empty = false;
  374. //item = ArrayGetCell(model_id, j);
  375. if(item == g_weaponRelation[i][MODEL_ID])
  376. {
  377. break;
  378. }
  379. if(j == sizeof(model_id))
  380. {
  381. ArrayPushCell(model_id, g_weaponRelation[i][MODEL_ID]);
  382. }
  383. }
  384. if(empty)
  385. {
  386. ArrayPushCell(model_id, g_weaponRelation[i][MODEL_ID]);
  387. }
  388. // во время перехода регистрируем коды оружий
  389. //g_keyWeapon[i][KEY] = engfunc(EngFunc_AllocString, g_weaponRelation[i][WEAPON_NAME])
  390. //copy(g_keyWeapon[i][W_NAME], 31, g_weaponRelation[i][WEAPON_NAME]);
  391. //formatex(tmp, charsmax(tmp), "sprites/%s.txt", g_weaponRelation[i][WEAPON_NAME]);
  392. //precache_generic(tmp);
  393. //register_message(78, "message_weaponlist") // get_user_msgid("WeaponList") не проканает
  394. }
  395.  
  396. count = 0;
  397. weapon_id = ArrayCreate(1);
  398. for(new i = 0; i < g_weaponRelationCount; i++)
  399. {
  400. empty = true;
  401. for(new j = 0; j < ArraySize(weapon_id); j++)
  402. {
  403. empty = false;
  404. item = ArrayGetCell(weapon_id, j);
  405. if(item == g_weaponRelation[i][WEAPON_ID]) break;
  406. if(j == sizeof(weapon_id) - 1)
  407. {
  408. ArrayPushCell(weapon_id, g_weaponRelation[i][WEAPON_ID]);
  409. count++;
  410. }
  411. }
  412. if(empty)
  413. {
  414. ArrayPushCell(weapon_id, g_weaponRelation[i][WEAPON_ID]);
  415. count++;
  416. }
  417. }
  418.  
  419. count = 0;
  420. hQuery = SQL_PrepareQuery(hConnection, "SELECT * FROM weapon_model");
  421. if( !SQL_Execute(hQuery) )
  422. {
  423. SQL_QueryError(hQuery, szError, 63);
  424. set_fail_state(szError);
  425. }
  426. new num;
  427. while(SQL_MoreResults(hQuery))
  428. {
  429. num = SQL_ReadResult(hQuery, 0)
  430. for(new i = 0; i < sizeof model_id; i++)
  431. {
  432. if (num == ArrayGetCell(model_id, i))
  433. {
  434. g_weaponModel[count][ID] = num;
  435. SQL_ReadResult(hQuery, 1, szData, 31);
  436. copy(g_weaponModel[count][MODEL_P], 31, szData);
  437. SQL_ReadResult(hQuery, 2, szData, 31);
  438. copy(g_weaponModel[count][MODEL_V], 31, szData);
  439. SQL_ReadResult(hQuery, 3, szData, 31);
  440. copy(g_weaponModel[count][MODEL_W], 31, szData);
  441. SQL_NextRow(hQuery);
  442. count++;
  443. }
  444. }
  445. }
  446. g_weaponModelCount = count;
  447.  
  448. for(new i = 0; i < g_weaponModelCount; i++)
  449. {
  450. precache_model(g_weaponModel[i][MODEL_P]);
  451. precache_model(g_weaponModel[i][MODEL_V]);
  452. precache_model(g_weaponModel[i][MODEL_W]);
  453. }
  454.  
  455. SQL_FreeHandle(hQuery);
  456. SQL_FreeHandle(hConnection);
  457. }
  458.  
  459. public plugin_end()
  460. {
  461. SQL_FreeHandle(g_hDBTuple);
  462. }
  463.  
  464. // утснавливает модель оружия со стороны и в выбрашенном состоянии
  465. public Fakemeta_SetModel(ent, const ModelStr[])
  466. {
  467. if(!pev_valid(ent)) return FMRES_IGNORED;
  468. new tmp[32];
  469. for(new j = 0; j < g_weaponRelationCount; j++)
  470. {
  471. static weapon_id;
  472. weapon_id = g_weaponRelation[j][WEAPON_ID];
  473. format(tmp, 31, "models/w_%s.mdl", g_wModel[weapon_id - 1]);
  474. if(equal(ModelStr, tmp))
  475. {
  476. static entity;
  477. entity = -1;
  478. while ((entity = engfunc(EngFunc_FindEntityByString, entity, "classname", g_wName[weapon_id - 1])))
  479. {
  480. if(is_valid_weapon(entity, g_weaponRelation[j][KEY]))
  481. {
  482. for(new z = 0; z < g_weaponModelCount; z++)
  483. {
  484. if(g_weaponModel[z][ID] == g_weaponRelation[j][MODEL_ID])
  485. {
  486. engfunc(EngFunc_SetModel, ent, g_weaponModel[z][MODEL_W]);
  487. return FMRES_SUPERCEDE;
  488. }
  489. }
  490. }
  491. }
  492. }
  493. }
  494.  
  495. return FMRES_IGNORED;
  496. }
  497.  
  498. public give_weapon(id, key, name[])
  499. {
  500. new Float:Origin[3];
  501. pev(id, pev_origin, Origin)
  502. //new wName[32];
  503.  
  504. /*new iItem1 = get_pdata_cbase(id, 367 + 2, 5);
  505. while (pev_valid(iItem1) == 2)
  506. {
  507. pev(iItem, pev_classname, wName, 31)
  508. engclient_cmd(id, "drop", wName)
  509. iItem1 = get_pdata_cbase(id, 367 + 2, 5);
  510. }*/
  511.  
  512. /*new iItem = get_pdata_cbase(id, 367 + 1, 5); // первый слот оружия
  513. while (pev_valid(iItem) == 2)
  514. {
  515. pev(iItem, pev_classname, wName, 31)
  516. engclient_cmd(id, "drop", wName)
  517. iItem = get_pdata_cbase(id, 367 + 1, 5);
  518. }*/
  519.  
  520. new iWeapon = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, name))
  521.  
  522. if(!pev_valid(iWeapon)) return PLUGIN_HANDLED
  523.  
  524. dllfunc(DLLFunc_Spawn, iWeapon)
  525. engfunc(EngFunc_SetOrigin, iWeapon, Origin)
  526.  
  527. set_pev(iWeapon, pev_impulse, key)
  528.  
  529. new save = pev(iWeapon, pev_solid)
  530. dllfunc(DLLFunc_Touch, iWeapon, id)
  531.  
  532. if( pev(iWeapon, pev_solid) != save )
  533. return iWeapon;
  534. engfunc(EngFunc_RemoveEntity, iWeapon)
  535. return PLUGIN_HANDLED;
  536. }
  537.  
  538. /*
  539. public client_disconnected(id)
  540. {
  541. if (g_loadPlayer[id])
  542. {
  543. new szSteamId[ 32 ];
  544. get_user_authid( id, szSteamId, charsmax( szSteamId ) );
  545.  
  546. new szTemp[ 512 ];
  547. format(szTemp, charsmax(szTemp), "UPDATE `ZPCustumSave` SET `NightVision` = '%i', `PosStats` = '%f', `PosStats2` = '%f', `ColorHud` = '%d', `ZombieSurvive` = '%i', `HumanKills` = '%i', `SurvivorKills` = '%i', `Infections` = '%i', `HumanSurvive` = '%i', `ZombieKills` = '%i', `NemesisKills` = '%i', `NumPack` = '%i' WHERE (`ZPCustumSave`.`steamid` = '%s');",
  548. g_iColorNightVision[id], g_flShiftHud[id][0], g_flShiftHud[id][1], g_iColorHud[id], g_iZombieSurvive[id], g_iHumanKills[id], g_iSurvivorKills[id], g_iInfections[id], g_iHumanSurvive[id], g_iZombieKills[id], g_iNemesisKills[id], g_numPack[id], szSteamId );
  549. new arg[1];
  550. arg[0] = id;
  551. SQL_ThreadQuery( g_hDBTuple,"SQL_QueryCloseConnection", szTemp, arg, sizeof arg );
  552. }
  553. }
  554. */
  555. public client_putinserver(id)
  556. {
  557. if( is_user_bot(id) || is_user_hltv(id) ) return;
  558. set_task(1.0, "loadFromDb", MYTASK + id);
  559. }
  560.  
  561. public loadFromDb(taskid)
  562. {
  563. new id = ID_MYTASK;
  564. new name[32];
  565. new szTemp[512];
  566. new arg[1];
  567. arg[0] = id;
  568. get_user_name(id, name, 31);
  569. g_User[id - 1][NAME][0] = 0;
  570. g_User[id - 1][ID_WR] = 0;
  571. format(szTemp, 511, "SELECT * FROM user_weapon WHERE (`user_weapon`.`name` = '%s')", name);
  572. SQL_ThreadQuery(g_hDBTuple, "SQL_QueryConnection", szTemp, arg, 1);
  573. g_User[id - 1][HP] = 0;
  574. g_User[id - 1][ARMOR] = 0;
  575. format(szTemp, 511, "SELECT * FROM user_hparm WHERE (`user_hparm`.`name` = '%s')", name);
  576. SQL_ThreadQuery(g_hDBTuple, "SQL_QueryConnectionHPArmor", szTemp, arg, 1);
  577. }
  578.  
  579. public SQL_QueryConnectionHPArmor( iState, Handle:hQuery, szError[ ], iErrcode, pParameters[], pParametersSize )
  580. {
  581. switch( iState )
  582. {
  583. case TQUERY_CONNECT_FAILED: log_amx("Load - Could not connect to SQL database. [ %d ] %s", iErrcode, szError );
  584. case TQUERY_QUERY_FAILED: log_amx(" Load Query failed. [ %d ] %s", iErrcode, szError );
  585. }
  586.  
  587. if( iErrcode )
  588. {
  589. log_amx("Error on query: %s",szError);
  590. return PLUGIN_CONTINUE;
  591. }
  592.  
  593. new pPlayer = pParameters[0];
  594. new Name[32];
  595. get_user_name(pPlayer, Name, 31);
  596. //new szTemp[512];
  597. new szSteamId[32];
  598. get_user_authid(pPlayer, szSteamId, 31);
  599.  
  600. // if doesn't exist
  601. if( SQL_NumResults(hQuery) < 1 )
  602. {
  603. // create something
  604. /*
  605. format(szTemp, charsmax(szTemp), "INSERT INTO `ZPCustumSave`( `steamid`, `NightVision`, `PosStats`, `PosStats2`, `ColorHud`, `ZombieSurvive`, `HumanKills`, `SurvivorKills`, `Infections`, `HumanSurvive`, `ZombieKills`, `NemesisKills`, `NumPack`) VALUES('%s','0','0','0','-1','0','0','0','0','0','0','0','1');", szSteamId );
  606. g_iColorHud[pPlayer] = -1;
  607. g_numPack[pPlayer] = 1;
  608. SQL_FreeHandle(hQuery);
  609. g_loadPlayer[pPlayer] = 1;
  610. SQL_ThreadQuery(g_hDBTuple,"SQL_QueryCloseConnection", szTemp, pParameters, 1);
  611. return PLUGIN_CONTINUE;
  612. */
  613. }
  614. else
  615. {
  616. SQL_ReadResult(hQuery, 0, g_User[pPlayer - 1][NAME], 31)
  617. g_User[pPlayer - 1][HP] = SQL_ReadResult(hQuery, 1)
  618. g_User[pPlayer - 1][ARMOR] = SQL_ReadResult(hQuery, 2)
  619. }
  620. SQL_FreeHandle(hQuery);
  621. return PLUGIN_CONTINUE;
  622. }
  623.  
  624. public SQL_QueryConnection( iState, Handle:hQuery, szError[ ], iErrcode, pParameters[], pParametersSize )
  625. {
  626. switch( iState )
  627. {
  628. case TQUERY_CONNECT_FAILED: log_amx("Load - Could not connect to SQL database. [ %d ] %s", iErrcode, szError );
  629. case TQUERY_QUERY_FAILED: log_amx(" Load Query failed. [ %d ] %s", iErrcode, szError );
  630. }
  631.  
  632. if( iErrcode )
  633. {
  634. log_amx("Error on query: %s",szError);
  635. return PLUGIN_CONTINUE;
  636. }
  637.  
  638. new pPlayer = pParameters[0];
  639. new Name[32];
  640. get_user_name(pPlayer, Name, 31);
  641. //new szTemp[512];
  642. new szSteamId[32];
  643. get_user_authid(pPlayer, szSteamId, 31);
  644.  
  645. // if doesn't exist
  646. if( SQL_NumResults(hQuery) < 1 )
  647. {
  648. // create something
  649. /*
  650. format(szTemp, charsmax(szTemp), "INSERT INTO `ZPCustumSave`( `steamid`, `NightVision`, `PosStats`, `PosStats2`, `ColorHud`, `ZombieSurvive`, `HumanKills`, `SurvivorKills`, `Infections`, `HumanSurvive`, `ZombieKills`, `NemesisKills`, `NumPack`) VALUES('%s','0','0','0','-1','0','0','0','0','0','0','0','1');", szSteamId );
  651. g_iColorHud[pPlayer] = -1;
  652. g_numPack[pPlayer] = 1;
  653. SQL_FreeHandle(hQuery);
  654. g_loadPlayer[pPlayer] = 1;
  655. SQL_ThreadQuery(g_hDBTuple,"SQL_QueryCloseConnection", szTemp, pParameters, 1);
  656. return PLUGIN_CONTINUE;
  657. */
  658. }
  659. else
  660. {
  661. //g_iColorNightVision[pPlayer] = SQL_ReadResult(hQuery, 1);
  662. //SQL_ReadResult(hQuery, 2, g_flShiftHud[pPlayer][0]);
  663. SQL_ReadResult(hQuery, 0, g_User[pPlayer - 1][NAME], 31)
  664. g_User[pPlayer - 1][ID_WR] = SQL_ReadResult(hQuery, 1);
  665. }
  666. SQL_FreeHandle(hQuery);
  667. return PLUGIN_CONTINUE;
  668. }
  669.  
  670. public SQL_QueryCloseConnection(iState, Handle:hQuery, szError[], iErrcode, pParameters[], pParametersSize)
  671. {
  672. new id = pParameters[0];
  673. new Name[32];
  674. get_user_name(id, Name, charsmax(Name));
  675. switch( iState )
  676. {
  677. case TQUERY_CONNECT_FAILED: log_amx("Load - Could not connect to SQL database. [%d] %s", iErrcode, szError);
  678. case TQUERY_QUERY_FAILED: log_amx("Load Query failed. [ %d ] %s", iErrcode, szError );
  679. }
  680. if( iErrcode )
  681. {
  682. log_amx("Error on query: %s", szError);
  683. return PLUGIN_CONTINUE;
  684. }
  685. SQL_FreeHandle(hQuery);
  686. return PLUGIN_CONTINUE;
  687. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement