Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.66 KB | None | 0 0
  1. include <amxmodx>
  2. #include <amxmisc>
  3. #include <fakemeta>
  4. #include <cstrike>
  5. #include <sqlx>
  6. #include <CSO_System>
  7. #include <nvault>
  8. #include <zombie_theheroex>
  9.  
  10. #define PLUGIN "[CSO] System: Level"
  11. #define VERSION "1.0"
  12. #define AUTHOR "Dias Pendragon"
  13.  
  14. // Use Medal System Also ?
  15. //#define USE_MEDALSYSTEM
  16.  
  17. #define HUD_X 0.02
  18. #define HUD_Y 0.30
  19.  
  20. // SAVE TYPE
  21. #define SAVE_TYPE 1 // 1 - Nvault | 2 - MySQL (Check Database Info)
  22.  
  23. // MySQL Config
  24. #define SQL_HOST "127.0.0.1"
  25. #define SQL_DB "databasename"
  26. #define SQL_USERNAME "user"
  27. #define SQL_PASSWORD "pass"
  28.  
  29. new Handle:g_SQL_Id, g_SQL_Error[128], g_SQL_Query[512]
  30.  
  31. // Profile Config
  32. #define SOUND_LVUP "cso_system/lvup.wav"
  33. #define SOUND_PROMOTED "cso_system/promoted.wav"
  34.  
  35. new g_PlayerLevel[33], g_PlayerExp[33]
  36.  
  37. // Level Configs
  38. #define MAX_LEVEL 30
  39. new const LevelTitle[MAX_LEVEL+1][] =
  40. {
  41. "[NONE]", // 0 - There is no level 0 :)
  42. "Recruit", // 1
  43. "Private", "Private First Class", "Corporal",
  44. "Sergeant", // 5
  45. "Staff Sergeant (1st)", "Staff Sergeant (Final)", "Sergeant First Class (1st)", "Sergeant First Class (2nd)",
  46. "Sergeant First Class (Final)", // 10
  47. "Master Sergeant (1st)", "Master Sergeant (2nd)", "Master Sergeant (Final)", "Sergeant Major (1st)",
  48. "Sergeant Major (2nd)", // 15
  49. "Sergeant Major (3rd)", "Sergeant Major (Final)", "Second Lieutenant (1st)", "Second Lieutenant (2nd)",
  50. "Second Lieutenant (3rd)", // 20
  51. "Second Lieutenant (4th)", "Second Lieutenant (Final)", "First Lieutenant (1st)", "First Lieutenant (2nd)",
  52. "First Lieutenant (3rd)", // 25
  53. "First Lieutenant (4th)", "First Lieutenant (Final)", "Captain (1st)", "Captain (2nd)", "Captain (3rd)" // 30
  54.  
  55. }
  56.  
  57. new const LevelExp[MAX_LEVEL+1] =
  58. {
  59. 0, // Level 0 lol
  60. 0, // 5000 Money
  61. 30, // 7000
  62. 50, // 8000
  63. 70, // 9000
  64. 100, // 10000
  65. 300, //12000
  66. 400, // 15000
  67. 500, // 20000
  68. 600, // 25000
  69. 700, // 30000
  70. 800, // 35000
  71. 900, //40000
  72. 1100, // 45000
  73. 1300, // 50000
  74. 2000, // 55000
  75. 2200, // 60000
  76. 2400, // 70000
  77. 2600, // 80000
  78. 2800, // 90000
  79. 3000, // 100000
  80. 3400, // 110000
  81. 3800, // 120000
  82. 4200, // 130000
  83. 4500, // 140000
  84. 5000, // 150000
  85. 5400, // 160000
  86. 5800, // 170000
  87. 6200, // 180000
  88. 6600, // 190000
  89. 7000 // 190000
  90. }
  91.  
  92. // Task
  93. #define TASK_LVUP_SOUND1 49651
  94. #define TASK_LVUP_SOUND2 49652
  95.  
  96. // Message
  97. enum _:MAX_TYPES
  98. {
  99. TYPE_NONE,
  100. TYPE_RELATION,
  101. TYPE_PLAYER,
  102. TYPE_HEALTH
  103. }
  104.  
  105. enum
  106. {
  107. LOOK_FRIEND = 1,
  108. LOOK_ENEMY,
  109. LOOK_HOSTAGE,
  110. }
  111.  
  112. new StatusValue[MAX_TYPES]
  113.  
  114. // Language (Becareful when changing those ones)
  115. #define NOTICE_LEVELUP "!g**** Congratulation! **** [%s] has been promoted to Lv.%i [%s]!n"
  116. #define STATUS_FRIEND "%s - %iHP (Lv.%i - Exp: %i percent)"
  117. #define STATUS_FRIEND_MEDAL "[%s] %s - %iHP (Lv.%i - Exp: %i percent)"
  118. #define STATUS_ENEMY "%s (Lv.%i - Exp: %i percent)"
  119. #define STATUS_ENEMY_MEDAL "[%s] %s (Lv.%i - Exp: %i percent)"
  120.  
  121. new g_MaxPlayers, g_MsgSayText, g_MsgStatusText
  122. new g_Forward_LevelUp, g_fwResult, g_VaultID
  123. new g_Hud
  124.  
  125. public plugin_init()
  126. {
  127. register_plugin(PLUGIN, VERSION, AUTHOR)
  128.  
  129. register_event("HLTV", "Event_NewRound", "a", "1=0", "2=0")
  130. register_logevent("Event_RoundEnd", 2, "1=Round_End")
  131.  
  132. g_Hud = zbheroex_get_synchud_id(SYNCHUD_ZBHM_SKILL1)
  133.  
  134. // Initialize MySql System
  135. new Type; Type = SAVE_TYPE
  136. if(Type == 1) g_VaultID = nvault_open("CSO_Level")
  137. else if(Type == 2) MySQL_Init()
  138.  
  139. // Event
  140. register_event("StatusValue", "Event_StatusValue", "b")
  141.  
  142. /// Forwards
  143. g_Forward_LevelUp = CreateMultiForward("CSO_System_LevelUp", ET_IGNORE, FP_CELL, FP_CELL)
  144.  
  145. // Get Data
  146. g_MaxPlayers = get_maxplayers()
  147. g_MsgSayText = get_user_msgid("SayText")
  148. g_MsgStatusText = get_user_msgid("StatusText")
  149.  
  150. // Command
  151. register_clcmd("say /player", "CMD_PlayerInfo")
  152. }
  153. public plugin_end() nvault_close(g_VaultID)
  154.  
  155. public plugin_precache()
  156. {
  157. precache_sound(SOUND_LVUP)
  158. precache_sound(SOUND_PROMOTED)
  159. }
  160.  
  161. public plugin_natives()
  162. {
  163. register_native("CSO_System_Level_GainExp", "Native_GainExp", 1)
  164.  
  165. register_native("CSO_System_Level_SetLv", "Native_SetLv", 1)
  166. register_native("CSO_System_Level_GetLv", "Native_GetLv", 1)
  167.  
  168. register_native("CSO_System_Level_SetExp", "Native_SetExp", 1)
  169. register_native("CSO_System_Level_GetExp", "Native_GetExp", 1)
  170. }
  171.  
  172. public client_putinserver(id)
  173. {
  174. Clear_PlayerLevel(id)
  175. Load_PlayerLevel(id)
  176. }
  177.  
  178. public client_disconnect(id)
  179. {
  180. Save_PlayerLevel(id)
  181. }
  182.  
  183.  
  184. public client_connect(id)
  185. {
  186. Load_PlayerLevel(id)
  187. }
  188.  
  189. public Event_NewRound()
  190. {
  191. for(new i = 0; i < g_MaxPlayers; i++)
  192. {
  193. if(!is_user_connected(i))
  194. continue
  195.  
  196. Save_PlayerLevel(i)
  197. }
  198. }
  199.  
  200. public Event_RoundEnd(id)
  201. {
  202. new Type; Type = SAVE_TYPE
  203. if(Type == 1) g_VaultID = nvault_open("CSO_Level")
  204.  
  205. Save_PlayerLevel(id)
  206. }
  207.  
  208. // ============================================================
  209. // --------------------- Natives Functions --------------------
  210. public Native_GainExp(id, Exp, CheckLvUp)
  211. {
  212. if(!is_user_connected(id))
  213. return
  214. Level_GainExp(id, Exp, CheckLvUp)
  215. }
  216.  
  217. public Native_SetLv(id, Level)
  218. {
  219. if(!is_user_connected(id))
  220. return
  221. if(Level > MAX_LEVEL)
  222. return
  223.  
  224. g_PlayerLevel[id] = Level
  225. }
  226.  
  227. public Native_GetLv(id)
  228. {
  229. if(!is_user_connected(id))
  230. return 0
  231.  
  232. return g_PlayerLevel[id]
  233. }
  234.  
  235. public Native_SetExp(id, Exp)
  236. {
  237. if(!is_user_connected(id))
  238. return
  239.  
  240. g_PlayerExp[id] = Exp
  241. }
  242.  
  243. public Native_GetExp(id)
  244. {
  245. if(!is_user_connected(id))
  246. return 0
  247.  
  248. return g_PlayerExp[id]
  249. }
  250.  
  251. // ============================================================
  252. // ------------------ Main Level Functions --------------------
  253. public Level_GainExp(id, Exp, CheckLvUp)
  254. {
  255. g_PlayerExp[id] += Exp
  256. if(CheckLvUp) Level_CheckUp(id)
  257.  
  258. Save_PlayerLevel(id)
  259. }
  260.  
  261. public Level_CheckUp(id)
  262. {
  263. if(g_PlayerLevel[id] >= MAX_LEVEL)
  264. return
  265.  
  266. static HadLevelUp; HadLevelUp = 0
  267. while(g_PlayerExp[id] >= LevelExp[g_PlayerLevel[id]+1])
  268. {
  269. g_PlayerLevel[id]++
  270. HadLevelUp = 1
  271. }
  272.  
  273. if(HadLevelUp)
  274. { // Player Level Up!
  275. PlaySound(id, SOUND_LVUP)
  276.  
  277. static Name[32]
  278. get_user_name(id, Name, sizeof(Name))
  279.  
  280. set_task(1.0, "Sound_LevelUp_Repeat", id+TASK_LVUP_SOUND1)
  281. set_task(2.25, "Sound_LevelUp_Promoted", id+TASK_LVUP_SOUND2)
  282.  
  283. client_printc(0, NOTICE_LEVELUP, Name, g_PlayerLevel[id], LevelTitle[g_PlayerLevel[id]])
  284.  
  285. // Run Forward
  286. ExecuteForward(g_Forward_LevelUp, g_fwResult, id, g_PlayerLevel[id])
  287. }
  288. }
  289.  
  290. public Sound_LevelUp_Repeat(id)
  291. {
  292. id -= TASK_LVUP_SOUND1
  293. if(!is_user_connected(id))
  294. return
  295.  
  296. PlaySound(id, SOUND_LVUP)
  297. set_task(1.0, "Sound_LevelUp_Repeat", id+TASK_LVUP_SOUND1)
  298. }
  299.  
  300. public Sound_LevelUp_Promoted(id)
  301. {
  302. id -= TASK_LVUP_SOUND2
  303.  
  304. remove_task(id+TASK_LVUP_SOUND1)
  305. remove_task(id+TASK_LVUP_SOUND2)
  306.  
  307. if(!is_user_connected(id))
  308. return
  309.  
  310. PlaySound(id, SOUND_PROMOTED)
  311. }
  312.  
  313. public zbheroex_skill_show(id, Zombie)
  314. {
  315. if(!Zombie)
  316. {
  317. if(g_PlayerLevel[id] >= MAX_LEVEL)
  318. {
  319. set_hudmessage(0, 0, 255, HUD_X, HUD_Y, 0, 2.0, 2.0)
  320. ShowSyncHudMsg(id, g_Hud, "[Level: %i]^n[Exp: %i]", g_PlayerLevel[id], g_PlayerExp[id])
  321. } else {
  322. set_hudmessage(0, 0, 255, HUD_X, HUD_Y, 0, 2.0, 2.0)
  323. ShowSyncHudMsg(id, g_Hud, "[Level: %i]^n[Exp: %i/%i]", g_PlayerLevel[id], g_PlayerExp[id], LevelExp[g_PlayerLevel[id]+1])
  324. }
  325. } else {
  326. if(g_PlayerLevel[id] >= MAX_LEVEL)
  327. {
  328. set_hudmessage(255, 0, 0, HUD_X, HUD_Y, 0, 2.0, 2.0)
  329. ShowSyncHudMsg(id, g_Hud, "[Level: %i]^n[Exp: %i]", g_PlayerLevel[id], g_PlayerExp[id])
  330. } else {
  331. set_hudmessage(255, 0, 0, HUD_X, HUD_Y, 0, 2.0, 2.0)
  332. ShowSyncHudMsg(id, g_Hud, "[Level: %i]^n[Exp: %i/%i]", g_PlayerLevel[id], g_PlayerExp[id], LevelExp[g_PlayerLevel[id]+1])
  333. }
  334. }
  335. }
  336.  
  337.  
  338. // ============================================================
  339. // ------------------------- Check Info -----------------------
  340. public CMD_PlayerInfo(id)
  341. {
  342. if(!is_user_connected(id))
  343. return
  344.  
  345. static Body, Target; get_user_aiming(id, Target, Body, 9999)
  346.  
  347. static Menu; Menu = menu_create("Players Infomation", "MenuHandle_PlayerInfo")
  348. static Name[32], Text[64], IdNumber[4]
  349.  
  350. for(new i = 0; i < g_MaxPlayers; i++)
  351. {
  352. if(!is_user_connected(i))
  353. continue
  354.  
  355. get_user_name(i, Name, sizeof(Name))
  356. switch(cs_get_user_team(i))
  357. {
  358. case CS_TEAM_SPECTATOR: formatex(Text, sizeof(Text), "%s (SPEC)", Name)
  359. case CS_TEAM_T: formatex(Text, sizeof(Text), "%s (T)", Name)
  360. case CS_TEAM_CT: formatex(Text, sizeof(Text), "%s (CT)", Name)
  361. }
  362.  
  363. num_to_str(i, IdNumber, sizeof(IdNumber))
  364. menu_additem(Menu, Text, IdNumber)
  365. }
  366.  
  367. menu_setprop(Menu, MPROP_EXIT, MEXIT_ALL)
  368. menu_display(id, Menu, 0)
  369. }
  370.  
  371. public MenuHandle_PlayerInfo(id, Menu, Item)
  372. {
  373. if(Item == MENU_EXIT)
  374. {
  375. menu_destroy(Menu)
  376. return PLUGIN_HANDLED
  377. }
  378.  
  379. static Name[32], IdNumber[4]
  380. static ItemCallback, ItemAccess
  381. menu_item_getinfo(Menu, Item, ItemAccess, IdNumber, charsmax(IdNumber), Name, charsmax(Name), ItemCallback)
  382.  
  383. static Player; Player = str_to_num(IdNumber)
  384. if(!is_user_connected(Player))
  385. {
  386. menu_destroy(Menu)
  387. return PLUGIN_HANDLED
  388. }
  389.  
  390. Show_Information(id, Player)
  391.  
  392. menu_destroy(Menu)
  393. return PLUGIN_HANDLED
  394. }
  395.  
  396. public Show_Information(id, Player)
  397. {
  398. static Name[32]; get_user_name(Player, Name, sizeof(Name))
  399. static Header[64]; formatex(Header, sizeof(Header), "Player Information: %s", Name)
  400. static Motd[512], Float:Percent
  401.  
  402. Percent = float(g_PlayerExp[Player]) / float(LevelExp[g_PlayerLevel[Player] + 1]) * 100.0
  403. formatex(Motd, sizeof(Motd), "<center><h2><b>%s</b></h2><br><br><b>Level:</b> %i<br><b>Experience:</b> %i/%i (%i%%)</center>", Name, g_PlayerLevel[Player], g_PlayerExp[Player], LevelExp[g_PlayerLevel[Player] + 1], floatround(Percent))
  404.  
  405. #if defined USE_MEDALSYSTEM
  406. static MedalText[400]
  407. if(CSO_System_Medal_GetUsingMedal(Player) != -1)
  408. {
  409. static Medal[32]; CSO_System_Medal_GetTitle(Player, Medal)
  410. static HonorPoint; HonorPoint = CSO_System_Medal_GetTotalHonorPoint(Player)
  411.  
  412. CSO_System_Medal_GetList(Player, MedalText)
  413. formatex(Motd, sizeof(Motd), "<center><h2><b>[%s] %s</b></h2><br><br><b>Level:</b> %i<br><b>Experience:</b> %i/%i (%i%%)<br><b>Total Honor Points:</b> %i<br><b>Medal List:</b> %s</center>", Medal, Name, g_PlayerLevel[Player], g_PlayerExp[Player], LevelExp[g_PlayerLevel[Player] + 1], floatround(Percent), HonorPoint, MedalText)
  414. } else {
  415. static HonorPoint; HonorPoint = CSO_System_Medal_GetTotalHonorPoint(Player)
  416.  
  417. CSO_System_Medal_GetList(Player, MedalText)
  418. formatex(Motd, sizeof(Motd), "<center><h2><b>%s</b></h2><br><br><b>Level:</b> %i<br><b>Experience:</b> %i/%i (%i%%)<br><b>Total Honor Points:</b> %i<br><b>Medal List:</b> %s</center>", Name, g_PlayerLevel[Player], g_PlayerExp[Player], LevelExp[g_PlayerLevel[Player] + 1], floatround(Percent), HonorPoint, MedalText)
  419. }
  420. #endif
  421.  
  422. show_motd(id, Motd, Header)
  423. }
  424.  
  425. // ============================================================
  426. // --------------------------- Event --------------------------
  427. public Event_StatusValue(id)
  428. {
  429. static Num; Num = read_data(1)
  430. if(Num <= 0 || Num >= MAX_TYPES)
  431. return
  432.  
  433. static Update; Update = StatusValue[Num] = read_data(2)
  434. switch(Num)
  435. {
  436. case TYPE_RELATION:
  437. {
  438. if(!Update && is_user_alive(id))
  439. {
  440. message_begin(MSG_ONE_UNRELIABLE, g_MsgStatusText, _, id)
  441. write_byte(0)
  442. write_string("")
  443. message_end()
  444. }
  445. }
  446. case TYPE_PLAYER:
  447. {
  448. if(is_user_alive(id))
  449. {
  450. new Message[192], Float:Percent
  451. new PlayerName[32];
  452. copy(PlayerName, sizeof(PlayerName), "%p2")
  453.  
  454. switch(StatusValue[TYPE_RELATION])
  455. {
  456. case LOOK_FRIEND:
  457. {
  458. Percent = float(g_PlayerExp[Update]) / float(LevelExp[g_PlayerLevel[Update] + 1]) * 100.0
  459. formatex(Message, sizeof(Message), STATUS_FRIEND, PlayerName, get_user_health(Update), g_PlayerLevel[Update], floatround(Percent))
  460.  
  461. #if defined USE_MEDALSYSTEM
  462. if(CSO_System_Medal_GetUsingMedal(Update) != -1)
  463. {
  464. static Medal[64]; CSO_System_Medal_GetTitle(Update, Medal)
  465. formatex(Message, sizeof(Message), STATUS_FRIEND_MEDAL, Medal, PlayerName, get_user_health(Update), g_PlayerLevel[Update], floatround(Percent))
  466. }
  467. #endif
  468. }
  469. case LOOK_ENEMY:
  470. {
  471. Percent = float(g_PlayerExp[Update]) / float(LevelExp[g_PlayerLevel[Update] + 1]) * 100.0
  472. formatex(Message, sizeof(Message), STATUS_ENEMY, PlayerName, g_PlayerLevel[Update], floatround(Percent))
  473. #if defined USE_MEDALSYSTEM
  474. if(CSO_System_Medal_GetUsingMedal(Update) != -1)
  475. {
  476. static Medal[64]; CSO_System_Medal_GetTitle(Update, Medal)
  477. formatex(Message, sizeof(Message), STATUS_ENEMY_MEDAL, Medal, PlayerName, g_PlayerLevel[Update], floatround(Percent))
  478. }
  479. #endif
  480. }
  481. case LOOK_HOSTAGE:
  482. {
  483. return;
  484. }
  485. }
  486.  
  487. message_begin(MSG_ONE_UNRELIABLE, g_MsgStatusText, _, id)
  488. write_byte(0)
  489. write_string(Message)
  490. message_end()
  491. }
  492. }
  493. }
  494. }
  495.  
  496. // ============================================================
  497. // ---------------------- MySQL Functions ---------------------
  498. public MySQL_Init()
  499. {
  500. server_print("[MySQL] Initializing...")
  501.  
  502. g_SQL_Id = SQL_MakeDbTuple(SQL_HOST, SQL_USERNAME, SQL_PASSWORD, SQL_DB)
  503.  
  504. new ErrorCode, Handle:SqlConnection = SQL_Connect(g_SQL_Id, ErrorCode, g_SQL_Error, charsmax(g_SQL_Error))
  505. if(SqlConnection == Empty_Handle)
  506. set_fail_state(g_SQL_Error)
  507.  
  508. new Handle:Queries
  509. Queries = SQL_PrepareQuery(SqlConnection, "CREATE TABLE IF NOT EXISTS Level (PlayerName varchar(32), Level INT(8), Exp INT(16))")
  510.  
  511. if(!SQL_Execute(Queries))
  512. {
  513. SQL_QueryError(Queries, g_SQL_Error, charsmax(g_SQL_Error))
  514. set_fail_state(g_SQL_Error)
  515. }
  516.  
  517. SQL_FreeHandle(Queries)
  518. SQL_FreeHandle(SqlConnection)
  519.  
  520. server_print("[MySQL] Initialize: Completed!")
  521. }
  522.  
  523. public Load_PlayerLevel(id)
  524. {
  525. new Type; Type = SAVE_TYPE
  526. static PlayerName[32]
  527. get_user_name(id, PlayerName, sizeof(PlayerName))
  528.  
  529. if(Type == 1)
  530. {
  531. static VaultKey[64], VaultData[256]
  532.  
  533. // Search
  534. format(VaultKey, 63,"%s-Level", PlayerName)
  535. format(VaultData, 255,"%i#%i#", g_PlayerExp[id], g_PlayerLevel[id])
  536.  
  537. // Load the Data
  538. nvault_get(g_VaultID, VaultKey, VaultData,255)
  539. replace_all(VaultData, 255, "#", " ")
  540.  
  541. static PlayerExp[32], PlayerLevel[32]
  542. parse(VaultData, PlayerExp, 31, PlayerLevel, 31)
  543.  
  544. // Set Data
  545. g_PlayerExp[id] = str_to_num(PlayerExp)
  546. g_PlayerLevel[id] = str_to_num(PlayerLevel)
  547. } else if(Type == 2) {
  548. static Data[1]; Data[0] = id
  549.  
  550. format(g_SQL_Query, charsmax(g_SQL_Query),"SELECT * FROM `Level` WHERE (`Level`.`PlayerName` = '%s')", PlayerName)
  551. SQL_ThreadQuery(g_SQL_Id, "SQLHandle_LoadLevel", g_SQL_Query, Data, sizeof(Data))
  552. }
  553. }
  554.  
  555. public Save_PlayerLevel(id)
  556. {
  557. new Type; Type = SAVE_TYPE
  558. static PlayerName[32]
  559. get_user_name(id, PlayerName, sizeof(PlayerName))
  560.  
  561. if(Type == 1)
  562. {
  563. // get the players steam id. We need this because we are saving by steam id
  564. static VaultKey[64], VaultData[256]
  565.  
  566. // format wat is going to be in the animal mod vault file
  567. format(VaultKey, 63,"%s-Level", PlayerName)
  568. format(VaultData, 255,"%i#%i#", g_PlayerExp[id], g_PlayerLevel[id])
  569.  
  570. // save the data
  571. nvault_set(g_VaultID, VaultKey, VaultData)
  572. } else if(Type == 2) {
  573. format(g_SQL_Query, charsmax(g_SQL_Query),"UPDATE `Level` SET `Level` = '%i', `Exp` = '%i' WHERE `Level`.`PlayerName` = '%s';", g_PlayerLevel[id], g_PlayerExp[id], PlayerName)
  574. SQL_ThreadQuery(g_SQL_Id, "SQLHandle_Ignore", g_SQL_Query)
  575. }
  576. }
  577.  
  578. public Clear_PlayerLevel(id)
  579. {
  580. g_PlayerLevel[id] = 1
  581. g_PlayerExp[id] = 0
  582. }
  583.  
  584. public SQLHandle_LoadLevel(FailState, Handle:Query, Error[], Errcode, Data[], DataSize)
  585. {
  586. if(FailState == TQUERY_CONNECT_FAILED)
  587. log_amx("[MySQL] Error (Load): Could not connect to SQL Database. [%d] %s", Errcode, Error)
  588. else if(FailState == TQUERY_QUERY_FAILED)
  589. log_amx("[MySQL] Error (Load): Query failed. [%d] %s", Errcode, Error)
  590.  
  591. static id; id = Data[0]
  592. if(SQL_NumResults(Query) < 1)
  593. { // if there are no results found
  594. static PlayerName[32]
  595. get_user_name(id, PlayerName, sizeof(PlayerName))
  596.  
  597. format(g_SQL_Query, charsmax(g_SQL_Query), "INSERT INTO `Level` ( `PlayerName` , `Level` , `Exp`)VALUES ('%s' , '1' , '0');", PlayerName)
  598. SQL_ThreadQuery(g_SQL_Id, "SQLHandle_Ignore", g_SQL_Query)
  599. } else {
  600. g_PlayerLevel[id] = SQL_ReadResult(Query, 1)
  601. g_PlayerExp[id] = SQL_ReadResult(Query, 2)
  602.  
  603. client_printc(id, "!g[Level]!n Loading Completed!")
  604. }
  605.  
  606. return PLUGIN_HANDLED
  607. }
  608.  
  609. public SQLHandle_Ignore(FailState, Handle:Query, Error[], Errcode, Data[], DataSize)
  610. {
  611. SQL_FreeHandle(Query)
  612. return PLUGIN_HANDLED
  613. }
  614.  
  615. // ===================================================
  616. // ---------------------- Stocks ---------------------
  617. stock PlaySound(id, const sound[])
  618. {
  619. if(equal(sound[strlen(sound)-4], ".mp3")) client_cmd(id, "mp3 play ^"sound/%s^"", sound)
  620. else client_cmd(id, "spk ^"%s^"", sound)
  621. }
  622.  
  623. stock client_printc(index, const text[], any:...)
  624. {
  625. static szMsg[128]; vformat(szMsg, sizeof(szMsg) - 1, text, 3)
  626.  
  627. replace_all(szMsg, sizeof(szMsg) - 1, "!g", "^x04")
  628. replace_all(szMsg, sizeof(szMsg) - 1, "!n", "^x01")
  629. replace_all(szMsg, sizeof(szMsg) - 1, "!t", "^x03")
  630.  
  631. if(!index)
  632. {
  633. for(new i = 0; i < g_MaxPlayers; i++)
  634. {
  635. if(!is_user_connected(i))
  636. continue
  637.  
  638. message_begin(MSG_ONE_UNRELIABLE, g_MsgSayText, _, i);
  639. write_byte(i);
  640. write_string(szMsg);
  641. message_end();
  642. }
  643. } else {
  644. message_begin(MSG_ONE_UNRELIABLE, g_MsgSayText, _, index);
  645. write_byte(index);
  646. write_string(szMsg);
  647. message_end();
  648. }
  649. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement