/*	Copyright © 2009, ConnorMcLeod

	AutoReload on NewRound is free software;
	you can redistribute it and/or modify it under the terms of the
	GNU General Public License as published by the Free Software Foundation.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with AutoReload on NewRound; if not, write to the
	Free Software Foundation, Inc., 59 Temple Place - Suite 330,
	Boston, MA 02111-1307, USA.
*/

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#define PLUGIN "Reloaded Weapons On New Round"
#define AUTHOR "ConnorMcLeod"
#define VERSION "2.0.0"

#define m_pNext	42
#define m_fInReload	54

#define m_flNextAttack			83
#define m_rgpPlayerItems_Slot1	368
#define m_rgpPlayerItems_Slot2	369

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	RegisterHam(Ham_Spawn, "player", "Player_Spawn")
}

public Player_Spawn( id )
{
	if( !is_user_alive(id) )
	{
		return
	}

	set_pdata_float(id, m_flNextAttack, -0.001, 5)

	new iWeapon
	for(new i=m_rgpPlayerItems_Slot1; i<=m_rgpPlayerItems_Slot2; i++)
	{
		iWeapon = get_pdata_cbase(id, i, 5)
		while( pev_valid(iWeapon) )
		{
			set_pdata_int(iWeapon, m_fInReload, 1, 4)
			ExecuteHamB(Ham_Item_PostFrame, iWeapon)
			iWeapon = get_pdata_cbase(iWeapon, m_pNext, 4)
		}
	}
}