#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <fakemeta>
#include <basebuilder>
#include <hamsandwich>

#define PLUGIN "[MG] Zombie Class: Jumper"
#define VERSION "1.1"
#define AUTHOR "Argon"

new const zclass_name[] = { "Jumper" }
new const zclass_info[] = { "\r[Multijump] \y[2 Jump]" }
new const zclass_model[] = { "zombie_jumper" }
new const zclass_clawmodel[] = { "basebulder/v_jumper" }
const zclass_health = 2000
const zclass_speed = 250
const Float:zclass_gravity = 0.6
const Float:zclass_knockback = 2.5
new g_zclass_jumper

new num_jumps[33] = 0
new jumpznum[33] = 0
new bool:dozjump[33] = false


public plugin_precache()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	g_zclass_jumper = zp_register_zombie_class(zclass_name, zclass_info, zclass_model, zclass_clawmodel, zclass_health, zclass_speed, zclass_gravity, zclass_knockback)	
}

public plugin_init()
{
	RegisterHam(Ham_Spawn, "player", "ham_PlayerSpawn_Post", 1)
}

public ham_PlayerSpawn_Post(id, infector)
{
	if ( bb_is_user_zombie(id) && bb_get_user_zombie_class(id) == g_zclass_jumper )
	{
		num_jumps[id] = 1
		new text[100]
		format(text,99,"^x04[MG]^x01 Your ability is ^x04Multijump^x01.")
		message_begin(MSG_ONE,get_user_msgid("SayText"),{0,0,0},id) 
		write_byte(id) 
		write_string(text) 
		message_end()
	}
	
	if( zp_get_user_zombie_class(infector) == g_zclass_jumper )
	{
		num_jumps[infector] = num_jumps[infector] + 1
		infections_hud(infector)
	}
}

public infections_hud(id)
{
	if( bb_is_user_zombie(id) && bb_get_user_zombie_class(id) == g_zclass_jumper)
	{
		new text[100]
		format(text,99,"^x04[MG]^x01 Now you can do ^x04%d^x01 jumps.",num_jumps[id])
		message_begin(MSG_ONE,get_user_msgid("SayText"),{0,0,0},id) 
		write_byte(id) 
		write_string(text) 
		message_end() 
	}
}

// -------------------------------------------------------------------------------------------------
public client_putinserver(id)
{
	jumpznum[id] = 0
	dozjump[id] = false
}

public client_disconnect(id)
{
	jumpznum[id] = 0
	dozjump[id] = false
}

public client_PreThink(id)
{
	if(!is_user_alive(id) || !bb_is_user_zombie(id) ) return PLUGIN_CONTINUE
	if(bb_get_user_zombie_class(id) != g_zclass_jumper) return PLUGIN_CONTINUE
	
	new nzbut = get_user_button(id)
	new ozbut = get_user_oldbutton(id)
	if((nzbut & IN_JUMP) && !(get_entity_flags(id) & FL_ONGROUND) && !(ozbut & IN_JUMP))
	{
		if (jumpznum[id] < num_jumps[id])
		{
			dozjump[id] = true
			jumpznum[id]++
			return PLUGIN_CONTINUE
		}
	}
	if((nzbut & IN_JUMP) && (get_entity_flags(id) & FL_ONGROUND))
	{
		jumpznum[id] = 0
		return PLUGIN_CONTINUE
	}	
	return PLUGIN_CONTINUE
}

public client_PostThink(id)
{
	if(!is_user_alive(id) || !zp_get_user_zombie(id)) return PLUGIN_CONTINUE
	if(bb_get_user_zombie_class(id) != g_zclass_jumper) return PLUGIN_CONTINUE
	
	if(dozjump[id] == true)
	{
		new Float:vezlocityz[3]	
		entity_get_vector(id,EV_VEC_velocity,vezlocityz)
		vezlocityz[2] = random_float(265.0,285.0)
		entity_set_vector(id,EV_VEC_velocity,vezlocityz)
		dozjump[id] = false
		return PLUGIN_CONTINUE
	}	
	return PLUGIN_CONTINUE
}	
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ fbidis\\ ansi\\ ansicpg1252\\ deff0{\\ fonttbl{\\ f0\\ fnil\\ fcharset0 Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ ltrpar\\ lang1049\\ f0\\ fs16 \n\\ par }
*/
