#include <amxmodx>
#include <fakemeta>
#include <fun>
#include <hamsandwich>
#include <zombieplague>

#define OFFSET_SECONDARYWEAPON    369

new bool:g_bOnSpawn

public plugin_init()
{
	RegisterHam(Ham_Spawn, "player", "PlayerSpawnPre", 0)
    	RegisterHam(Ham_Spawn, "player", "PlayerSpawnPost", 1)
    	RegisterHam(Ham_GiveAmmo, "player", "PlayerGiveAmmoPre", 0)
    
    	register_forward(FM_CreateNamedEntity, "CreateNamedEntityPre", 0)
}

public PlayerSpawnPre() g_bOnSpawn = true

public PlayerSpawnPost() g_bOnSpawn = false

public PlayerGiveAmmoPre()
{
    	if (!g_bOnSpawn)
        	return HAM_IGNORED
    
    	return HAM_SUPERCEDE
}

public CreateNamedEntityPre(iClassname)
{
    	if (!g_bOnSpawn)
        	return FMRES_IGNORED
    
    	new iClassname2[32]
    
    	global_get(glb_pStringBase, iClassname, iClassname2, 31)
    
    	if (equal(iClassname2, "weapon_knife"))
        	return FMRES_IGNORED
    
    	forward_return(FMV_CELL, 0)
    
    	return FMRES_SUPERCEDE
}

public zp_round_started()
{
    	new iPlayers[32], iPlayersCount, iEntity
    
    	get_players(iPlayers, iPlayersCount, "a")
    
    	for (new i = 0; i < iPlayersCount; i++)
    	{
        	iEntity = iPlayers[i]
        
        	if (zp_get_user_zombie(iEntity))
            		continue
        	if (zp_get_user_survivor(iEntity))
            		continue
        	if (get_pdata_cbase(iEntity, OFFSET_SECONDARYWEAPON) != -1)
            		continue
        
        	give_item(iEntity, "weapon_usp")
        	ExecuteHamB(Ham_GiveAmmo, iEntity, 24, "45acp", 100)
    	}
}