Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // precompiled http://www.mediafire.com/download/09i145l87z7jp8e/%5BL4D2%5D+Prevent+M60+Drop+on+empty+clip.smx
- #include <sourcemod>
- #include <sdktools>
- #pragma semicolon 1
- new g_ActiveWeaponOffset;
- static bool:buttondelay[MAXPLAYERS + 1];
- public Plugin:myinfo =
- {
- name = "[L4D2] Prevent M60 Drop on empty clip",
- author = "DeathChaos25",
- description = "Prevents M60s from getting auto deleted when they run empty as well as fixing other various bugs",
- version = "1.1",
- url = "https://forums.alliedmods.net/showthread.php?t=266485"
- }
- public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
- {
- decl String:s_GameFolder[32];
- GetGameFolderName(s_GameFolder, sizeof(s_GameFolder));
- if (!StrEqual(s_GameFolder, "left4dead2", false))
- {
- strcopy(error, err_max, "This plugin is for Left 4 Dead 2 Only!");
- return APLRes_Failure;
- }
- return APLRes_Success;
- }
- public OnPluginStart()
- {
- g_ActiveWeaponOffset = FindSendPropInfo("CBasePlayer", "m_hActiveWeapon");
- HookEvent("upgrade_incendiary_ammo", Event_AmmoUpgrade);
- HookEvent("upgrade_explosive_ammo", Event_AmmoUpgrade);
- HookEvent("receive_upgrade", Event_AmmoUpgrade);
- }
- public OnGameFrame()
- {
- decl String:weaponclass[128];
- for (new client = 1; client <= MaxClients; client++)
- {
- if (IsSurvivor(client) && IsPlayerAlive(client))
- {
- new ReserveAmmo = GetConVarInt(FindConVar("ammo_m60_max"));
- new weapon = GetPlayerWeaponSlot(client, 0);
- if (IsValidEdict(weapon) && ReserveAmmo > 0)
- {
- new PrimType = GetEntProp(weapon, Prop_Send, "m_iPrimaryAmmoType");
- new ammo = GetEntProp(client, Prop_Send, "m_iAmmo", _, PrimType);
- GetEdictClassname(weapon, weaponclass, sizeof(weaponclass));
- if (StrEqual(weaponclass, "weapon_rifle_m60"))
- {
- SetEntProp(weapon, Prop_Send, "m_iExtraPrimaryAmmo", ammo);
- }
- }
- }
- }
- }
- public Action:Event_AmmoUpgrade(Handle:event, const String:name[], bool:dontBroadcast)
- {
- new client = GetClientOfUserId(GetEventInt(event, "userid"));
- if (!IsSurvivor(client))
- {
- return;
- }
- new weapon = GetPlayerWeaponSlot(client, 0);
- decl String:s_Weapon[32];
- if (IsValidEntity(weapon))
- {
- GetEdictClassname(weapon, s_Weapon, sizeof(s_Weapon));
- }
- if (StrEqual(s_Weapon, "weapon_rifle_m60"))
- {
- new clip = GetEntProp(weapon, Prop_Data, "m_iClip1");
- if (clip == 0)
- {
- SetEntProp(weapon, Prop_Send, "m_nUpgradedPrimaryAmmoLoaded", 150, 1);
- SetEntProp(weapon, Prop_Send, "m_iClip1", 150);
- }
- }
- }
- public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:f_Velocity[3], Float:f_Angles[3], &weapon)
- {
- if (IsSurvivor(client))
- {
- if (buttons & IN_ATTACK)
- {
- decl String:s_Weapon[32];
- weapon = GetEntDataEnt2(client, g_ActiveWeaponOffset);
- if (IsValidEntity(weapon))
- {
- GetEdictClassname(weapon, s_Weapon, sizeof(s_Weapon));
- }
- if (StrEqual(s_Weapon, "weapon_rifle_m60"))
- {
- new clip = GetEntProp(weapon, Prop_Data, "m_iClip1");
- new PrimType = GetEntProp(weapon, Prop_Send, "m_iPrimaryAmmoType");
- new ammo = GetEntProp(client, Prop_Send, "m_iAmmo", _, PrimType);
- new laser = GetEntProp(weapon, Prop_Send, "m_upgradeBitVec");
- if (clip == 0)
- {
- buttons &= ~IN_ATTACK;
- ClientCommand(client, "-reload");
- return Plugin_Changed;
- }
- else if (clip <= 1)
- {
- AcceptEntityInput(weapon, "kill");
- new M60 = CreateEntityByName("weapon_rifle_m60");
- DispatchSpawn(M60);
- EquipPlayerWeapon(client, M60);
- SetEntProp(M60, Prop_Send, "m_iClip1", 0);
- SetEntProp(client, Prop_Send, "m_iAmmo", ammo, _, PrimType);
- SetEntProp(M60, Prop_Send, "m_upgradeBitVec", laser);
- SetEntPropEnt(client, Prop_Data, "m_hActiveWeapon", M60);
- ChangeEdictState(client, FindDataMapOffs(client, "m_hActiveWeapon"));
- //AcceptEntityInput(M60, "Use", client);
- }
- }
- }
- else if (buttons & IN_USE && !buttondelay[client])
- {
- new M60 = GetClientAimTarget(client, false);
- decl String:s_Weapon[32];
- if (IsValidEntity(M60))
- {
- GetEdictClassname(M60, s_Weapon, sizeof(s_Weapon));
- }
- buttondelay[client] = true;
- CreateTimer(2.0, ResetDelay, client);
- if (StrEqual(s_Weapon, "weapon_rifle_m60"))
- {
- EquipPlayerWeapon(client, M60);
- }
- else if (StrEqual(s_Weapon, "weapon_ammo_spawn"))
- {
- new ReserveAmmo = GetConVarInt(FindConVar("ammo_m60_max"));
- weapon = GetPlayerWeaponSlot(client, 0);
- if (IsValidEdict(weapon))
- {
- new PrimType = GetEntProp(weapon, Prop_Send, "m_iPrimaryAmmoType");
- GetEdictClassname(weapon, s_Weapon, sizeof(s_Weapon));
- if (StrEqual(s_Weapon, "weapon_rifle_m60"))
- {
- SetEntProp(client, Prop_Send, "m_iAmmo", ReserveAmmo, _, PrimType);
- GiveHint(client);
- }
- }
- }
- }
- }
- return Plugin_Continue;
- }
- public Action:ResetDelay(Handle:timer, any:client)
- {
- buttondelay[client] = false;
- }
- stock bool:IsSurvivor(client)
- {
- return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2;
- }
- stock GiveHint(client)
- {
- if (IsClientInGame(client) && !IsFakeClient(client) && client > 0)
- {
- decl i_Ent, String:s_TargetName[32], String:s_Message[256], Handle:h_Pack;
- i_Ent = CreateEntityByName("env_instructor_hint");
- FormatEx(s_TargetName, sizeof(s_TargetName), "hint%d", client);
- FormatEx(s_Message, sizeof(s_Message), "You have refueled your M60!");
- ReplaceString(s_Message, sizeof(s_Message), "\n", " ");
- DispatchKeyValue(client, "targetname", s_TargetName);
- DispatchKeyValue(i_Ent, "hint_target", s_TargetName);
- DispatchKeyValue(i_Ent, "hint_timeout", "5");
- DispatchKeyValue(i_Ent, "hint_range", "0.01");
- DispatchKeyValue(i_Ent, "hint_icon_onscreen", "icon_tip");
- DispatchKeyValue(i_Ent, "hint_caption", s_Message);
- DispatchKeyValue(i_Ent, "hint_color", "255 255 255");
- DispatchSpawn(i_Ent);
- AcceptEntityInput(i_Ent, "ShowHint");
- h_Pack = CreateDataPack();
- WritePackCell(h_Pack, client);
- WritePackCell(h_Pack, i_Ent);
- CreateTimer(5.0, RemoveInstructorHint, h_Pack);
- }
- }
- public Action:RemoveInstructorHint(Handle:h_Timer, Handle:h_Pack)
- {
- decl i_Ent, client;
- ResetPack(h_Pack, false);
- client = ReadPackCell(h_Pack);
- i_Ent = ReadPackCell(h_Pack);
- CloseHandle(h_Pack);
- if (!client || !IsClientInGame(client))
- return Plugin_Handled;
- if (IsValidEntity(i_Ent))
- RemoveEdict(i_Ent);
- return Plugin_Continue;
- }
- public Action:L4D2_OnFindScavengeItem(client, &item)
- {
- if (!item)
- {
- decl Float:Origin[3], Float:TOrigin[3];
- new weapon = GetPlayerWeaponSlot(client, 0);
- decl String:class[128];
- if (IsValidEdict(weapon))
- {
- GetEdictClassname(weapon, class, sizeof(class));
- if (StrEqual(class, "weapon_rifle_m60"))
- {
- for (new i = 0; i <= GetMaxEntities(); i++)
- {
- if (IsValidEdict(i))
- {
- GetEdictClassname(i, class, sizeof(class));
- new ReserveAmmo = GetConVarInt(FindConVar("ammo_m60_max"));
- new PrimType = GetEntProp(weapon, Prop_Send, "m_iPrimaryAmmoType");
- new ammo = GetEntProp(client, Prop_Send, "m_iAmmo", _, PrimType);
- if (StrEqual("weapon_ammo_spawn", class) && ReserveAmmo > 0 && ammo < ReserveAmmo)
- {
- GetEntPropVector(i, Prop_Send, "m_vecOrigin", Origin);
- GetEntPropVector(client, Prop_Send, "m_vecOrigin", TOrigin);
- new Float:distance = GetVectorDistance(TOrigin, Origin);
- if (distance < 300)
- {
- item = i;
- return Plugin_Changed;
- }
- }
- }
- }
- }
- }
- }
- return Plugin_Continue;
- }
Advertisement
Add Comment
Please, Sign In to add comment