Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sourcemod>
- #include <sdktools>
- #define PLUGIN_VERSION "1.5.3"
- public Plugin:myinfo =
- {
- name = "[L4D2] Random Ammunition",
- author = "NoBody",
- description = "Periodically changes the amount of ammo contained in picked up guns",
- version = PLUGIN_VERSION,
- url = ""
- };
- new Handle:glammo = INVALID_HANDLE;
- new Handle:m60ammo = INVALID_HANDLE;
- new Handle:sniperammo = INVALID_HANDLE;
- new Handle:glammo_min = INVALID_HANDLE
- new Handle:m60ammo_min = INVALID_HANDLE
- new Handle:glammo_max = INVALID_HANDLE
- new Handle:glamount_max = INVALID_HANDLE
- new Handle:m60ammo_max = INVALID_HANDLE
- new Handle:m60amount_max = INVALID_HANDLE
- public OnPluginStart()
- {
- HookEvent("player_use", Event_PlayerUse, EventHookMode_Pre);
- HookEvent("item_pickup", Event_ItemPickup, EventHookMode_Pre)
- //HookEvent("weapon_drop", Event_WeaponDrop, EventHookMode_Pre);
- HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
- sniperammo = FindConVar("ammo_m60_max")
- glammo = FindConVar("ammo_grenadelauncher_max")
- glammo_min = CreateConVar("l4d_glammo_min", "1", "Min Grenade Launcher ammo variation", FCVAR_NOTIFY)
- m60ammo_min = CreateConVar("l4d_m60ammo_min", "50", "Min M60 ammo variation", FCVAR_NOTIFY)
- // max ammo (created own convar to avoid conflicts)
- glammo_max = CreateConVar("l4d_glammo_max", "12", "Max Grenade Launcher ammo variation", FCVAR_NOTIFY)
- glamount_max = CreateConVar("l4d_gl_amount_max", "18", "Maximum Grenade Launcher amount of amunition to picked up", FCVAR_NOTIFY)
- m60ammo_max = CreateConVar("l4d_m60ammo_max", "500", "Max M60 ammo variation", FCVAR_NOTIFY)
- m60amount_max = CreateConVar("l4d_m60_amount_max", "500", "Maximum M60 amount of amunition to picked up", FCVAR_NOTIFY)
- AutoExecConfig(true, "l4d2_varyingammo", "sourcemod")
- }
- public Action:Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
- {
- CreateTimer(4.0, GunTimer, TIMER_REPEAT, TIMER_FLAG_NO_MAPCHANGE);
- }
- public Action:GunTimer(Handle:timer)
- {
- static NumPrinted = 0
- if (NumPrinted++ <= 2)
- {
- new m79 = GetRandomInt(0, 8)
- new sniperAwp = GetRandomInt(0, 200)
- SetConVarInt(glammo, m79)
- SetConVarInt(m60ammo, sniperAwp)
- NumPrinted = 0
- }
- return Plugin_Continue
- }
- /*
- public Action:Event_WeaponDrop(Handle:event, const String:name[], bool:dontBroadcast)
- {
- new client = GetClientOfUserId(GetEventInt(event, "userid"));
- if (client == 0 || !IsClientConnected(client) || !IsClientInGame(client) || GetClientTeam(client) != 2) return;
- if (GetPlayerWeaponSlot(client, slot) > 0)
- {
- new String:weapon[32];
- new ammo;
- new clip;
- new upgrade;
- new upammo;
- new ammoOffset = FindSendPropInfo("CTerrorPlayer", "m_iAmmo");
- GetEdictClassname(GetPlayerWeaponSlot(client, slot), weapon, 32);
- if (slot == 0)
- {
- clip = GetEntProp(GetPlayerWeaponSlot(client, 0), Prop_Send, "m_iClip1");
- upgrade = GetEntProp(GetPlayerWeaponSlot(client, 0), Prop_Send, "m_upgradeBitVec");
- upammo = GetEntProp(GetPlayerWeaponSlot(client, 0), Prop_Send, "m_nUpgradedPrimaryAmmoLoaded");
- if (StrEqual(weapon, "weapon_rifle") || StrEqual(weapon, "weapon_rifle_sg552") || StrEqual(weapon, "weapon_rifle_desert") || StrEqual(weapon, "weapon_rifle_ak47"))
- {
- ammo = GetEntData(client, ammoOffset+(12));
- SetEntData(client, ammoOffset+(12), 0);
- }
- else if (StrEqual(weapon, "weapon_smg") || StrEqual(weapon, "weapon_smg_silenced") || StrEqual(weapon, "weapon_smg_mp5"))
- {
- ammo = GetEntData(client, ammoOffset+(20));
- SetEntData(client, ammoOffset+(20), 0);
- }
- else if (StrEqual(weapon, "weapon_pumpshotgun") || StrEqual(weapon, "weapon_shotgun_chrome"))
- {
- ammo = GetEntData(client, ammoOffset+(28));
- SetEntData(client, ammoOffset+(28), 0);
- }
- else if (StrEqual(weapon, "weapon_autoshotgun") || StrEqual(weapon, "weapon_shotgun_spas"))
- {
- ammo = GetEntData(client, ammoOffset+(32));
- SetEntData(client, ammoOffset+(32), 0);
- }
- else if (StrEqual(weapon, "weapon_hunting_rifle"))
- {
- ammo = GetEntData(client, ammoOffset+(36));
- SetEntData(client, ammoOffset+(36), 0);
- }
- else if (StrEqual(weapon, "weapon_sniper_scout") || StrEqual(weapon, "weapon_sniper_military") || StrEqual(weapon, "weapon_sniper_awp"))
- {
- ammo = GetEntData(client, ammoOffset+(40));
- SetEntData(client, ammoOffset+(40), 0);
- }
- else if (StrEqual(weapon, "weapon_grenade_launcher"))
- {
- ammo = GetEntData(client, ammoOffset+(68));
- SetEntData(client, ammoOffset+(68), 0);
- }
- }
- new index = CreateEntityByName(weapon);
- new Float:origin[3];
- GetEntPropVector(client, Prop_Send, "m_vecOrigin", origin);
- origin[2]+=20;
- TeleportEntity(index, origin, NULL_VECTOR, NULL_VECTOR);
- DispatchSpawn(index);
- ActivateEntity(index);
- RemovePlayerItem(client, GetPlayerWeaponSlot(client, slot));
- if (slot == 0)
- {
- SetEntProp(index, Prop_Send, "m_iExtraPrimaryAmmo", ammo);
- SetEntProp(index, Prop_Send, "m_iClip1", clip);
- SetEntProp(index, Prop_Send, "m_upgradeBitVec", upgrade);
- SetEntProp(index, Prop_Send, "m_nUpgradedPrimaryAmmoLoaded", upammo);
- }
- }
- }
- */
- public Event_PlayerUse(Handle:event, const String:name[], bool:dontBroadcast)
- {
- new playerClient = GetClientOfUserId(GetEventInt(event, "userid"));
- new entityId = GetEventInt(event, "targetid");
- decl String:ent_name[64];
- if (IsValidEdict(entityId))
- {
- GetEdictClassname(entityId, ent_name, sizeof(ent_name)); //get the entities name
- if (StrEqual(ent_name, "weapon_ammo_spawn", false))
- {
- new weaponIndex = GetPlayerWeaponSlot(playerClient, 0);
- if(weaponIndex == -1)
- return;
- new String:classname[64];
- GetEdictClassname(weaponIndex, classname, sizeof(classname));
- if(StrEqual(classname, "weapon_rifle_m60"))
- {
- new iClip1 = GetEntProp(weaponIndex, Prop_Send, "m_iClip1");
- new iPrimType = GetEntProp(weaponIndex, Prop_Send, "m_iPrimaryAmmoType");
- SetEntProp(playerClient, Prop_Send, "m_iAmmo", (GetConVarInt(m60amount_max)-iClip1), _, iPrimType);
- }
- else if(StrEqual(classname, "weapon_grenade_launcher"))
- {
- new iClip1 = GetEntProp(weaponIndex, Prop_Send, "m_iClip1");
- new iPrimType = GetEntProp(weaponIndex, Prop_Send, "m_iPrimaryAmmoType");
- SetEntProp(playerClient, Prop_Send, "m_iAmmo", (GetConVarInt(glamount_max)-iClip1), _, iPrimType);
- }
- }
- }
- //CreateTimer(30.0, GunTimer, TIMER_FLAG_NO_MAPCHANGE);
- }
- public Action:Event_ItemPickup(Handle:event, const String:name[], bool:dontBroadcast)
- {
- new client = GetClientOfUserId(GetEventInt(event, "userid"))
- if (!client || !IsClientInGame(client)) return Plugin_Continue;
- decl String:weaponname[128]
- GetEventString(event, "item", weaponname, sizeof(weaponname))
- new targetgun = GetPlayerWeaponSlot(client, 0)
- if (IsValidEdict(targetgun))
- {
- if (StrEqual(weaponname, "rifle_m60", false))
- {
- new ammmo = GetRandomInt(0, 200);
- new M60 = GetRandomInt(GetConVarInt(m60ammo_min), GetConVarInt(m60ammo_max))
- SetConVarInt(sniperammo, M60)
- SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
- }
- else if (StrEqual(weaponname, "grenade_launcher", false))
- {
- new GrenadeLauncher = GetRandomInt(GetConVarInt(glammo_min), GetConVarInt(glammo_max))
- SetConVarInt(glammo, GrenadeLauncher)
- }
- }
- return Plugin_Continue;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement