Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <reapi>
  4. #include <shopapi>
  5. #include <paint_marker_api>
  6.  
  7. #pragma semicolon 1
  8.  
  9. new const PLUGIN_VERSION[] = "1.1";
  10.  
  11. #define GetCvarDesc(%0) fmt("%L", LANG_SERVER, %0)
  12.  
  13. new ShopItem:g_iItem;
  14.  
  15. enum (<<= 1)
  16. {
  17. RESET_FLAG_DISCONNECTED = 1,
  18. RESET_FLAG_KILLED = 2,
  19. RESET_FLAG_ROUND_START
  20. };
  21.  
  22. new g_iResetFlags = (RESET_FLAG_DISCONNECTED|RESET_FLAG_KILLED|RESET_FLAG_ROUND_START);
  23.  
  24. public plugin_init()
  25. {
  26. register_plugin("Shop: Paint Marker", PLUGIN_VERSION, "w0w");
  27. register_dictionary("shop_paint_marker.txt");
  28.  
  29. RegisterHookChain(RG_CSGameRules_RestartRound, "refwd_NewRound_Post", true);
  30. RegisterHookChain(RG_CBasePlayer_Killed, "refwd_PlayerKilled_Post", true);
  31.  
  32. new pCvarCost = create_cvar("shop_paint_marker_cost", "50", FCVAR_NONE, GetCvarDesc("SHOP_CVAR_PAINT_MARKER_COST"), true, 0.0);
  33.  
  34. new pCvarFlags = create_cvar("shop_paint_marker_reset_flags", "abc", FCVAR_NONE, GetCvarDesc("SHOP_CVAR_PAINT_MARKER_RESET_FLAGS"));
  35. hook_cvar_change(pCvarFlags, "hook_CvarChange_ResetFlags");
  36.  
  37. AutoExecConfig(true, "shop_paint_marker", "shop");
  38.  
  39. g_iItem = ShopPushItem(
  40. .name = GetCvarDesc("SHOP_PAINT_MARKER"),
  41. .cost = get_pcvar_num(pCvarCost),
  42. .access = ADMIN_ALL,
  43. .flags = IF_OnlyAlive,
  44. .discount = 0,
  45. .inventory = true,
  46. .strkey = "paint_marker",
  47. .cmd = "shop_paint_marker"
  48. );
  49.  
  50. ShopRegisterEvent(Shop_ItemBuy, "func_BuyItem", .this = true);
  51. }
  52.  
  53. public client_putinserver(id)
  54. {
  55. if(ShopHasUserItem(id, g_iItem))
  56. paint_marker_user_manage(id, true);
  57. }
  58.  
  59. public client_disconnected(id)
  60. {
  61. if(g_iResetFlags & RESET_FLAG_DISCONNECTED)
  62. ShopRemoveUserItem(id, g_iItem);
  63. }
  64.  
  65. public refwd_NewRound_Post()
  66. {
  67. if(g_iResetFlags & RESET_FLAG_ROUND_START)
  68. {
  69. new iPlayers[MAX_PLAYERS], iPlayerCount, iPlayer;
  70. get_players_ex(iPlayers, iPlayerCount, GetPlayers_ExcludeBots|GetPlayers_ExcludeHLTV);
  71.  
  72. for(new i; i < iPlayerCount; i++)
  73. {
  74. iPlayer = iPlayers[i];
  75.  
  76. if(ShopHasUserItem(iPlayer, g_iItem))
  77. {
  78. ShopRemoveUserItem(iPlayer, g_iItem);
  79. paint_marker_user_manage(iPlayer, false);
  80. }
  81. }
  82. }
  83. }
  84.  
  85. public refwd_PlayerKilled_Post(iVictim, iKiller, iGib)
  86. {
  87. if(g_iResetFlags & RESET_FLAG_KILLED && ShopHasUserItem(iVictim, g_iItem))
  88. {
  89. ShopRemoveUserItem(iVictim, g_iItem);
  90. paint_marker_user_manage(iVictim, false);
  91. }
  92. }
  93.  
  94. public func_BuyItem(id, ShopItem:iItem, BuyState:iBuyState)
  95. {
  96. if(iBuyState == Buy_OK)
  97. {
  98. client_print(id, print_center, "%l", "SHOP_BOUGHT_PAINT_MARKER");
  99. paint_marker_user_manage(id, true);
  100. }
  101.  
  102. return SHOP_CONTINUE;
  103. }
  104.  
  105. public func_ItemEnablePressing(id, ShopItem:iItem)
  106. {
  107. if(!ShopHasUserItem(id, iItem) && paint_marker_has_user(id))
  108. return SHOP_BREAK;
  109.  
  110. return SHOP_CONTINUE;
  111. }
  112.  
  113. public hook_CvarChange_ResetFlags(pCvar, const szOldValue[], const szNewValue[])
  114. {
  115. g_iResetFlags = read_flags(szNewValue);
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement