Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma semicolon 1
- #pragma newdecls required
- #include <sourcemod>
- #include <sdktools>
- #include <sdkhooks>
- #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_a", iViewAmmo);
- RegConsoleCmd("a", iViewAmmo);
- AddCommandListener(HookPlayerChat, "say");
- AutoExecConfig(true, "l4d_pistol_reloading");
- }
- public Action HookPlayerChat(int iClient, const char[] sCommand, int iArgs)
- {
- if (StrEqual(sCommand, "say") || StrEqual(sCommand, "say_team"))
- {
- char sArg[2];
- GetCmdArg(1, sArg, sizeof(sArg));
- if(strcmp(sArg, "a") == 0)
- {
- iViewAmmo(iClient, 0);
- return Plugin_Continue;
- }
- }
- return Plugin_Continue;
- }
- 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 (strcmp(iEntName, "weapon_pistol") == 0 || strcmp(iEntName, "weapon_pistol_magnum") == 0)
- {
- 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 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) <= 150)
- {
- 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