SHOW:
|
|
- or go back to the newest paste.
| 1 | #pragma semicolon 1 | |
| 2 | #pragma newdecls required | |
| 3 | ||
| 4 | #include <sourcemod> | |
| 5 | #include <sdktools> | |
| 6 | #include <sdkhooks> | |
| 7 | ||
| 8 | #define MAX_FRAMECHECK 10 | |
| 9 | ||
| 10 | bool bPistol[MAXPLAYERS+1] = {true, ...};
| |
| 11 | bool bPistolFix[MAXPLAYERS+1] = {true, ...};
| |
| 12 | ||
| 13 | public void OnPluginStart() | |
| 14 | {
| |
| 15 | - | HookEvent("player_use", Event_Ammo_Pickup);
|
| 15 | + | HookEvent("player_use", Event_Ammo_Pickup);
|
| 16 | - | HookEvent("item_pickup", OnItemPickup);
|
| 16 | + | HookEvent("item_pickup", OnItemPickup);
|
| 17 | - | RegConsoleCmd("sm_ammo", iViewAmmo);
|
| 17 | + | RegConsoleCmd("sm_a", iViewAmmo);
|
| 18 | - | AutoExecConfig(true, "l4d_pistol_reloading"); |
| 18 | + | RegConsoleCmd("a", iViewAmmo);
|
| 19 | AddCommandListener(HookPlayerChat, "say"); | |
| 20 | AutoExecConfig(true, "l4d_pistol_reloading"); | |
| 21 | } | |
| 22 | ||
| 23 | public Action HookPlayerChat(int iClient, const char[] sCommand, int iArgs) | |
| 24 | {
| |
| 25 | if (StrEqual(sCommand, "say") || StrEqual(sCommand, "say_team")) | |
| 26 | {
| |
| 27 | char sArg[2]; | |
| 28 | GetCmdArg(1, sArg, sizeof(sArg)); | |
| 29 | if(strcmp(sArg, "a") == 0) | |
| 30 | {
| |
| 31 | iViewAmmo(iClient, 0); | |
| 32 | return Plugin_Continue; | |
| 33 | } | |
| 34 | } | |
| 35 | return Plugin_Continue; | |
| 36 | } | |
| 37 | ||
| 38 | ||
| 39 | public Action iViewAmmo(int client, int args) | |
| 40 | {
| |
| 41 | int iCurrentWeapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon"); | |
| 42 | if(!IsValidEntity(iCurrentWeapon)) return Plugin_Handled; | |
| 43 | ||
| 44 | char iEntName[56]; | |
| 45 | GetEdictClassname(iCurrentWeapon, iEntName, sizeof(iEntName)); | |
| 46 | if (strcmp(iEntName, "weapon_pistol") == 0 || strcmp(iEntName, "weapon_pistol_magnum") == 0) | |
| 47 | {
| |
| 48 | int AmmoSmgType = GetEntProp(iCurrentWeapon, Prop_Data, "m_iPrimaryAmmoType"); | |
| 49 | if (AmmoSmgType == -1) return Plugin_Continue; | |
| 50 | int AmmoSmg = GetEntProp(client, Prop_Send, "m_iAmmo", _, AmmoSmgType); | |
| 51 | PrintHintText(client, "Патроны - %i", AmmoSmg); | |
| 52 | } | |
| 53 | return Plugin_Handled; | |
| 54 | } | |
| 55 | ||
| 56 | public Action OnItemPickup(Handle event, const char[] name, bool dontBroadcast) | |
| 57 | {
| |
| 58 | int client = GetClientOfUserId(GetEventInt(event, "userid")); | |
| 59 | ||
| 60 | char item[36]; | |
| 61 | GetEventString(event, "item", item, sizeof(item)); | |
| 62 | if(StrEqual(item ,"grenade_launcher")) | |
| 63 | {
| |
| 64 | PrintHintText(client, "Вы можете восполнить гранаты для гранатамёта из стопки патронов."); | |
| 65 | } | |
| 66 | else if(StrEqual(item ,"rifle_m60")) | |
| 67 | {
| |
| 68 | PrintHintText(client, "Вы можете восполнить патроны для M60 из стопки патронов."); | |
| 69 | } | |
| 70 | } | |
| 71 | ||
| 72 | public void ConvarChanged(Handle hCvar, const char[] sOldVal, const char[] sNewVal) | |
| 73 | {
| |
| 74 | CvarsChanged(); | |
| 75 | } | |
| 76 | ||
| 77 | public void OnMapStart() | |
| 78 | {
| |
| 79 | CvarsChanged(); | |
| 80 | } | |
| 81 | ||
| 82 | void CvarsChanged() | |
| 83 | {
| |
| 84 | SetConVarInt(FindConVar("ammo_pistol_max"), 0);
| |
| 85 | } | |
| 86 | ||
| 87 | public void OnClientPostAdminCheck(int client) | |
| 88 | {
| |
| 89 | if (IsFakeClient(client)) return; | |
| 90 | ||
| 91 | bPistol[client] = true; | |
| 92 | bPistolFix[client] = true; | |
| 93 | ||
| 94 | SDKHook(client, SDKHook_WeaponEquip, Hook_WeaponEquip); | |
| 95 | } | |
| 96 | ||
| 97 | public Action Hook_WeaponEquip(int client, int weapon) | |
| 98 | {
| |
| 99 | if (!IsSurvivor(client) || !bPistolFix[client]) | |
| 100 | return; | |
| 101 | ||
| 102 | bPistolFix[client] = false; | |
| 103 | } | |
| 104 | ||
| 105 | public void OnGameFrame() | |
| 106 | {
| |
| 107 | int iFrameskip = 0; | |
| 108 | iFrameskip = (iFrameskip + 1) % MAX_FRAMECHECK; | |
| 109 | if(iFrameskip != 0 || !IsServerProcessing()) | |
| 110 | return; | |
| 111 | ||
| 112 | for (int client = 1; client <= MaxClients; client++) | |
| 113 | {
| |
| 114 | if (!IsSurvivor(client) || !IsPlayerAlive(client) || !IsFakeClient(client)) | |
| 115 | continue; | |
| 116 | ||
| 117 | ||
| 118 | int Weapon = GetPlayerWeaponSlot(client, 1); | |
| 119 | if (Weapon == -1) continue; | |
| 120 | ||
| 121 | char sWeapon[32]; | |
| 122 | GetEntityClassname(Weapon, sWeapon, sizeof(sWeapon)); | |
| 123 | ||
| 124 | int AmmoType = GetEntProp(Weapon, Prop_Data, "m_iPrimaryAmmoType"); | |
| 125 | int Ammo = GetEntProp(client, Prop_Send, "m_iAmmo", _, AmmoType); | |
| 126 | ||
| 127 | if (StrEqual(sWeapon, "weapon_pistol")) | |
| 128 | {
| |
| 129 | if (AmmoType == -1) continue; | |
| 130 | ||
| 131 | if (Ammo == 0) | |
| 132 | SetEntProp(client, Prop_Send, "m_iAmmo", 15, _, AmmoType); | |
| 133 | } | |
| 134 | if (StrEqual(sWeapon, "weapon_pistol", false) && GetEntProp(Weapon, Prop_Send, "m_hasDualWeapons")) | |
| 135 | {
| |
| 136 | if (AmmoType == -1) continue; | |
| 137 | ||
| 138 | if (Ammo == 0) | |
| 139 | {
| |
| 140 | SetEntProp(client, Prop_Send, "m_iAmmo", 30, _, AmmoType); | |
| 141 | } | |
| 142 | } | |
| 143 | if (StrEqual(sWeapon, "weapon_pistol_magnum", false)) | |
| 144 | {
| |
| 145 | SetEntProp(client, Prop_Send, "m_iAmmo", 8, _, AmmoType); | |
| 146 | } | |
| 147 | } | |
| 148 | } | |
| 149 | ||
| 150 | public Action Event_Ammo_Pickup(Event event, const char[] name, bool dontBroadcast) | |
| 151 | {
| |
| 152 | int client = GetClientOfUserId(event.GetInt("userid"));
| |
| 153 | if (!IsSurvivor(client) || !IsPlayerAlive(client)) return; | |
| 154 | ||
| 155 | int AmmoPile = event.GetInt("targetid");
| |
| 156 | if (!IsValidEntity(AmmoPile)) return; | |
| 157 | ||
| 158 | char sWeapon[32]; | |
| 159 | GetEntityClassname(AmmoPile, sWeapon, sizeof(sWeapon)); | |
| 160 | ||
| 161 | if (!StrEqual(sWeapon, "weapon_ammo_spawn", false)) | |
| 162 | return; | |
| 163 | ||
| 164 | int Weapon = GetPlayerWeaponSlot(client, 1); | |
| 165 | if (Weapon == -1) return; | |
| 166 | ||
| 167 | GetEntityClassname(Weapon, sWeapon, sizeof(sWeapon)); | |
| 168 | ||
| 169 | if (!(StrEqual(sWeapon, "weapon_pistol", false) || StrEqual(sWeapon, "weapon_pistol_magnum", false))) | |
| 170 | return; | |
| 171 | ||
| 172 | float cPos[3]; | |
| 173 | GetEntPropVector(client, Prop_Data, "m_vecAbsOrigin", cPos); | |
| 174 | ||
| 175 | float aPos[3]; | |
| 176 | GetEntPropVector(AmmoPile, Prop_Data, "m_vecAbsOrigin", aPos); | |
| 177 | ||
| 178 | if (GetVectorDistance(cPos, aPos) <= 150) | |
| 179 | {
| |
| 180 | bPistol[client] = true; | |
| 181 | ||
| 182 | int AmmoType = GetEntProp(Weapon, Prop_Data, "m_iPrimaryAmmoType"); | |
| 183 | if (AmmoType == -1) return; | |
| 184 | ||
| 185 | int Clip = GetEntProp(Weapon, Prop_Send, "m_iClip1"); | |
| 186 | ||
| 187 | if (StrEqual(sWeapon, "weapon_pistol", false) && GetEntProp(Weapon, Prop_Send, "m_hasDualWeapons")) | |
| 188 | {
| |
| 189 | SetEntProp(Weapon, Prop_Send, "m_iClip1", Clip); | |
| 190 | SetEntProp(client, Prop_Send, "m_iAmmo", 150, _, AmmoType); | |
| 191 | } | |
| 192 | else if (StrEqual(sWeapon, "weapon_pistol", false)) | |
| 193 | {
| |
| 194 | ||
| 195 | SetEntProp(Weapon, Prop_Send, "m_iClip1", Clip); | |
| 196 | SetEntProp(client, Prop_Send, "m_iAmmo", 150, _, AmmoType); | |
| 197 | } | |
| 198 | ||
| 199 | if (StrEqual(sWeapon, "weapon_pistol_magnum", false)) | |
| 200 | {
| |
| 201 | SetEntProp(Weapon, Prop_Send, "m_iClip1", Clip); | |
| 202 | SetEntProp(client, Prop_Send, "m_iAmmo", 32, _, AmmoType); | |
| 203 | } | |
| 204 | } | |
| 205 | } | |
| 206 | ||
| 207 | stock bool IsValidAdmin(int client) | |
| 208 | {
| |
| 209 | if (GetUserFlagBits(client) & ADMFLAG_ROOT) return true; | |
| 210 | return false; | |
| 211 | } | |
| 212 | ||
| 213 | stock bool IsValidClient(int client) | |
| 214 | {
| |
| 215 | if (client > 0 && client <= MaxClients && IsClientInGame(client)) return true; | |
| 216 | return false; | |
| 217 | } | |
| 218 | ||
| 219 | stock bool IsSpectator(int client) | |
| 220 | {
| |
| 221 | if (client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 1) return true; | |
| 222 | return false; | |
| 223 | } | |
| 224 | ||
| 225 | stock bool IsSurvivor(int client) | |
| 226 | {
| |
| 227 | if (client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2) return true; | |
| 228 | return false; | |
| 229 | } | |
| 230 | ||
| 231 | stock bool IsInfected(int client) | |
| 232 | {
| |
| 233 | if (client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 3) return true; | |
| 234 | return false; | |
| 235 | } |