#pragma semicolon 1
#pragma newdecls required
#include <sdktools>
#define PLUGIN_VERSION "1.0"
#define CVAR_FLAGS FCVAR_NOTIFY
public Plugin myinfo =
{
name = "[L4D] Give Items",
author = "BloodyBlade",
description = "Gives items on player spawn.",
version = PLUGIN_VERSION,
url = "https://bloodsiworld.ru/"
}
PluginData plugin;
enum struct PluginCvars
{
ConVar hPluginEnabled;
ConVar hPluginGiveItimsType;
void Init()
{
CreateConVar("l4d_giveitems", PLUGIN_VERSION, "[L4D] Give Items plugin version.", CVAR_FLAGS|FCVAR_DONTRECORD);
this.hPluginEnabled = CreateConVar("l4d_giveitems_enable", "1", "Enable/Disable the plugin.", CVAR_FLAGS);
this.hPluginGiveItimsType = CreateConVar("l4d_giveitems_type", "1", "0 = random item, 1 = Pump Shotgun, 2 = SMG, 3 = Auto Shotgun, 4 = M16, 5 = Hunting Rifle.", CVAR_FLAGS);
this.hPluginEnabled.AddChangeHook(ConVarAllowChanged);
this.hPluginGiveItimsType.AddChangeHook(OnConVarsChanged);
AutoExecConfig(true, "l4d_giveitems");
}
}
enum struct PluginData
{
PluginCvars cvars;
bool bHooked;
bool bPluginOn;
int iItemType;
int iItem;
int iGiven;
int iRandom;
char cWeapon[64];
void Init()
{
this.cvars.Init();
}
void GetCvarValues()
{
this.iItemType = this.cvars.hPluginGiveItimsType.IntValue;
}
void IsAllowed()
{
this.bPluginOn = this.cvars.hPluginEnabled.BoolValue;
if(!this.bHooked && this.bPluginOn)
{
this.bHooked = true;
HookEvent("player_spawn", Event_PlayerSpawn);
}
else if(this.bHooked && !this.bPluginOn)
{
this.bHooked = false;
UnhookEvent("player_spawn", Event_PlayerSpawn);
}
}
}
public void OnPluginStart()
{
plugin.Init();
}
public void OnConfigsExecuted()
{
plugin.IsAllowed();
plugin.GetCvarValues();
}
void ConVarAllowChanged(ConVar convar, const char[] oldValue, const char[] newValue)
{
plugin.IsAllowed();
}
void OnConVarsChanged(ConVar convar, const char[] oldValue, const char[] newValue)
{
plugin.GetCvarValues();
}
Action Event_PlayerSpawn(Event event, char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
if(IsValidSurv(client))
{
RequestFrame(GiveStartWeapons, client);
}
return Plugin_Continue;
}
void GiveStartWeapons(int client)
{
if(plugin.bHooked)
{
if(IsValidSurv(client))
{
plugin.iItem = GetPlayerWeaponSlot(client, 0);
if(plugin.iItem == -1)
{
switch(plugin.iItemType)
{
case 0:
{
plugin.iRandom = GetRandomInt(1, 5);
switch(plugin.iRandom)
{
case 1:
{
plugin.cWeapon = "weapon_pumpshotgun";
}
case 2:
{
plugin.cWeapon = "weapon_smg_silenced";
}
case 3:
{
plugin.cWeapon = "weapon_autoshotgun";
}
case 4:
{
plugin.cWeapon = "weapon_rifle";
}
case 5:
{
plugin.cWeapon = "weapon_hunting_rifle";
}
}
}
case 1:
{
plugin.cWeapon = "weapon_pumpshotgun";
}
case 2:
{
plugin.cWeapon = "weapon_smg_silenced";
}
case 3:
{
plugin.cWeapon = "weapon_autoshotgun";
}
case 4:
{
plugin.cWeapon = "weapon_rifle";
}
case 5:
{
plugin.cWeapon = "weapon_hunting_rifle";
}
}
plugin.iGiven = GivePlayerItem(client, plugin.cWeapon);
if(plugin.iGiven > 0)
{
EquipPlayerWeapon(client, plugin.iGiven);
}
}
}
}
}
bool IsValidSurv(int client)
{
return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2 && IsPlayerAlive(client);
}