#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
new g_offsAccount;
new g_iMyWeapons;
new Handle:h_HePrice, heprice;
public Plugin:myinfo =
{
name = "Buying grenade via chat",
author = "FrozDark (HLModders.ru LLC)",
description = "Buying grenade via chat",
version = SOURCEMOD_VERSION,
url = "http://www.hlmod.ru/"
};
public OnPluginStart()
{
h_HePrice = CreateConVar("hg_cost", "300", "He grenade cost");
g_iMyWeapons = FindSendPropOffs("CBaseCombatCharacter", "m_hMyWeapons");
g_offsAccount = FindSendPropInfo("CCSPlayer", "m_iAccount");
if (g_offsAccount == -1)
SetFailState("Couldn't find offset \"m_iAccount\"!");
if (g_iMyWeapons == -1)
SetFailState("Couldn't find offset \"m_hMyWeapons\"!");
HookConVarChange(h_HePrice, ConVarChange_HePrice);
RegConsoleCmd("sm_hg", BuyGrenade);
RegConsoleCmd("sm_bhg", BuyGrenade);
RegConsoleCmd("sm_buyhe", BuyGrenade);
RegConsoleCmd("sm_buyhegrenade", BuyGrenade);
}
public OnConfigsExecuted()
{
heprice = GetConVarInt(h_HePrice);
}
public ConVarChange_HePrice(Handle:convar, const String:oldValue[], const String:newValue[])
{
heprice = StringToInt(newValue);
}
public Action:BuyGrenade(client, argc)
{
if (IsFakeClient(client))
return Plugin_Handled;
new money = GetEntData(client, g_offsAccount);
if (PlayerHasWeapon(client, "weapon_hegrenade") || (money < heprice))
return Plugin_Handled;
SetEntData(client, g_offsAccount, money - heprice);
GivePlayerItem(client, "weapon_hegrenade");
return Plugin_Handled;
}
bool:PlayerHasWeapon(client, const String:Weapon[32])
{
new weaponentity = -1;
new String:weaponname[32];
for (new i = 0; i <= 128; i += 4)
{
weaponentity = GetEntDataEnt2(client, (g_iMyWeapons + i));
if (IsValidEdict(weaponentity))
{
GetEdictClassname(weaponentity, weaponname, sizeof(weaponname));
if (StrEqual(weaponname, Weapon, false))
return true;
}
else
continue;
}
return false;
}