michaelrw

Untitled

Dec 6th, 2017
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.20 KB | None | 0 0
  1. /*  CS:GO Weapons&Knives SourceMod Plugin
  2.  *
  3.  *  Copyright (C) 2017 Kağan 'kgns' Üstüngel
  4.  *
  5.  * This program is free software: you can redistribute it and/or modify it
  6.  * under the terms of the GNU General Public License as published by the Free
  7.  * Software Foundation, either version 3 of the License, or (at your option)
  8.  * any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful, but WITHOUT
  11.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12.  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License along with
  15.  * this program. If not, see http://www.gnu.org/licenses/.
  16.  */
  17.  
  18. #include <sourcemod>
  19. #include <sdktools>
  20. #include <sdkhooks>
  21. #include <cstrike>
  22. #include <PTaH>
  23.  
  24. #pragma semicolon 1
  25. #pragma newdecls required
  26.  
  27. #include "weapons/globals.sp"
  28. #include "weapons/forwards.sp"
  29. #include "weapons/hooks.sp"
  30. #include "weapons/helpers.sp"
  31. #include "weapons/database.sp"
  32. #include "weapons/config.sp"
  33. #include "weapons/menus.sp"
  34.  
  35. public Plugin myinfo =
  36. {
  37.     name = "Weapons & Knives",
  38.     author = "kgns | pluginal.com",
  39.     description = "All in one custom weapon management",
  40.     version = "1.1.1",
  41.     url = "https://pluginal.com"
  42. };
  43.  
  44. public void OnPluginStart()
  45. {
  46.     LoadTranslations("weapons.phrases");
  47.    
  48.     g_Cvar_DBConnection             = CreateConVar("sm_weapons_db_connection",          "storage-local",    "Database connection name in databases.cfg to use");
  49.     g_Cvar_TablePrefix              = CreateConVar("sm_weapons_table_prefix",           "",                 "Prefix for database table (example: 'xyz_')");
  50.     g_Cvar_ChatPrefix               = CreateConVar("sm_weapons_chat_prefix",            "[wasdzone]",       "Prefix for chat messages");
  51.     g_Cvar_KnifeStatTrakMode        = CreateConVar("sm_weapons_knife_stattrak_mode",    "0",                "0: All knives show the same StatTrak counter (total knife kills) 1: Each type of knife shows its own separate StatTrak counter");
  52.     g_Cvar_EnableFloat              = CreateConVar("sm_weapons_enable_float",           "1",                "Enable/Disable weapon float options");
  53.     g_Cvar_EnableNameTag            = CreateConVar("sm_weapons_enable_nametag",         "1",                "Enable/Disable name tag options");
  54.     g_Cvar_EnableStatTrak           = CreateConVar("sm_weapons_enable_stattrak",        "1",                "Enable/Disable StatTrak options");
  55.     g_Cvar_FloatIncrementSize       = CreateConVar("sm_weapons_float_increment_size",   "0.05",             "Increase/Decrease by value for weapon float");
  56.     g_Cvar_EnableWeaponOverwrite    = CreateConVar("sm_weapons_enable_overwrite",       "1",                "Enable/Disable players overwriting other players' weapons (picked up from the ground) by using !ws command");
  57.     g_Cvar_GracePeriod              = CreateConVar("sm_weapons_grace_period",           "0",                "Grace period in terms of seconds counted after round start for allowing the use of !ws command. 0 means no restrictions");
  58.    
  59.     AutoExecConfig(true, "weapons");
  60.    
  61.     RegConsoleCmd("buyammo1", CommandWeaponSkins);
  62.     RegConsoleCmd("sm_skins", CommandWeaponSkins);
  63.     RegConsoleCmd("buyammo2", CommandKnife);
  64.     RegConsoleCmd("sm_getknife", CommandKnife);
  65.     RegConsoleCmd("sm_nametag", CommandNameTag);
  66.     RegConsoleCmd("sm_wslang", CommandWSLang);
  67.    
  68.     PTaH(PTaH_GiveNamedItemPre, Hook, GiveNamedItemPre);
  69.     PTaH(PTaH_GiveNamedItem, Hook, GiveNamedItem);
  70.    
  71.     AddCommandListener(ChatListener, "say");
  72.     AddCommandListener(ChatListener, "say2");
  73.     AddCommandListener(ChatListener, "say_team");
  74. }
  75.  
  76. public Action CommandWeaponSkins(int client, int args)
  77. {
  78.     if (IsValidClient(client))
  79.     {
  80.         if(g_iGracePeriod > 0 && g_iRoundStartTime + g_iGracePeriod < GetTime() && IsPlayerAlive(client))
  81.         {
  82.             PrintToChat(client, " %s \x02%t", g_ChatPrefix, "GracePeriod", g_iGracePeriod);
  83.         }
  84.         else
  85.         {
  86.             CreateMainMenu(client).Display(client, GetRemainingGracePeriodSeconds());
  87.         }
  88.     }
  89.     return Plugin_Handled;
  90. }
  91.  
  92. public Action CommandKnife(int client, int args)
  93. {
  94.     if (IsValidClient(client))
  95.     {
  96.         CreateKnifeMenu(client).Display(client, GetRemainingGracePeriodSeconds());
  97.     }
  98.     return Plugin_Handled;
  99. }
  100.  
  101. public Action CommandWSLang(int client, int args)
  102. {
  103.     if (IsValidClient(client))
  104.     {
  105.         CreateLanguageMenu(client).Display(client, GetRemainingGracePeriodSeconds());
  106.     }
  107.     return Plugin_Handled;
  108. }
  109.  
  110. public Action CommandNameTag(int client, int args)
  111. {
  112.     if(!g_bEnableNameTag)
  113.     {
  114.         ReplyToCommand(client, " %s \x02%T", g_ChatPrefix, "NameTagDisabled", client);
  115.         return Plugin_Handled;
  116.     }
  117.     ReplyToCommand(client, " %s \x04%T", g_ChatPrefix, "NameTagNew", client);
  118.     return Plugin_Handled;
  119. }
  120.  
  121. void SetWeaponProps(int client, int entity)
  122. {
  123.     int index = GetWeaponIndex(entity);
  124.     if (index > -1 && g_iSkins[client][index] != 0)
  125.     {
  126.         SetEntProp(entity, Prop_Send, "m_iItemIDLow", -1);
  127.         SetEntProp(entity, Prop_Send, "m_nFallbackPaintKit", g_iSkins[client][index] == -1 ? GetRandomSkin(client, index) : g_iSkins[client][index]);
  128.         SetEntPropFloat(entity, Prop_Send, "m_flFallbackWear", !g_bEnableFloat || g_fFloatValue[client][index] == 0.0 ? 0.000001 : g_fFloatValue[client][index] == 1.0 ? 0.999999 : g_fFloatValue[client][index]);
  129.         SetEntProp(entity, Prop_Send, "m_nFallbackSeed", GetRandomInt(0, 8192));
  130.         if(!IsKnife(entity))
  131.         {
  132.             if(g_bEnableStatTrak)
  133.             {
  134.                 SetEntProp(entity, Prop_Send, "m_nFallbackStatTrak", g_iStatTrak[client][index] == 1 ? g_iStatTrakCount[client][index] : -1);
  135.                 SetEntProp(entity, Prop_Send, "m_iEntityQuality", g_iStatTrak[client][index] == 1 ? 9 : 0);
  136.             }
  137.         }
  138.         else
  139.         {
  140.             if(g_bEnableStatTrak)
  141.             {
  142.                 SetEntProp(entity, Prop_Send, "m_nFallbackStatTrak", g_iStatTrak[client][index] == 0 ? -1 : g_iKnifeStatTrakMode == 0 ? GetTotalKnifeStatTrakCount(client) : g_iStatTrakCount[client][index]);
  143.             }
  144.             SetEntProp(entity, Prop_Send, "m_iEntityQuality", 3);
  145.         }
  146.         if (g_bEnableNameTag && strlen(g_NameTag[client][index]) > 0)
  147.         {
  148.             SetEntDataString(entity, FindSendPropInfo("CBaseAttributableItem", "m_szCustomName"), g_NameTag[client][index], 128);
  149.         }
  150.         SetEntProp(entity, Prop_Send, "m_iAccountID", g_iSteam32[client]);
  151.         SetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity", client);
  152.         SetEntPropEnt(entity, Prop_Send, "m_hPrevOwner", -1);
  153.     }
  154. }
  155.  
  156. void RefreshWeapon(int client, int index, bool defaultKnife = false)
  157. {
  158.     int size = GetEntPropArraySize(client, Prop_Send, "m_hMyWeapons");
  159.    
  160.     for (int i = 0; i < size; i++)
  161.     {
  162.         int weapon = GetEntPropEnt(client, Prop_Send, "m_hMyWeapons", i);
  163.         if (IsValidWeapon(weapon))
  164.         {
  165.             bool isKnife = IsKnife(weapon);
  166.             if ((!defaultKnife && GetWeaponIndex(weapon) == index) || (isKnife && (defaultKnife || IsKnifeClass(g_WeaponClasses[index]))))
  167.             {
  168.                 if(!g_bOverwriteEnabled)
  169.                 {
  170.                     int previousOwner;
  171.                     if ((previousOwner = GetEntPropEnt(weapon, Prop_Send, "m_hPrevOwner")) != INVALID_ENT_REFERENCE && previousOwner != client)
  172.                     {
  173.                         return;
  174.                     }
  175.                 }
  176.                
  177.                 int clip = -1;
  178.                 int ammo = -1;
  179.                 int offset = -1;
  180.                 int reserve = -1;
  181.                
  182.                 if (!isKnife)
  183.                 {
  184.                     offset = FindDataMapInfo(client, "m_iAmmo") + (GetEntProp(weapon, Prop_Data, "m_iPrimaryAmmoType") * 4);
  185.                     ammo = GetEntData(client, offset);
  186.                     clip = GetEntProp(weapon, Prop_Send, "m_iClip1");
  187.                     reserve = GetEntProp(weapon, Prop_Send, "m_iPrimaryReserveAmmoCount");
  188.                 }
  189.                
  190.                 RemovePlayerItem(client, weapon);
  191.                 AcceptEntityInput(weapon, "KillHierarchy");
  192.                
  193.                 if (!isKnife)
  194.                 {
  195.                     weapon = GivePlayerItem(client, g_WeaponClasses[index]);
  196.                     if (clip != -1)
  197.                     {
  198.                         SetEntProp(weapon, Prop_Send, "m_iClip1", clip);
  199.                     }
  200.                     if (reserve != -1)
  201.                     {
  202.                         SetEntProp(weapon, Prop_Send, "m_iPrimaryReserveAmmoCount", reserve);
  203.                     }
  204.                     if (offset != -1 && ammo != -1)
  205.                     {
  206.                         DataPack pack;
  207.                         CreateDataTimer(0.1, ReserveAmmoTimer, pack);
  208.                         pack.WriteCell(GetClientUserId(client));
  209.                         pack.WriteCell(offset);
  210.                         pack.WriteCell(ammo);
  211.                     }
  212.                 }
  213.                 else
  214.                 {
  215.                     GivePlayerItem(client, "weapon_knife");
  216.                 }
  217.                 break;
  218.             }
  219.         }
  220.     }
  221. }
  222.  
  223. public Action ReserveAmmoTimer(Handle timer, DataPack pack)
  224. {
  225.     ResetPack(pack);
  226.     int clientIndex = GetClientOfUserId(pack.ReadCell());
  227.     int offset = pack.ReadCell();
  228.     int ammo = pack.ReadCell();
  229.    
  230.     if(clientIndex > 0 && IsClientInGame(clientIndex))
  231.     {
  232.         SetEntData(clientIndex, offset, ammo, 4, true);
  233.     }
  234. }
Advertisement
Add Comment
Please, Sign In to add comment