#pragma tabsize 0
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools_functions>
#include <sdktools_entinput>
#include <sdkhooks>
public Plugin myinfo =
{
name = "Round of snowballs",
author = "Drumanid",
version = "1.0.0",
url = "Discord: Drumanid#9108"
};
int g_iAmmo = -1, g_iRound;
bool g_bVote[MAXPLAYERS +1];
#define V0(%0) \
for(int i = 1; i <= MaxClients; ++i)\
if(IsClientInGame(i))\
{\
%0(i, SDKHook_WeaponCanUse, WeaponCanUse);\
%0(i, SDKHook_OnTakeDamage, OnTakeDamage);\
}
public void OnPluginStart()
{
LoadTranslations("round_of_snowballs.phrases.txt");
RegConsoleCmd("sm_sbr", SbrCommand);
if(g_iRound == 1)
V0(SDKHook)
}
public void OnMapStart()
{
if(g_iRound != 0)
UnhookEvents();
if(g_iAmmo != -1)
return;
// https://hlmod.ru/threads/kak-vydavat-snezhki.47060/#post-386555
int iEntity = CreateEntityByName("weapon_snowball");
if(iEntity == -1)
SetFailState("No found entity: weapon_snowball");
DispatchSpawn(iEntity);
g_iAmmo = GetEntProp(iEntity, Prop_Send, "m_iPrimaryAmmoType");
AcceptEntityInput(iEntity, "Kill");
}
#define V1(%0) \
%0("round_prestart", RoundPreStart, EventHookMode_Pre);\
%0("round_end", RoundEnd)
#define V2(%0,%1) \
V0(%0)\
%1("player_spawn", PlayerSpawn)
public Action SbrCommand(int iClient, int iArgs)
{
if(iClient && iArgs == 0)
{
if(g_iRound != 0)
{
PrintToChat(iClient, "%t", "Denied, round started");
return Plugin_Handled;
}
PrintToChatAll("%t", (g_bVote[iClient] = !g_bVote[iClient]) ? "No, vote":"Yes, vote", iClient);
int i = 1, iCount[2];
for(; i <= MaxClients; ++i)
{
if(!IsClientInGame(i))
continue;
++iCount[0];
if(IsFakeClient(i) || g_bVote[i])
++iCount[1];
}
iCount[0] /= 2;
if(iCount[0] > iCount[1])
{
PrintToChatAll("%t", "Not enough votes", iCount[0] - iCount[1]);
return Plugin_Handled;
}
PrintToChatAll("%t", "Pre start round");
V1(HookEvent);
g_iRound = 1;
return Plugin_Handled;
}
return Plugin_Handled;
}
#define EVENT(%0) public void %0(Event hEvent, char[] sEvName, bool bDontBroadcast)
EVENT(RoundPreStart)
{
g_iRound = 2;
V2(SDKHook, HookEvent);
PrintToChatAll("%t", "Round start");
}
EVENT(PlayerSpawn)
{
int iClient = GetClientOfUserId(hEvent.GetInt("userid"));
if(GetEntProp(iClient, Prop_Data, "m_iAmmo", _, g_iAmmo) == 0)
GivePlayerItem(iClient, "weapon_snowball");
SetEntProp(iClient, Prop_Data, "m_iAmmo", 999, _, g_iAmmo);
EquipPlayerWeapon(iClient, GivePlayerItem(iClient, "weapon_knife"));
FakeClientCommand(iClient, "use weapon_snowball");
}
EVENT(RoundEnd)
{
if(g_iRound != 1)
{
UnhookEvents();
PrintToChatAll("%t", "Round end");
}
}
void UnhookEvents()
{
V1(UnhookEvent);
if(g_iRound == 2)
V2(SDKUnhook, UnhookEvent);
g_iRound = 0;
// In public SbrCommand
for(int i = 1; i <= MaxClients; ++i)
g_bVote[i] = false;
}
Action WeaponCanUse(int iClient, int iWeapon)
{
return GetEntProp(iWeapon, Prop_Send, "m_iItemDefinitionIndex") == 84 ? Plugin_Continue:Plugin_Handled;
}
Action OnTakeDamage(int iClient, int &iAttacker, int &iInflictor, float &fDamage, int &iDamageType)
{
if(iDamageType != 512)
return Plugin_Continue;
fDamage = 25.0;
return Plugin_Changed;
}
public void OnClientDisconnect(int iClient)
{
g_bVote[iClient] = false;
}