#pragma newdecls required

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <cstrike>

#define ARMS_MODEL_T  "models/weapons/v_models/arms/glove_hardknuckle/v_glove_hardknuckle_black.mdl"
#define ARMS_MODEL_CT "models/weapons/v_models/arms/glove_hardknuckle/v_glove_hardknuckle_black.mdl"

//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Plugin myinfo =
{
	name         = "Fix Invisible Gloves",
	author       = "zaCade",
	description  = "Feex more volvo bullshiet!",
	version      = "1.0.0"
};

//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
	if(GetEngineVersion() != Engine_CSGO)
	{
		strcopy(error, err_max, "This plugin is only required on CS:GO!");
		return APLRes_Failure;
	}

	return APLRes_Success;
}

//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnPluginStart()
{
	for (int iClient = 1; iClient <= MaxClients; iClient++)
	{
		if (IsClientInGame(iClient))
		{
			OnClientPutInServer(iClient);
		}
	}
}

//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnMapStart()
{
	PrecacheModel(ARMS_MODEL_T);
	PrecacheModel(ARMS_MODEL_CT);
}

//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientPutInServer(int iClient)
{
	SDKHook(iClient, SDKHook_SpawnPost, OnSpawnPost);
}

//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnSpawnPost(int iClient)
{
	if(!IsClientInGame(iClient) || IsClientObserver(iClient) || !IsPlayerAlive(iClient))
		return;

	if (GetEntPropEnt(iClient, Prop_Send, "m_hMyWearables") == INVALID_ENT_REFERENCE)
	{
		switch(GetClientTeam(iClient))
		{
			case CS_TEAM_T:  SetEntPropString(iClient, Prop_Send, "m_szArmsModel", ARMS_MODEL_T);
			case CS_TEAM_CT: SetEntPropString(iClient, Prop_Send, "m_szArmsModel", ARMS_MODEL_CT);
		}
	}
}