Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.21 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdktools>
  3. #include <ASteambot>
  4. #include <morecolors>
  5. #include <base64>
  6.  
  7. // meaning of credits - the method to buy vip and mod
  8.  
  9. #pragma dynamic 131072
  10.  
  11. #define PLUGIN_AUTHOR "Arkarr, edited by kekes"
  12. #define PLUGIN_VERSION "3.8"
  13. #define MODULE_NAME "[ASteambot - Donation]"
  14.  
  15. #define ITEM_ID "itemID"
  16. #define ITEM_NAME "itemName"
  17. #define ITEM_VALUE "itemValue"
  18. #define ITEM_DONATED "itemDonated"
  19.  
  20. #define GAMEID_TF2 440
  21. #define GAMEID_CSGO 730
  22. #define GAMEID_DOTA2 570
  23.  
  24. #define QUERY_CREATE_T_CLIENTS "CREATE TABLE IF NOT EXISTS `t_client` (`id` INT(10) NOT NULL AUTO_INCREMENT, `client_steamid` VARCHAR(30) NOT NULL, `client_balance` DOUBLE NOT NULL, `timeleft` INT(11) NOT NULL, `ismod` BOOLEAN NOT NULL DEFAULT '0', `isvip` BOOLEAN NOT NULL DEFAULT '0', PRIMARY KEY (`id`)) COLLATE='latin1_swedish_ci' ENGINE=MyISAM;"
  25. #define QUERY_SELECT_MONEY "SELECT `client_balance` FROM `t_client` WHERE `client_steamid`= '%s'"
  26. #define QUERY_INSERT_MONEY "INSERT INTO `t_client` (`client_steamid`,`client_balance`, `timeleft`, `ismod`, `isvip`) VALUES ('%s', '%.2f', '%i', '%s', '%s');"
  27. #define QUERY_UPDATE_MONEY "UPDATE `t_client` SET `client_balance`= '%.2f' WHERE `client_steamid`= '%s'"
  28. #define QUERY_UPDATE_MOD "UPDATE `t_client` SET `ismod`= '%s' WHERE `client_steamid`= '%s'"
  29. #define QUERY_UPDATE_VIP "UPDATE `t_client` SET `isvip`= '%s' WHERE `client_steamid`= '%s'"
  30. #define QUERY_UPDATE_TIME "UPDATE `t_client` SET `timeleft`= '%s' WHERE `client_steamid`= '%s'"
  31.  
  32. #define CONFIG_OverridPrices "configs/ASDonation_Prices.ini"
  33. #define CONFIG_ExcludedItems "configs/ASDonation_ExcludedItems.ini"
  34. #define CONFIG_IncludedItems "configs/ASDonation_IncludedItems.ini"
  35.  
  36. #define UPDATE_URL "https://raw.githubusercontent.com/Arkarr/SourcemodASteambot/master/Updater/ASteambot_Donation.txt"
  37.  
  38. int lastSelectedGame[MAXPLAYERS + 1];
  39.  
  40. float minValue;
  41. float maxValue;
  42. float valueMultiplier;
  43. float tradeValue[MAXPLAYERS + 1], tempz[MAXPLAYERS+1];
  44. int g_iDaysLeft[MAXPLAYERS + 1];
  45. bool boughtMod[MAXPLAYERS + 1], boughtVIP[MAXPLAYERS + 1];
  46.  
  47. Handle DATABASE;
  48. Handle CVAR_MaxDonation;
  49. Handle CVAR_MinDonation;
  50. //Handle CVAR_RCONOnSucess;
  51. Handle CVAR_ValueMultiplier;
  52. Handle TRIE_OverridedPrices;
  53. Handle ARRAY_ExcludedItems;
  54. Handle ARRAY_IncludedItems;
  55. Handle ARRAY_ItemsTF2[MAXPLAYERS + 1];
  56. Handle ARRAY_ItemsCSGO[MAXPLAYERS + 1];
  57. Handle ARRAY_ItemsDOTA2[MAXPLAYERS + 1];
  58.  
  59. //Release note
  60. /*
  61. *Updater update file location
  62. */
  63.  
  64. public Plugin myinfo =
  65. {
  66. name = "[ANY] ASteambot Donation",
  67. author = PLUGIN_AUTHOR,
  68. description = "Allow player to do donation to the server with steam items.",
  69. version = PLUGIN_VERSION,
  70. url = "http://www.sourcemod.net"
  71. };
  72.  
  73. public OnAllPluginsLoaded()
  74. {
  75. //Ensure that there is not late-load problems.
  76. if (LibraryExists("ASteambot"))
  77. ASteambot_RegisterModule("ASteambot_Donation");
  78. else
  79. SetFailState("ASteambot_Core is not present/not running. Plugin can't continue !");
  80. }
  81.  
  82. public void OnPluginStart()
  83. {
  84. CVAR_ValueMultiplier = CreateConVar("sm_asteambot_donation_vm", "100", "By how much the steam market prices have to be multiplied to get a correct ammount of store credits.", _, true, 1.0);
  85. CVAR_MaxDonation = CreateConVar("sm_asteambot_max_donation_value", "500", "If the trade offer's value is higher than this one, the player will get additional credits like this : (([TRADE OFFER VALUE] - [THIS CVAR])/[TRADE OFFER VALUE])*[TRADE OFFER VALUE], view : https://forums.alliedmods.net/showpost.php?p=2559559&postcount=16");
  86. CVAR_MinDonation = CreateConVar("sm_asteambot_min_donation_value", "50", "Any trade offer's value below this cvar is automatically refused.");
  87. //CVAR_RCONOnSucess = CreateConVar("sm_asteambot_trade_sucess_rcon", "sm_say \"Hello World\";sm_slap [PLAYER] 0", "The following command will be executed on trade sucess. [PLAYER] is the steamID of the one who made the trade.");
  88.  
  89. RegConsoleCmd("sm_pay", CMD_Donate, "Create a trade offer with ASteambot as donation.");
  90. RegConsoleCmd("sm_friend", CMD_AsFriends, "Send a steam invite to the player.");
  91. RegConsoleCmd("sm_daysleft", CMD_Left);
  92.  
  93. RegAdminCmd("sm_asdonation_reload_config", CMD_ReloadConfig, ADMFLAG_CONFIG, "Reload the configs file");
  94.  
  95. LoadOverridedPrices();
  96.  
  97. AutoExecConfig(true, "asteambot_donation", "asteambot");
  98.  
  99. LoadTranslations("ASteambot.donation.phrases");
  100.  
  101. for(int i = 1; i <= MaxClients; i++)
  102. {
  103. if (IsClientInGame(i))
  104. {
  105. OnClientPostAdminCheck(i);
  106. }
  107. }
  108. }
  109.  
  110. public Action CMD_Left(int client, int args)
  111. {
  112. ReplyToCommand(client, "[SM] You have %d days until your access will be removed.", g_iDaysLeft[client]);
  113. }
  114.  
  115. public OnPluginEnd()
  116. {
  117. ASteambot_RemoveModule();
  118. }
  119.  
  120. public void OnClientPostAdminCheck(int client)
  121. {
  122. SQL_LoadUser(client);
  123. if (g_iDaysLeft[client])
  124. {
  125. AdminId ID = GetUserAdmin(client);
  126. if (boughtVIP[client] && !GetAdminFlag(ID, Admin_Reservation) && !GetAdminFlag(ID, Admin_Custom2))
  127. {
  128. if (ID == INVALID_ADMIN_ID)
  129. {
  130. ID = CreateAdmin("");
  131. SetUserAdmin(client, ID, true);
  132. SetAdminFlag(ID, Admin_Reservation, true);
  133. SetAdminFlag(ID, Admin_Custom2, true);
  134. }
  135. }
  136. }
  137. }
  138.  
  139. public void SQL_LoadUser(int client)
  140. {
  141. if (DATABASE)
  142. {
  143. char strAuth[32], strQuery[128];
  144. GetClientAuthId(client, AuthId_Steam2, strAuth, 32);
  145. FormatEx(strQuery, 128, "SELECT * FROM `t_client` WHERE `client_steamid` = '%s';", strAuth);
  146. SQL_TQuery(DATABASE, SQLQuery_LoadUser, strQuery, GetClientUserId(client));
  147. }
  148. }
  149.  
  150. public void SQLQuery_LoadUser(Handle hOwner, Handle hQuery, char[] strError, int Data)
  151. {
  152. int client = GetClientOfUserId(Data);
  153. if (!client)
  154. {
  155. return;
  156. }
  157. if (strcmp(strError,"",false) != 0)
  158. {
  159. LogError("SQL Error ON SQLQuery_LoadUser: %s", strError);
  160. return;
  161. }
  162. if (SQL_FetchRow(hQuery) && SQL_GetRowCount(hQuery))
  163. {
  164. int iTime = SQL_FetchInt(hQuery, 3);
  165. int iCalc = iTime / 86400 - GetTime({0,0}) / 86400;
  166. if (iTime && iCalc <= 0 && iTime != -8239)
  167. {
  168. g_iDaysLeft[client] = 0;
  169. boughtMod[client] = false;
  170. boughtVIP[client] = false;
  171. char strAuth[32];
  172. char strQuery[128];
  173. GetClientAuthId(client, AuthId_Steam2, strAuth, 32);
  174. FormatEx(strQuery, 128, "DELETE FROM `t_client` WHERE `client_steamid` = '%s'", strAuth);
  175. SQL_TQuery(DATABASE, SQLQuery_Update, strQuery, view_as<any>(0), view_as<DBPriority>(1));
  176. }
  177. else
  178. {
  179. g_iDaysLeft[client] = iCalc;
  180. boughtMod[client] = SQL_FetchInt(hQuery, 4) == 1 ? true : false;
  181. boughtVIP[client] = SQL_FetchInt(hQuery, 5) == 1 ? true : false;
  182. }
  183. }
  184. }
  185.  
  186. public void OnConfigsExecuted()
  187. {
  188. char value[45];
  189.  
  190. GetConVarString(CVAR_MinDonation, value, sizeof(value));
  191. minValue = StringToFloat(value);
  192. GetConVarString(CVAR_MaxDonation, value, sizeof(value));
  193. maxValue = StringToFloat(value);
  194.  
  195. valueMultiplier = GetConVarFloat(CVAR_ValueMultiplier);
  196.  
  197. SQL_TConnect(GotDatabase, "ASteambot");
  198. }
  199.  
  200. public void LoadOverridedPrices()
  201. {
  202. TRIE_OverridedPrices = CreateTrie();
  203. ARRAY_ExcludedItems = CreateArray(100);
  204. ARRAY_IncludedItems = CreateArray(100);
  205.  
  206. char path[PLATFORM_MAX_PATH], line[128];
  207. BuildPath(Path_SM, path, PLATFORM_MAX_PATH, CONFIG_OverridPrices);
  208. Handle fileHandle = OpenFile(path, "r");
  209.  
  210. PrintToServer(path);
  211.  
  212. while(!IsEndOfFile(fileHandle) && ReadFileLine(fileHandle, line, sizeof(line)))
  213. {
  214. char bit[2][64];
  215. if(StrContains(line, "=") != -1 && ExplodeString(line, "=", bit, sizeof bit, sizeof bit[]) == 2)
  216. SetTrieValue(TRIE_OverridedPrices, bit[0], (StringToFloat(bit[1])/GetConVarFloat(CVAR_ValueMultiplier)));
  217. }
  218.  
  219. CloseHandle(fileHandle);
  220.  
  221. BuildPath(Path_SM, path, PLATFORM_MAX_PATH, CONFIG_ExcludedItems);
  222. fileHandle = OpenFile(path, "r");
  223.  
  224. while(!IsEndOfFile(fileHandle) && ReadFileLine(fileHandle, line, sizeof(line)))
  225. {
  226. ReplaceString(line, sizeof(line), "\n", "");
  227. ReplaceString(line, sizeof(line), "\r", "");
  228. ReplaceString(line, sizeof(line), "\t", "");
  229. PushArrayString(ARRAY_ExcludedItems, line);
  230. }
  231.  
  232. CloseHandle(fileHandle);
  233.  
  234. BuildPath(Path_SM, path, PLATFORM_MAX_PATH, CONFIG_IncludedItems);
  235. fileHandle = OpenFile(path, "r");
  236.  
  237. while(!IsEndOfFile(fileHandle) && ReadFileLine(fileHandle, line, sizeof(line)))
  238. {
  239. ReplaceString(line, sizeof(line), "\n", "");
  240. ReplaceString(line, sizeof(line), "\r", "");
  241. ReplaceString(line, sizeof(line), "\t", "");
  242.  
  243. PushArrayString(ARRAY_IncludedItems, line);
  244. }
  245.  
  246. CloseHandle(fileHandle);
  247. }
  248.  
  249. public void OnClientConnected(int client)
  250. {
  251. lastSelectedGame[client] = -1;
  252. }
  253.  
  254. public Action CMD_Donate(int client, int args)
  255. {
  256. if(client == 0)
  257. {
  258. PrintToServer("%s %t", MODULE_NAME, "ingame");
  259. return Plugin_Continue;
  260. }
  261.  
  262. if(!ASteambot_IsConnected())
  263. {
  264. CPrintToChat(client, "%s {fullred}%t", MODULE_NAME, "ASteambot_NotConnected");
  265. return Plugin_Handled;
  266. }
  267.  
  268. CPrintToChat(client, "%s {green}%t", MODULE_NAME, "TradeOffer_WaitItems");
  269.  
  270. tradeValue[client] = 0.0;
  271.  
  272. char clientSteamID[40];
  273. GetClientAuthId(client, AuthId_Steam2, clientSteamID, sizeof(clientSteamID));
  274.  
  275. ASteambot_SendMesssage(AS_SCAN_INVENTORY, clientSteamID);
  276.  
  277. return Plugin_Handled;
  278. }
  279.  
  280. public Action CMD_ReloadConfig(int client, int args)
  281. {
  282. LoadOverridedPrices();
  283.  
  284. if(client != 0)
  285. CPrintToChat(client, "%s {green}Done !", MODULE_NAME);
  286. else
  287. PrintToServer("%s Done !", MODULE_NAME);
  288.  
  289. return Plugin_Handled;
  290. }
  291.  
  292. public Action CMD_AsFriends(int client, int args)
  293. {
  294. char clientSteamID[30];
  295.  
  296. GetClientAuthId(client, AuthId_Steam2, clientSteamID, sizeof(clientSteamID));
  297. ASteambot_SendMesssage(AS_FRIEND_INVITE, clientSteamID);
  298.  
  299. CPrintToChat(client, "%s {green}%t", MODULE_NAME, "Steam_FriendInvitSend");
  300.  
  301. return Plugin_Handled;
  302. }
  303.  
  304. public int ASteambot_Message(AS_MessageType MessageType, char[] message, const int messageSize)
  305. {
  306. char query[300];
  307.  
  308. char[][] parts = new char[4][messageSize];
  309. char steamID[40];
  310.  
  311. ExplodeString(message, "/", parts, 4, messageSize);
  312. Format(steamID, sizeof(steamID), parts[0]);
  313.  
  314. int client = ASteambot_FindClientBySteam64(steamID);
  315.  
  316. if(MessageType == AS_NOT_FRIENDS && client != -1)
  317. {
  318. CPrintToChat(client, "%s {green}%t", MODULE_NAME, "Steam_NotFriends");
  319. }
  320. else if(MessageType == AS_SCAN_INVENTORY && client != -1)
  321. {
  322. CPrintToChat(client, "%s {green}%t", MODULE_NAME, "TradeOffer_InventoryScanned");
  323. PrepareInventories(client, parts[1], parts[2], parts[3], messageSize)
  324. }
  325. else if (MessageType == AS_TRADEOFFER_DECLINED && client != -1)
  326. {
  327. CPrintToChat(client, "%s {red}%t", MODULE_NAME, "TradeOffer_Declined");
  328. }
  329. else if(MessageType == AS_TRADEOFFER_SUCCESS)
  330. {
  331. char[] offerID = new char[messageSize];
  332. char[] value = new char[messageSize];
  333.  
  334. Format(offerID, messageSize, parts[1]);
  335. Format(value, messageSize, parts[2]);
  336.  
  337. float credits = StringToFloat(value);
  338.  
  339. if(credits > maxValue)
  340. credits += ((credits - maxValue) / credits) * credits;
  341.  
  342. Handle pack = CreateDataPack();
  343. WritePackString(pack, steamID);
  344. WritePackFloat(pack, credits);
  345. Format(query, sizeof(query), QUERY_SELECT_MONEY, steamID);
  346. SQL_TQuery(DATABASE, GetPlayerCredits, query, pack);
  347.  
  348. CPrintToChat(client, "%s {green}%t", MODULE_NAME, "TradeOffer_Success", credits);
  349. }
  350. }
  351.  
  352. public void SQLQuery_Update(Handle hOwner, Handle hQuery, char[] strError, any iData)
  353. {
  354. if (strcmp(strError,"",false) != 0)
  355. {
  356. LogError("SQL Error ON SQLQuery_Update: %s", strError);
  357. }
  358. }
  359.  
  360. public void PrepareInventories(int client, const char[] tf2, const char[] csgo, const char[] dota2, int charSize)
  361. {
  362. int tf2_icount = CountCharInString(tf2, ',')+1;
  363. int csgo_icount = CountCharInString(csgo, ',')+1;
  364. int dota2_icount = CountCharInString(dota2, ',')+1;
  365.  
  366. ARRAY_ItemsTF2[client] = CreateArray(tf2_icount);
  367. ARRAY_ItemsCSGO[client] = CreateArray(csgo_icount);
  368. ARRAY_ItemsDOTA2[client] = CreateArray(dota2_icount);
  369.  
  370. bool inv_tf2 = CreateInventory(client, tf2, tf2_icount, ARRAY_ItemsTF2[client]);
  371. bool inv_csgo = CreateInventory(client, csgo, csgo_icount, ARRAY_ItemsCSGO[client]);
  372. bool inv_dota2 = CreateInventory(client, dota2, dota2_icount, ARRAY_ItemsDOTA2[client]);
  373.  
  374. CreateInventory(client, tf2, tf2_icount, ARRAY_ItemsTF2[client]);
  375. CreateInventory(client, csgo, csgo_icount, ARRAY_ItemsCSGO[client]);
  376. CreateInventory(client, dota2, dota2_icount, ARRAY_ItemsDOTA2[client]);
  377.  
  378. if(!inv_tf2 && !inv_csgo && !inv_dota2)
  379. {
  380. lastSelectedGame[client] = -1;
  381.  
  382. CPrintToChat(client, "%s {fullred}%t", MODULE_NAME, "TradeOffer_InventoryError");
  383. }
  384. else
  385. {
  386. lastSelectedGame[client] = -1;
  387.  
  388. DisplayInventorySelectMenu(client);
  389. }
  390. }
  391.  
  392. public bool IsItemAllowed(const char[] itemName)
  393. {
  394. bool excluded = false;
  395. bool allowed = false;
  396.  
  397. for (int i = 0; i < GetArraySize(ARRAY_ExcludedItems); i++)
  398. {
  399. if(excluded)
  400. continue;
  401.  
  402. char excludedItem[100];
  403. GetArrayString(ARRAY_ExcludedItems, i, excludedItem, sizeof(excludedItem));
  404.  
  405. if(!StrEqual(excludedItem, "*"))
  406. {
  407. if(StrContains(itemName, excludedItem, false) != -1)
  408. {
  409. excluded = true;
  410. }
  411. }
  412. else
  413. {
  414. excluded = true;
  415. }
  416. }
  417.  
  418. if(excluded)
  419. {
  420. for (int i = 0; i < GetArraySize(ARRAY_IncludedItems); i++)
  421. {
  422. if(allowed)
  423. continue;
  424.  
  425. char includedItem[100];
  426. GetArrayString(ARRAY_IncludedItems, i, includedItem, sizeof(includedItem));
  427.  
  428. if(!StrEqual(includedItem, "*"))
  429. {
  430. if(StrContains(itemName, includedItem, false) != -1)
  431. {
  432. return true;
  433. }
  434. }
  435. }
  436. }
  437.  
  438. return !excluded;
  439. }
  440.  
  441. public bool CreateInventory(int client, const char[] strinventory, int itemCount, Handle inventory)
  442. {
  443. if(!StrEqual(strinventory, "EMPTY"))
  444. {
  445. char[][] items = new char[itemCount][60];
  446.  
  447. ExplodeString(strinventory, ",", items, itemCount, 60);
  448.  
  449. for (int i = 0; i < itemCount; i++)
  450. {
  451. char itemInfos[3][100];
  452. ExplodeString(items[i], "=", itemInfos, sizeof itemInfos, sizeof itemInfos[]);
  453.  
  454. Handle TRIE_Item = CreateTrie();
  455. SetTrieString(TRIE_Item, ITEM_ID, itemInfos[0]);
  456. SetTrieString(TRIE_Item, ITEM_NAME, itemInfos[1]);
  457.  
  458. if(IsItemAllowed(itemInfos[1]))
  459. {
  460. float value;
  461. if(GetTrieValue(TRIE_OverridedPrices, itemInfos[1], value))
  462. SetTrieValue(TRIE_Item, ITEM_VALUE, value);
  463. else
  464. SetTrieValue(TRIE_Item, ITEM_VALUE, StringToFloat(itemInfos[2]));
  465.  
  466. SetTrieValue(TRIE_Item, ITEM_DONATED, 0);
  467. PushArrayCell(inventory, TRIE_Item);
  468. }
  469. }
  470. }
  471. else if(StrEqual(strinventory, "ERROR"))
  472. {
  473. CPrintToChat(client, "%s {fullred}%t", MODULE_NAME, "TradeOffer_ItemsError", strinventory);
  474. return false;
  475. }
  476.  
  477. return true;
  478. }
  479.  
  480. public int CountCharInString(const char[] str, int c)
  481. {
  482. int i = 0, count = 0;
  483.  
  484. while (str[i] != '\0')
  485. {
  486. if (str[i++] == c)
  487. count++;
  488. }
  489.  
  490. return count;
  491. }
  492.  
  493. public void DisplayInventorySelectMenu(int client)
  494. {
  495. CPrintToChat(client, "%s {green}%t", MODULE_NAME, "TradeOffer_SelectItems");
  496. CPrintToChat(client, "%s {yellow}%t", MODULE_NAME, "TradeOffer_Explication", minValue, maxValue);
  497.  
  498. Handle menu = CreateMenu(MenuHandle_MainMenu);
  499. SetMenuTitle(menu, "Select an inventory :");
  500.  
  501. if(GetArraySize(ARRAY_ItemsTF2[client]) > 0)
  502. AddMenuItem(menu, "tf2", "Team Fortress 2");
  503. else
  504. AddMenuItem(menu, "tf2", "Team Fortress 2", ITEMDRAW_DISABLED);
  505.  
  506. if(GetArraySize(ARRAY_ItemsCSGO[client]) > 0)
  507. AddMenuItem(menu, "csgo", "Counter-Strike: Global Offensive");
  508. else
  509. AddMenuItem(menu, "csgo", "Counter-Strike: Global Offensive", ITEMDRAW_DISABLED);
  510.  
  511. if(GetArraySize(ARRAY_ItemsDOTA2[client]) > 0)
  512. AddMenuItem(menu, "dota2", "Dota 2");
  513. else
  514. AddMenuItem(menu, "dota2", "Dota 2", ITEMDRAW_DISABLED);
  515.  
  516.  
  517. SetMenuExitButton(menu, true);
  518. DisplayMenu(menu, client, MENU_TIME_FOREVER);
  519. }
  520.  
  521. public void DisplayInventory(int client, int inventoryID)
  522. {
  523. Handle inventory;
  524. if(lastSelectedGame[client] == -1)
  525. {
  526. if(inventoryID == 0)
  527. {
  528. inventory = ARRAY_ItemsTF2[client];
  529. lastSelectedGame[client] = GAMEID_TF2;
  530. }
  531. else if(inventoryID == 1)
  532. {
  533. inventory = ARRAY_ItemsCSGO[client];
  534. lastSelectedGame[client] = GAMEID_CSGO;
  535. }
  536. else if(inventoryID == 2)
  537. {
  538. inventory = ARRAY_ItemsDOTA2[client];
  539. lastSelectedGame[client] = GAMEID_DOTA2;
  540. }
  541. }
  542. else
  543. {
  544. inventory = GetLastInventory(client);
  545. }
  546.  
  547.  
  548. Handle menu = CreateMenu(MenuHandle_ItemSelect);
  549. SetMenuTitle(menu, "Select items to donate (%.2f$ / %.2f$) :", tradeValue[client], minValue);
  550.  
  551. char itemName[30];
  552. char itemID[30];
  553. float itemValue;
  554. int itemDonated;
  555.  
  556. for (int i = 0; i < GetArraySize(inventory); i++)
  557. {
  558. Handle trie = GetArrayCell(inventory, i);
  559. GetTrieString(trie, ITEM_NAME, itemName, sizeof(itemName));
  560. GetTrieString(trie, ITEM_ID, itemID, sizeof(itemID));
  561. GetTrieValue(trie, ITEM_VALUE, itemValue);
  562. GetTrieValue(trie, ITEM_DONATED, itemDonated);
  563.  
  564. char menuItem[35];
  565.  
  566. Format(menuItem, sizeof(menuItem), "%.2f$ - %s", GetItemValue(itemValue), itemName);
  567.  
  568. if(itemDonated == 0)
  569. AddMenuItem(menu, itemID, menuItem);
  570. else
  571. AddMenuItem(menu, itemID, menuItem, ITEMDRAW_DISABLED);
  572. }
  573.  
  574. AddMenuItem(menu, "OK", "OK!");
  575.  
  576. SetMenuExitButton(menu, true);
  577. DisplayMenu(menu, client, MENU_TIME_FOREVER);
  578. }
  579.  
  580. public int MenuHandle_MainMenu(Handle menu, MenuAction action, int client, int itemIndex)
  581. {
  582. if (action == MenuAction_Select)
  583. {
  584. if (itemIndex == 0) //TF2
  585. DisplayInventory(client, 0);
  586. else if (itemIndex == 1) //CSGO
  587. DisplayInventory(client, 1);
  588. else if (itemIndex == 2) //DOTA2 ---> DEFINE !!!
  589. DisplayInventory(client, 2);
  590. }
  591. else if (action == MenuAction_End)
  592. {
  593. CloseHandle(menu);
  594. }
  595. }
  596.  
  597. public int MenuHandle_ItemSelect(Handle menu, MenuAction action, int client, int itemIndex)
  598. {
  599. if (action == MenuAction_Select)
  600. {
  601. char description[32];
  602. char itemID[32];
  603. float itemValue;
  604. GetMenuItem(menu, itemIndex, description, sizeof(description));
  605.  
  606. if(StrEqual(description, "OK"))
  607. {
  608. int selected = 0;
  609. Handle inventory = GetLastInventory(client);
  610. for (int i = 0; i < GetArraySize(inventory); i++)
  611. {
  612. Handle trie = GetArrayCell(inventory, i);
  613. GetTrieValue(trie, ITEM_DONATED, selected);
  614.  
  615. if(selected == 1)
  616. break;
  617. }
  618.  
  619. if(selected == 0)
  620. {
  621. CPrintToChat(client, "%s {green}%t", MODULE_NAME, "TradeOffer_NoItems");
  622. }
  623. else if(minValue <= tradeValue[client])
  624. {
  625. CreateTradeOffer(client, tradeValue[client]);
  626. CPrintToChat(client, "%s {green}%t", MODULE_NAME, "TradeOffer_Created");
  627. }
  628. else
  629. {
  630. CPrintToChat(client, "%s {green}%t", MODULE_NAME, "TradeOffer_ValueTooLow", minValue);
  631. }
  632. }
  633. else
  634. {
  635. Handle inventory = GetLastInventory(client);
  636. for (int i = 0; i < GetArraySize(inventory); i++)
  637. {
  638. Handle trie = GetArrayCell(inventory, i);
  639. GetTrieString(trie, ITEM_ID, itemID, sizeof(itemID));
  640. GetTrieValue(trie, ITEM_VALUE, itemValue);
  641.  
  642. if(StrEqual(itemID, description))
  643. {
  644. SetTrieValue(trie, ITEM_DONATED, 1);
  645. tradeValue[client] += GetItemValue(itemValue);
  646. DisplayInventory(client, -1);
  647. return;
  648. }
  649. }
  650. }
  651. }
  652. else if (action == MenuAction_End)
  653. {
  654. CloseHandle(menu);
  655. }
  656. }
  657.  
  658. public Handle GetLastInventory(int client)
  659. {
  660. switch(lastSelectedGame[client])
  661. {
  662. case GAMEID_TF2: return ARRAY_ItemsTF2[client];
  663. case GAMEID_CSGO: return ARRAY_ItemsCSGO[client];
  664. case GAMEID_DOTA2: return ARRAY_ItemsDOTA2[client];
  665. }
  666.  
  667. return INVALID_HANDLE;
  668. }
  669.  
  670. public void CreateTradeOffer(int client, float tv)
  671. {
  672. char itemID[32];
  673. int selected = 0;
  674. Handle items = CreateArray(30);
  675.  
  676. Handle inventory = GetLastInventory(client);
  677. for (int i = 0; i < GetArraySize(inventory); i++)
  678. {
  679. Handle trie = GetArrayCell(inventory, i);
  680. GetTrieValue(trie, ITEM_DONATED, selected);
  681.  
  682. if(selected == 1)
  683. {
  684. GetTrieString(trie, ITEM_ID, itemID, sizeof(itemID));
  685. PushArrayString(items, itemID);
  686. }
  687. }
  688.  
  689. ASteambot_CreateTradeOffer(client, items, INVALID_HANDLE, tv);
  690. }
  691.  
  692. public void GetPlayerCredits(Handle db, Handle results, const char[] error, any data)
  693. {
  694. char steamID[30];
  695.  
  696. ResetPack(data);
  697. ReadPackString(data, steamID, sizeof(steamID));
  698. float value = ReadPackFloat(data);
  699.  
  700. int client = ASteambot_FindClientBySteam64(steamID);
  701.  
  702. if (results == INVALID_HANDLE)
  703. {
  704. SetFailState(error);
  705. return;
  706. }
  707.  
  708. char query[300];
  709. if (!SQL_FetchRow(results))
  710. {
  711. Format(query, sizeof(query), QUERY_INSERT_MONEY, steamID, value, "0", "0", "0");
  712. DBFastQuery(query);
  713. }
  714. else
  715. {
  716. value += SQL_FetchFloat(results, 0);
  717. Format(query, sizeof(query), QUERY_UPDATE_MONEY, value, steamID);
  718. DBFastQuery(query);
  719. }
  720.  
  721. if (client != -1)
  722. CPrintToChat(client, "%s {green}%t", MODULE_NAME, "TradeOffer_Success", value);
  723. tempz[client] = value;
  724. DoMenu(client);
  725. }
  726.  
  727. // VIP //
  728.  
  729. void DoMenu(int client)
  730. {
  731. Menu menu = CreateMenu(SelectAccess);
  732. SetMenuTitle(menu, "Select access to receive\nYou donated %.2f$.\n*You can't abort a payment*:", tempz[client]);
  733. AddMenuItem(menu, "4.2/30", "Moderator - 1 Month (4.20$)", tempz[client] < 4.2 ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT);
  734. AddMenuItem(menu, "7/60", "Moderator - 2 Month (7$)", tempz[client] < 7 ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT);
  735. AddMenuItem(menu, "9.8/90", "Moderator - 3 Month (9.80$)", tempz[client] < 9.8 ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT);
  736. AddMenuItem(menu, "12.6/120", "Moderator - 4 Month (12.60$)", tempz[client] < 12.6 ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT);
  737. AddMenuItem(menu, "15.75/182", "Moderator - 6 Month (15.75$)", tempz[client] < 15.75 ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT);
  738. AddMenuItem(menu, "21/365", "Moderator - 1 Year (21.00$)", tempz[client] < 21 ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT);
  739. AddMenuItem(menu, "0.21/7", "VIP - 1 Week (0.21$)", tempz[client] < 0.21 ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT);
  740. AddMenuItem(menu, "0.53/30", "VIP - 1 Month (0.53$)", tempz[client] < 0.53 ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT);
  741. AddMenuItem(menu, "0.81/60", "VIP - 2 Month (0.81$)", tempz[client] < 0.81 ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT);
  742. AddMenuItem(menu, "1.05/90", "VIP - 3 Month (1.05$)", tempz[client] < 1.05 ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT);
  743. AddMenuItem(menu, "1.4/120", "VIP - 4 Month (1.40$)", tempz[client] < 1.4 ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT);
  744. AddMenuItem(menu, "1.93/182", "VIP - 6 Month (1.93$)", tempz[client] < 1.93 ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT);
  745. AddMenuItem(menu, "4.2/365", "VIP - 1 Year (4.20$)", tempz[client] < 4.2 ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT);
  746. DisplayMenu(menu, client, 30);
  747. }
  748.  
  749. public int SelectAccess(Handle menu, MenuAction action, int client, int param2)
  750. {
  751. if (action == MenuAction_Select)
  752. {
  753. char sInfo[32], display[64];
  754. char parts[2][6]; // parts[0] - the price, parts[1] - time
  755. GetMenuItem(menu, param2, sInfo, 32, _, display, 64);
  756. Handle pack = CreateDataPack();
  757. ExplodeString(sInfo, "/", parts, 2, 6, true);
  758. WritePackCell(pack, client);
  759.  
  760. if(display[0] == 'M')
  761. {
  762. WritePackCell(pack, 1);
  763. WritePackCell(pack, StringToInt(parts[1]) * 86400 + GetTime({0,0}));
  764. WritePackFloat(pack, StringToFloat(parts[0]));
  765. }
  766. else
  767. {
  768. WritePackCell(pack, 2);
  769. WritePackCell(pack, StringToInt(parts[1]) * 86400 + GetTime({0,0}));
  770. WritePackFloat(pack, StringToFloat(parts[0]));
  771. }
  772.  
  773. char query[300], steamID[32];
  774. GetClientAuthId(client, AuthId_Steam2, steamID, 32);
  775. Format(query, sizeof(query), QUERY_SELECT_MONEY, steamID);
  776. SQL_TQuery(DATABASE, RemoveCredits, query, pack);
  777. }
  778. else if (action == MenuAction_End)
  779. {
  780. delete menu;
  781. }
  782. }
  783.  
  784. public void RemoveCredits(Handle db, Handle results, const char[] error, any data)
  785. {
  786. char steamID[30];
  787. ResetPack(data);
  788. int client = ReadPackCell(data);
  789. int type = ReadPackCell(data);
  790. int time = ReadPackCell(data);
  791. float myItem = ReadPackFloat(data);
  792. GetClientAuthId(client, AuthId_Steam2, steamID, sizeof(steamID));
  793. float setCredits = SQL_FetchFloat(results, 0) - myItem;
  794.  
  795. if (results == INVALID_HANDLE)
  796. {
  797. SetFailState(error);
  798. return;
  799. }
  800.  
  801. char query[300];
  802. tempz[client] = setCredits;
  803. Format(query, sizeof(query), QUERY_UPDATE_MONEY, setCredits, steamID);
  804. DBFastQuery(query);
  805. Format(query, sizeof(query), QUERY_UPDATE_TIME, time, steamID);
  806. DBFastQuery(query);
  807. if(type == 1)
  808. Format(query, sizeof(query), QUERY_UPDATE_MOD, "1", steamID);
  809. else
  810. Format(query, sizeof(query), QUERY_UPDATE_VIP, "1", steamID);
  811. DBFastQuery(query);
  812. }
  813.  
  814. // END OF VIP //
  815.  
  816. public void GotDatabase(Handle owner, Handle hndl, const char[] error, any data)
  817. {
  818. if (hndl == INVALID_HANDLE)
  819. {
  820. SetFailState(error);
  821. }
  822. else
  823. {
  824. DATABASE = hndl;
  825.  
  826. if (DBFastQuery(QUERY_CREATE_T_CLIENTS))
  827. PrintToServer("%s %t", MODULE_NAME, "Database_Success");
  828. }
  829. }
  830.  
  831. public bool DBFastQuery(const char[] sql)
  832. {
  833. char error[400];
  834. SQL_FastQuery(DATABASE, sql);
  835. if (SQL_GetError(DATABASE, error, sizeof(error)))
  836. {
  837. PrintToServer("%s %t", MODULE_NAME, "Database_Failure", error);
  838. return false;
  839. }
  840.  
  841. return true;
  842. }
  843.  
  844. public float GetItemValue(float itemBaseValue)
  845. {
  846. valueMultiplier = GetConVarFloat(CVAR_ValueMultiplier);
  847. return itemBaseValue * valueMultiplier;
  848. }
  849.  
  850. stock bool IsValidClientASteambot(int client)
  851. {
  852. if (client <= 0)return false;
  853. if (client > MaxClients)return false;
  854. if (!IsClientConnected(client))return false;
  855. return IsClientInGame(client);
  856. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement