Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma semicolon 1
- #include <sourcemod>
- #include <sdktools>
- #include <sdkhooks>
- #pragma semicolon 1
- #pragma newdecls required
- #define MAX_FRAMECHECK 10
- bool bPistol[MAXPLAYERS+1] = {true, ...};
- bool bPistolFix[MAXPLAYERS+1] = {true, ...};
- public void OnPluginStart()
- {
- HookEvent("player_use", Event_Ammo_Pickup);
- HookEvent("item_pickup", OnItemPickup);
- RegConsoleCmd("sm_view", iViewAmmo);
- RegConsoleCmd("sm_v", iViewAmmo);
- AutoExecConfig(true, "l4d_pistol_reloading");
- }
- public Action iViewAmmo(int client, int args)
- {
- int iCurrentWeapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
- if(!IsValidEntity(iCurrentWeapon)) return Plugin_Handled;
- char iEntName[56];
- GetEdictClassname(iCurrentWeapon, iEntName, sizeof(iEntName));
- if (StrEqual(iEntName, "weapon_pistol"))
- {
- int AmmoSmgType = GetEntProp(iCurrentWeapon, Prop_Data, "m_iPrimaryAmmoType");
- if (AmmoSmgType == -1) return Plugin_Continue;
- int AmmoSmg = GetEntProp(client, Prop_Send, "m_iAmmo", _, AmmoSmgType);
- PrintHintText(client, "Патроны - %i", AmmoSmg);
- }
- return Plugin_Handled;
- }
- public void OnEntityCreated(int entity, const char[] classname)
- {
- SDKHook(entity, SDKHook_SpawnPost, ItemSpawnPost);
- }
- public void ItemSpawnPost(int entity)
- {
- if (IsValidEntity(entity))
- {
- SDKUnhook(entity, SDKHook_SpawnPost, ItemSpawnPost);
- SDKHook(entity, SDKHook_Use, OnPlayerUse);
- }
- }
- public Action OnPlayerUse(int iEnt, int client, int caller, UseType type, float value)
- {
- if(IsValidEdict(iEnt))
- {
- char iEntName[56];
- GetEdictClassname(iEnt, iEntName, sizeof(iEntName));
- if (StrEqual(iEntName, "weapon_ammo_spawn", false))
- {
- int iSmg = GetPlayerWeaponSlot(client, 0);
- if (iSmg == -1) return Plugin_Continue;
- int Weapon = GetPlayerWeaponSlot(client, 1);
- if (Weapon == -1) return Plugin_Continue;
- char sWeaponEx[56];
- GetEdictClassname(iEnt, sWeaponEx, sizeof(sWeaponEx));
- if(StrEqual(sWeaponEx, "weapon_smg_silenced") || StrEqual(sWeaponEx, "weapon_smg") || StrEqual(sWeaponEx, "weapon_smg_mp5"))
- {
- char sWeapon[32];
- GetEntityClassname(Weapon, sWeapon, sizeof(sWeapon));
- int AmmoType = GetEntProp(Weapon, Prop_Data, "m_iPrimaryAmmoType");
- if(AmmoType == -1) return Plugin_Continue;
- int Ammo = GetEntProp(client, Prop_Send, "m_iAmmo", _, AmmoType);
- if (StrEqual(sWeapon, "weapon_pistol"))
- {
- int AmmoSmgType = GetEntProp(iSmg, Prop_Data, "m_iPrimaryAmmoType");
- if (AmmoSmgType == -1) return Plugin_Continue;
- int AmmoSmg = GetEntProp(client, Prop_Send, "m_iAmmo", _, AmmoSmgType);
- SetEntProp(client, Prop_Send, "m_iAmmo", Ammo + AmmoSmg, _, AmmoSmgType);
- }
- }
- }
- }
- return Plugin_Continue;
- }
- public Action OnItemPickup(Handle event, const char[] name, bool dontBroadcast)
- {
- int client = GetClientOfUserId(GetEventInt(event, "userid"));
- char item[36];
- GetEventString(event, "item", item, sizeof(item));
- if(StrEqual(item ,"grenade_launcher"))
- {
- PrintHintText(client, "Вы можете восполнить гранаты для гранатамёта из стопки патронов.");
- }
- else if(StrEqual(item ,"rifle_m60"))
- {
- PrintHintText(client, "Вы можете восполнить патроны для M60 из стопки патронов.");
- }
- }
- public void ConvarChanged(Handle hCvar, const char[] sOldVal, const char[] sNewVal)
- {
- CvarsChanged();
- }
- public void OnMapStart()
- {
- CvarsChanged();
- }
- void CvarsChanged()
- {
- SetConVarInt(FindConVar("ammo_pistol_max"), 0);
- }
- public void OnClientPostAdminCheck(int client)
- {
- if (IsFakeClient(client)) return;
- bPistol[client] = true;
- bPistolFix[client] = true;
- SDKHook(client, SDKHook_WeaponEquip, Hook_WeaponEquip);
- }
- public Action Hook_WeaponEquip(int client, int weapon)
- {
- if (!IsSurvivor(client) || !bPistolFix[client])
- return;
- bPistolFix[client] = false;
- }
- public void OnGameFrame()
- {
- int iFrameskip = 0;
- iFrameskip = (iFrameskip + 1) % MAX_FRAMECHECK;
- if(iFrameskip != 0 || !IsServerProcessing())
- return;
- for (int client = 1; client <= MaxClients; client++)
- {
- if (!IsSurvivor(client) || !IsPlayerAlive(client) || !IsFakeClient(client))
- continue;
- int Weapon = GetPlayerWeaponSlot(client, 1);
- if (Weapon == -1) continue;
- char sWeapon[32];
- GetEntityClassname(Weapon, sWeapon, sizeof(sWeapon));
- int AmmoType = GetEntProp(Weapon, Prop_Data, "m_iPrimaryAmmoType");
- int Ammo = GetEntProp(client, Prop_Send, "m_iAmmo", _, AmmoType);
- if (StrEqual(sWeapon, "weapon_pistol"))
- {
- if (AmmoType == -1) continue;
- if (Ammo == 0)
- SetEntProp(client, Prop_Send, "m_iAmmo", 15, _, AmmoType);
- }
- if (StrEqual(sWeapon, "weapon_pistol", false) && GetEntProp(Weapon, Prop_Send, "m_hasDualWeapons"))
- {
- if (AmmoType == -1) continue;
- if (Ammo == 0)
- {
- SetEntProp(client, Prop_Send, "m_iAmmo", 30, _, AmmoType);
- }
- }
- if (StrEqual(sWeapon, "weapon_pistol_magnum", false))
- {
- SetEntProp(client, Prop_Send, "m_iAmmo", 8, _, AmmoType);
- }
- }
- }
- public Action Event_Ammo_Pickup(Event event, const char[] name, bool dontBroadcast)
- {
- int client = GetClientOfUserId(event.GetInt("userid"));
- if (!IsSurvivor(client) || !IsPlayerAlive(client)) return;
- int AmmoPile = event.GetInt("targetid");
- if (!IsValidEntity(AmmoPile)) return;
- char sWeapon[32];
- GetEntityClassname(AmmoPile, sWeapon, sizeof(sWeapon));
- if (!StrEqual(sWeapon, "weapon_ammo_spawn", false))
- return;
- int Weapon = GetPlayerWeaponSlot(client, 1);
- if (Weapon == -1) return;
- GetEntityClassname(Weapon, sWeapon, sizeof(sWeapon));
- if (!(StrEqual(sWeapon, "weapon_pistol", false) || StrEqual(sWeapon, "weapon_pistol_magnum", false)))
- return;
- float cPos[3];
- GetEntPropVector(client, Prop_Data, "m_vecAbsOrigin", cPos);
- float aPos[3];
- GetEntPropVector(AmmoPile, Prop_Data, "m_vecAbsOrigin", aPos);
- if (GetVectorDistance(cPos, aPos) <= 100)
- {
- bPistol[client] = true;
- int AmmoType = GetEntProp(Weapon, Prop_Data, "m_iPrimaryAmmoType");
- if (AmmoType == -1) return;
- int Clip = GetEntProp(Weapon, Prop_Send, "m_iClip1");
- if (StrEqual(sWeapon, "weapon_pistol", false) && GetEntProp(Weapon, Prop_Send, "m_hasDualWeapons"))
- {
- SetEntProp(Weapon, Prop_Send, "m_iClip1", Clip);
- SetEntProp(client, Prop_Send, "m_iAmmo", 150, _, AmmoType);
- }
- else if (StrEqual(sWeapon, "weapon_pistol", false))
- {
- SetEntProp(Weapon, Prop_Send, "m_iClip1", Clip);
- SetEntProp(client, Prop_Send, "m_iAmmo", 150, _, AmmoType);
- }
- if (StrEqual(sWeapon, "weapon_pistol_magnum", false))
- {
- SetEntProp(Weapon, Prop_Send, "m_iClip1", Clip);
- SetEntProp(client, Prop_Send, "m_iAmmo", 32, _, AmmoType);
- }
- }
- }
- stock bool IsValidAdmin(int client)
- {
- if (GetUserFlagBits(client) & ADMFLAG_ROOT) return true;
- return false;
- }
- stock bool IsValidClient(int client)
- {
- if (client > 0 && client <= MaxClients && IsClientInGame(client)) return true;
- return false;
- }
- stock bool IsSpectator(int client)
- {
- if (client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 1) return true;
- return false;
- }
- stock bool IsSurvivor(int client)
- {
- if (client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2) return true;
- return false;
- }
- stock bool IsInfected(int client)
- {
- if (client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 3) return true;
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement