Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.66 KB | None | 0 0
  1. #pragma semicolon 1
  2.  
  3. #include <sourcemod>
  4. #include <store>
  5. #include <scp>
  6. #include <smjansson>
  7. //#include <colors>
  8. //#include <morecolors_store>
  9.  
  10. StringMap CTrie;
  11.  
  12.  
  13. enum ChatColor
  14. {
  15. String:ChatColorName[STORE_MAX_NAME_LENGTH],
  16. String:ChatColorText[64]
  17. }
  18.  
  19. new g_chatcolors[1024][ChatColor];
  20. new g_chatcolorCount = 0;
  21.  
  22. new g_clientChatColors[MAXPLAYERS+1] = { -1, ... };
  23.  
  24. new Handle:g_chatcolorsNameIndex = INVALID_HANDLE;
  25. new bool:g_databaseInitialized = false;
  26.  
  27. public Plugin:myinfo =
  28. {
  29. name = "[Store] Chat Color",
  30. author = "Panduh, csgo fix by wyd3x",
  31. description = "Chat Colors component for [Store]",
  32. version = "1.2",
  33. url = "http://forums.alliedmodders.com/"
  34. };
  35.  
  36. /**
  37. * Plugin is loading.
  38. */
  39. public OnPluginStart()
  40. {
  41. LoadTranslations("common.phrases");
  42. LoadTranslations("store.phrases");
  43. CTrie = InitColorTrie();
  44. Store_RegisterItemType("chatcolor_csgo", OnEquip, LoadItem);
  45. Store_RegisterPluginModule("[Store] Chat Colors", "Chat Colors component for [Store]", "sm_chatcolor_version", "1.2");
  46. }
  47.  
  48. /**
  49. * Called when a new API library is loaded.
  50. */
  51. public OnLibraryAdded(const String:name[])
  52. {
  53. if (StrEqual(name, "store-inventory"))
  54. {
  55. Store_RegisterItemType("chatcolor_csgo", OnEquip, LoadItem);
  56. }
  57. }
  58.  
  59. public Store_OnDatabaseInitialized()
  60. {
  61. g_databaseInitialized = true;
  62. }
  63.  
  64. /**
  65. * Called once a client is authorized and fully in-game, and
  66. * after all post-connection authorizations have been performed.
  67. *
  68. * This callback is gauranteed to occur on all clients, and always
  69. * after each OnClientPutInServer() call.
  70. *
  71. * @param client Client index.
  72. * @noreturn
  73. */
  74. public OnClientPostAdminCheck(client)
  75. {
  76. g_clientChatColors[client] = -1;
  77. if (!g_databaseInitialized)
  78. return;
  79.  
  80. Store_GetEquippedItemsByType(Store_GetClientAccountID(client), "chatcolor_csgo", Store_GetClientLoadout(client), OnGetPlayerChatColor, GetClientSerial(client));
  81. }
  82.  
  83. public Store_OnClientLoadoutChanged(client)
  84. {
  85. g_clientChatColors[client] = -1;
  86. Store_GetEquippedItemsByType(Store_GetClientAccountID(client), "chatcolor_csgo", Store_GetClientLoadout(client), OnGetPlayerChatColor, GetClientSerial(client));
  87. }
  88.  
  89. public Store_OnReloadItems()
  90. {
  91. if (g_chatcolorsNameIndex != INVALID_HANDLE)
  92. CloseHandle(g_chatcolorsNameIndex);
  93.  
  94. g_chatcolorsNameIndex = CreateTrie();
  95. g_chatcolorCount = 0;
  96. }
  97.  
  98. public OnGetPlayerChatColor(titles[], count, any:serial)
  99. {
  100. new client = GetClientFromSerial(serial);
  101.  
  102. if (client == 0)
  103. return;
  104.  
  105. for (new index = 0; index < count; index++)
  106. {
  107. decl String:itemName[STORE_MAX_NAME_LENGTH];
  108. Store_GetItemName(titles[index], itemName, sizeof(itemName));
  109.  
  110. new chatcolor = -1;
  111. if (!GetTrieValue(g_chatcolorsNameIndex, itemName, chatcolor))
  112. {
  113. PrintToChat(client, "%s%t", STORE_PREFIX, "No item attributes");
  114. continue;
  115. }
  116.  
  117. g_clientChatColors[client] = chatcolor;
  118. break;
  119. }
  120. }
  121.  
  122. public LoadItem(const String:itemName[], const String:attrs[])
  123. {
  124. strcopy(g_chatcolors[g_chatcolorCount][ChatColorName], STORE_MAX_NAME_LENGTH, itemName);
  125.  
  126. SetTrieValue(g_chatcolorsNameIndex, g_chatcolors[g_chatcolorCount][ChatColorName], g_chatcolorCount);
  127.  
  128. new Handle:json = json_load(attrs);
  129.  
  130. json_object_get_string(json, "color", g_chatcolors[g_chatcolorCount][ChatColorText], 64);
  131. new size = STORE_MAX_NAME_LENGTH;
  132. ReplaceString(g_chatcolors[g_chatcolorCount][ChatColorText], size, "{", "");
  133. ReplaceString(g_chatcolors[g_chatcolorCount][ChatColorText], size, "}", "");
  134. new String:value[STORE_MAX_NAME_LENGTH];
  135. CTrie.GetString(g_chatcolors[g_chatcolorCount][ChatColorText], value, STORE_MAX_NAME_LENGTH);
  136. Format(g_chatcolors[g_chatcolorCount][ChatColorText], size, "%s", value);
  137.  
  138. //ReplaceString(g_chatcolors[g_chatcolorCount][ChatColorText], 10, "/", "\\", false);
  139.  
  140. CloseHandle(json);
  141.  
  142. g_chatcolorCount++;
  143. }
  144.  
  145. public Store_ItemUseAction:OnEquip(client, itemId, bool:equipped)
  146. {
  147. new String:name[32];
  148. Store_GetItemName(itemId, name, sizeof(name));
  149.  
  150. if (equipped)
  151. {
  152. g_clientChatColors[client] = -1;
  153.  
  154. decl String:displayName[STORE_MAX_DISPLAY_NAME_LENGTH];
  155. Store_GetItemDisplayName(itemId, displayName, sizeof(displayName));
  156.  
  157. PrintToChat(client, "%s%t", STORE_PREFIX, "Unequipped item", displayName);
  158.  
  159. return Store_UnequipItem;
  160. }
  161. else
  162. {
  163. new chatcolor = -1;
  164. if (!GetTrieValue(g_chatcolorsNameIndex, name, chatcolor))
  165. {
  166. PrintToChat(client, "%s%t", STORE_PREFIX, "No item attributes");
  167. return Store_DoNothing;
  168. }
  169.  
  170. g_clientChatColors[client] = chatcolor;
  171.  
  172. decl String:displayName[STORE_MAX_DISPLAY_NAME_LENGTH];
  173. Store_GetItemDisplayName(itemId, displayName, sizeof(displayName));
  174.  
  175. PrintToChat(client, "%s%t", STORE_PREFIX, "Equipped item", displayName);
  176.  
  177. return Store_EquipItem;
  178. }
  179. }
  180.  
  181. public Action:OnChatMessage(&author, Handle:recipients, String:name[], String:message[])
  182. {
  183. if (g_clientChatColors[author] != -1)
  184. {
  185. new MaxMessageLength = MAXLENGTH_MESSAGE - strlen(name) - 5;
  186. Format(message, MaxMessageLength, "%s%s", g_chatcolors[g_clientChatColors[author]][ChatColorText], message, g_chatcolors[g_clientChatColors[author]][ChatColorText]);
  187. return Plugin_Changed;
  188. }
  189.  
  190. return Plugin_Continue;
  191. }
  192.  
  193. stock StringMap InitColorTrie() {
  194. StringMap hTrie = CreateTrie();
  195. hTrie.SetString("blue", "\x0C");
  196. hTrie.SetString("green", "\x04");
  197. hTrie.SetString("light-blue", "\x0A");
  198. hTrie.SetString("light-red", "\x07");
  199. hTrie.SetString("light-yellow", "\x09");
  200. hTrie.SetString("orange", "\x10");
  201. hTrie.SetString("pink", "\x0E");
  202. hTrie.SetString("red", "\x02");
  203. hTrie.SetString("turquoise", "\x05");
  204. hTrie.SetString("yellow-green", "\x06");
  205. return hTrie;
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement