Code:
#include <sourcemod>
#include <sdktools>
public Plugin:myinfo =
{
name = "L4D2 weapon tier2",
author = "GBR",
description = "",
version = "1.1",
url = ""
}
public OnPluginStart()
{
HookEvent("player_first_spawn", Event_MissionStart);
swapweapons();
giveweapons();
}
public Event_MissionStart(Handle:event, const String:name[], bool:Broadcast)
{
swapweapons();
giveweapons();
}
public giveweapons()
{
new ent;
decl String:wpn[64];
for(new x=1;x<=MaxClients;x++)
{
if(IsClientConnected(x) && IsClientInGame(x) && IsPlayerAlive(x) && GetClientTeam(x)==2)
{
if((ent = GetPlayerWeaponSlot(x, 0))!=-1)
{
GetEdictClassname(ent, wpn, sizeof(wpn));
if(StrContains("weapon_autoshotgun|weapon_shotgun_spas|weapon_rifle|weapon_rifle_ak47|weapon_rifle_desert|weapon_rifle_sg552|weapon_hunting_rifle|weapon_sniper_awp|weapon_sniper_military|weapon_sniper_scout",wpn, false) == -1)
{
new weaponIndex;
while((weaponIndex = GetPlayerWeaponSlot(x, 0))!=-1)
{
RemovePlayerItem(x, weaponIndex);
RemoveEdict(weaponIndex);
}
GiveWeapon(x);
}
}else
{
GiveWeapon(x);
}
}
}
}
stock GiveWeapon(client)
{
switch(GetRandomInt(0,9))
{
case 0: BypassAndExecuteCommand(client, "give", "autoshotgun");
case 1: BypassAndExecuteCommand(client, "give", "shotgun_spas");
case 2: BypassAndExecuteCommand(client, "give", "rifle");
case 3: BypassAndExecuteCommand(client, "give", "rifle_ak47");
case 4: BypassAndExecuteCommand(client, "give", "rifle_desert");
case 5: BypassAndExecuteCommand(client, "give", "rifle_sg552");
case 6: BypassAndExecuteCommand(client, "give", "hunting_rifle");
case 7: BypassAndExecuteCommand(client, "give", "sniper_awp");
case 8: BypassAndExecuteCommand(client, "give", "sniper_military");
case 9: BypassAndExecuteCommand(client, "give", "sniper_scout");
}
BypassAndExecuteCommand(client, "give", "ammo");
}
stock BypassAndExecuteCommand(client, String: strCommand[], String: strParam1[])
{
new flags = GetCommandFlags(strCommand);
SetCommandFlags(strCommand, flags & ~FCVAR_CHEAT);
FakeClientCommand(client, "%s %s", strCommand, strParam1);
SetCommandFlags(strCommand, flags);
}
public swapweapons()
{
new EntCount = GetEntityCount();
new String:EdictName[128];
new Float:position[3];
new Float:angle[3];
for (new i = 0; i <= EntCount; i++)
{
if(IsValidEdict(i))
{
GetEdictClassname(i, EdictName, sizeof(EdictName));
if ((StrContains(EdictName, "weapon_pumpshotgun_spawn", false) != -1)||(StrContains(EdictName, "weapon_shotgun_chrome_spawn", false) != -1))
{
GetEntPropVector(i, Prop_Send, "m_vecOrigin", position);
GetEntPropVector(i, Prop_Data, "m_angRotation", angle);
if (!AcceptEntityInput(i, "Kill")){RemoveEdict(i);}
new iWeapon = CreateEntityByName("weapon_autoshotgun_spawn");
if(IsValidEntity(iWeapon))
{
DispatchKeyValue(iWeapon, "count", "8");
DispatchSpawn(iWeapon);
TeleportEntity(iWeapon, position, angle, NULL_VECTOR);
}
}
}
}
}