#if defined _csgom_included
    #endinput
#endif

#define _csgom_included

#if !defined pev
#include <fakemeta>
#endif

#if !defined MAX_PLAYERS
#define MAX_PLAYERS			32
#endif

#if !defined MAX_MODEL_LENGTH
#define MAX_MODEL_LENGTH		64
#endif

#define DEFAULT_CODE_VALUE		1000

#define fm_get_weapon_id(%1) 		get_pdata_int(%1, 43, 4)
#define DROP_GUN_CLASSNAME 		"drop_gun_ef"

#define m_pPlayer			41
#define XTRA_OFS_WEAPON			4
#define m_fInReload			54
#define m_flNextAttack		 	83 

#define INDUSTRIAL_CHANCE 		70
#define MIL_CHANCE 			25
#define RESTRICTED_CHANCE 		15
#define CLASS_CHANCE 			10
#define COVERT_CHANCE 			9		
#define RARE_CHANCE 			1
#define DEFAULT_CHANCE 			10

#define USE_SKINS			0
#define BUY_SKINS			1
#define INVENTORY			2
#define MARKET				3
#define TRADE				4
#define FIX_WEAPON			10

#define MAX_ATTEMPTS			150
#define PRICE_TO_RESTORE		50
#define GOLD_VALUE			4

enum cModelsArray
{
	szModelName[MAX_MODEL_LENGTH + MAX_PLAYERS],
	szViewModel[MAX_MODEL_LENGTH],
	iModelPrice,
	szModelRarity[MAX_MODEL_LENGTH],
	iWeaponBodyPart
}

enum rRarity
{
	rUseless,
	rBattleScared,
	rWellWorn,
	rFieldTested,
	rMinimalWear,
	rFactoryNew
}

stock const g_szRarityNames[rRarity][] =
{
	"",
	"Battle Scared",
	"Well-Worn",
	"Field Tested",
	"Minimal Wear",
	"Factory New"
}

stock const g_szRarityModels[][MAX_MODEL_LENGTH] =
{
	"models/industrial.mdl",
	"models/milspec.mdl",
	"models/restricted.mdl",
	"models/classified.mdl",
	"models/covert.mdl",
	"models/rare.mdl"
}

stock Float:g_iRarityDamageMultiplier[] =
{
	1.0,
	0.2,
	0.4,
	0.6,
	0.8,
	1.0
}

stock Float:g_iRaritySpeedMultiplier[] =
{
	1.0,
	1.8,
	1.6,
	1.4,
	1.2,
	1.0
}

stock g_iRaritiesKills[] =
{
	1000,
	800,
	500,
	200,
	100
}

stock const g_fVault[] = 			"CSGOM_Rank"
stock const g_fVaultMoney[] = 			"CSGOM_Money"

forward gotWeaponFromAnotherPlayer(iPlayerId, iWeaponID, iModelID)
forward giveUserSkin(iPlayer, iWID, iSId, bool:bIsSTT, bool:IsM4A4, bool:bGive)
forward boughtSkinFromMarket(iBuyer, iSeller, iSID, iWID, bool:bIsStt, iWPrice)

native registerItemInInventory(iPlayer, iWID, iSID, iWPrice, bool:bIsStt, szSkinN[])
native registerTradeItem(iPlayer, iSID, bool:bIsStt, szSkinN[], iWID)

native cs_set_viewmodel_body(pPlayer, iWeaponId, iValue)
native cs_set_modelformat(id, iWeaponId, szCustomModel[])
native cs_set_bodypart_animation(id, iWeapon, iAnimation)

native getUserMusicKit(id, szMusicKit[])

native csgom_reset_m4a1skin(id)
native csgom_reset_m4a4skin(id)
native csgom_has_m4a1skin(id)
native csgom_has_m4a4skin(id)
native csgom_getmoney(id)
native csgom_setmoney(id, value)
native csgom_get_goldmoney(id)
native csgom_set_goldmoney(id, value)
native get_user_elo(id)
native set_user_elo(id, value)

native csgom_using_custom_m4a4skin(id)
native csgom_using_m4a4_default(id)
native csgom_use_m4a4_default(id, bool:bSet)
native csgom_using_m4a1_default(id)
native csgom_using_custom_m4a1skin(id)
native csgom_use_m4a1_default(id, bool:bSet)

stock convertSkinPrice(bool:bIsStt, iMaxPrice)
{
	const Float:fSttPercent = 90.0
	const Float:fNormalPercent = 60.0
	
	return floatround(((bIsStt ? fSttPercent : fNormalPercent) * float(iMaxPrice)) / 100.0)
}

stock getNextRarityCount(iRarityInfo, iCurrentKillsCheck, szMessage[], iLen)
{
	if(iRarityInfo <= 1)
		return
	
	formatex(szMessage, iLen, "%d kills to %s", (g_iRaritiesKills[iRarityInfo - 1] - iCurrentKillsCheck), g_szRarityNames[rRarity:(iRarityInfo - 1)])
}

stock getDiscountValue(&iPrice, iUserID)
{
	if(get_user_flags(iUserID) & ADMIN_RESERVATION)
	{
		iPrice = floatround((90.0 * float(iPrice)) / 100.0)
		return true
	}
	return false
}

stock removeWeaponIcon(id, spriteName[]) 
{
	if(is_user_connected(id)) 
	{
		message_begin(MSG_ONE, get_user_msgid("StatusIcon"), {0,0,0}, id)
		write_byte(0)
		write_string(spriteName)
		message_end()
	}
}

stock getRarityMath(iRarity, szFinalInformation[], iLen)
{
	new Float:fFinalPercentageSpeed, Float:fFinalPercentageDamage
	fFinalPercentageDamage = (100.0 * g_iRarityDamageMultiplier[iRarity])

	fFinalPercentageSpeed = (100.0 * (2.0 - g_iRaritySpeedMultiplier[iRarity]))
	if(iRarity == 1)
	{
		fFinalPercentageSpeed += 0.1
	}

	if(fFinalPercentageSpeed == 0.0)
	{
		fFinalPercentageSpeed = 100.0
	}

	formatex(szFinalInformation, iLen, "(%.0f%%%% dmg & %.0f%%%% speed)", fFinalPercentageDamage, fFinalPercentageSpeed)
}

stock getRarityColorToHud(iWeaponID, Array:g_arArray, iRGB[3] = {255, 255, 255}, bool:bReturnChance = false, &iChanceReturn = 0)
{
	if((iWeaponID == -1) || (iWeaponID == DEFAULT_CODE_VALUE) || !ArraySize(g_arArray))
	{
		iRGB = {255, 255, 255}
		return
	}

	new arrayData[cModelsArray]
	ArrayGetArray(g_arArray, iWeaponID, arrayData)	
	if(equal(arrayData[szModelRarity], "Industrial Grade"))
	{
		if(bReturnChance)
		{
			iChanceReturn = INDUSTRIAL_CHANCE
		}
		else iRGB = {0, 100, 200}
	}
	else if(equal(arrayData[szModelRarity], "Mil-Spec"))
	{
		if(bReturnChance)
		{
			iChanceReturn = MIL_CHANCE
		}
		else iRGB = {0, 0, 200}
	}
	else if(equal(arrayData[szModelRarity], "Restricted"))
	{
		if(bReturnChance)
		{
			iChanceReturn = RESTRICTED_CHANCE
		}
		else iRGB = {180, 0, 180}
	}
	else if(equal(arrayData[szModelRarity], "Classified"))
	{
		if(bReturnChance)
		{
			iChanceReturn = CLASS_CHANCE
		}
		else iRGB = {60, 0, 130}
	}
	else if(equal(arrayData[szModelRarity], "Covert"))
	{
		if(bReturnChance)
		{
			iChanceReturn = COVERT_CHANCE
		}
		else iRGB = {200, 0, 0}
	}
	else if(equal(arrayData[szModelRarity], "Exceedingly Rare"))
	{
		if(bReturnChance)
		{
			iChanceReturn = RARE_CHANCE
		}
		else iRGB = {200, 120, 0}
	}
	else 
	{
		if(bReturnChance)
		{
			iChanceReturn = DEFAULT_CHANCE
		}
		else iRGB = {255, 255, 255}
	}
}

stock printForSpecs(id, iRGB[3], szMessageFmt[])
{
	for(new iSpectator= 1, iSpectating;iSpectator <= get_maxplayers();iSpectator++)
	{
		if(!is_user_connected(iSpectator))
			continue
			
		iSpectating = entity_get_int(iSpectator, EV_INT_iuser2)
		if(iSpectating != id)
			continue

		set_hudmessage(iRGB[0], iRGB[1], iRGB[2], -1.0, 0.77, 0, 1.0, 1.0)
		show_hudmessage(iSpectator, szMessageFmt)
	}
}

stock setRendering(iEnt, iRenderFx = kRenderFxNone, Float:fRenderColor[3] = {0.0, 0.0, 0.0}, Float:fRenderAmmt = 0.0)
{
	set_pev(iEnt, pev_renderfx, iRenderFx)
	set_pev(iEnt, pev_rendercolor, fRenderColor)
	set_pev(iEnt, pev_rendermode, kRenderNormal)
	set_pev(iEnt, pev_renderamt, fRenderAmmt)
}

stock ChatColor(const id, const input[], any:...)
{
        new count = 1, players[32]
        static msg[191]
        vformat(msg, 190, input, 3)
	format(msg, charsmax(msg), "^x04[CSGOM]^x01: %s", msg)

        replace_all(msg, 190, "!g", "^4") // verde
        replace_all(msg, 190, "!y", "^1") // Default
        replace_all(msg, 190, "!t", "^3") // Team

        if (id) players[0] = id; else get_players(players, count, "ch")
        {
                for (new i = 0; i < count; i++)
                {
                        if (is_user_connected(players[i]))
                        {
                                message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players[i])
                                write_byte(players[i]);
                                write_string(msg);
                                message_end();
                        }
                }
        }
}