#include <amxmodx>
#include <cstrike>
#include <fun>

new bool:g_hasLongJump[33]
new PcvarMode
new PcvarCost
static const PLUGIN_NAME[] = "Buy Longjump"
static const PLUGIN_AUTHOR[] = "Locks"
static const PLUGIN_VERSION[] = "1.1"

public plugin_init() 
{
	register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
	register_concmd("say buy_longjump", "buy_longjump")
	register_concmd("say buylongjump", "buy_longjump")
	register_concmd("say buy_jumppack", "buy_longjump")
	register_concmd("say buyjumppack", "buy_longjump")
	register_concmd("buy_longjump", "buy_longjump")
	register_concmd("buylongjump", "buy_longjump")
	register_concmd("buy_jumppack", "buy_longjump")
	register_concmd("buyjumppack", "buy_longjump")
	PcvarMode = register_cvar("sv_longjump", "1")
	PcvarCost = register_cvar("amx_longjump_cost","0")

	register_event("DeathMsg", "death", "a")
}

public client_connect(id)
{
	g_hasLongJump[id] = false
	return PLUGIN_HANDLED
}

public client_disconnect(id)
{
	g_hasLongJump[id] = false
	return PLUGIN_HANDLED
}

public death()
{
	new id = read_data(2)
	g_hasLongJump[id] = false
}

public buy_longjump(id)
{
	if ( get_pcvar_num(PcvarMode) == 0 )
	{
		client_print(id, print_chat, "[AMXX] Long Jump plugin is disabled.")
		return PLUGIN_HANDLED
	}

	if ( g_hasLongJump[id] )
	{
		client_print(id, print_chat, "[AMXX] You have already purchased a jumppack.")
	}

	if ( !is_user_alive(id) )
	{
		client_print(id,print_chat,"[AMXX] Dead clients are not allow to buy a jumppack.")
		return PLUGIN_HANDLED
	}

	new money = cs_get_user_money(id)
	new cost = get_pcvar_num(PcvarCost)

	if ( money < cost )
	{
		client_print(id, print_chat, "[AMXX] You don't have enough money to buy a jumppack. ($%i needed).", cost)
		return PLUGIN_CONTINUE
	}

	give_item(id, "item_longjump")
	cs_set_user_money(id, money - cost)
	client_print(id, print_chat, "[AMXX] You have bought a Jump Pack. To use it, press duck and jump while moving forward.")
	g_hasLongJump[id] = true

	return PLUGIN_CONTINUE
}