/*
* Empires API
* 
* Created By Theowningone
* Version: 1.1
* http://www.theowningone.info/
* http://www.borgamers.com/
*/

/******************
* --> Defines <-- *
******************/

#if defined _empires_included
#endinput
#endif
#define _empires_included

#include <sourcemod>
#include <sdktools>





/********************
* --> Is Stocks <-- *
********************/

/**
* Is Player Squad Leader
*
* @param client			Client Index
* @return				true if leader, false if other
*/
stock bool:IsSquadLeader(client)
{
	new ent = FindEntityByNetClass("CPlayerResource");
	new offset = FindSendPropOffs("CPlayerResource", "m_bSquadLeader");
	new out = GetEntData(ent, offset + (client*4), 4);
	new bool:newout = false;
	if(out) newout = true;
	return newout;
}

/**
* Is Player Commander
*
* @param client			Client Index
* @return				true if comm, false if other
*/
stock bool:IsComm(client)
{
	new ent = FindEntityByNetClass("CPlayerResource");
	new offset = FindSendPropOffs("CPlayerResource", "m_bCommander");
	new out = GetEntData(ent, offset + (client*4), 4);
	new bool:newout = false;
	if(out) newout = true;
	return newout;
}

/**
* Is Player In Vehicle
*
* @param client			Client Index
* @return				true if in vehicle, false if not
*/
stock bool:IsInVehicle(client)
{
	new team = GetClientTeam(client);
	new ent,out = 0;
	if(team == 2){
		ent = FindEntityByNetClass("CPlayerResource_NF");
		new offset = FindSendPropOffs("CPlayerResource_NF", "m_iVehicle_NF");
		out = GetEntData(ent, offset + (client*4), 4);
	}else if(team == 3){
		ent = FindEntityByNetClass("CPlayerResource_IMP");
		new offset = FindSendPropOffs("CPlayerResource_IMP", "m_iVehicle_IMP");
		out = GetEntData(ent, offset + (client*4), 4);
	}
	if(IsComm(client)){
		out = 1;
	}
	new newout = 0;
	if(out >= 1){
		newout = 1;
	}
	new bool:newout2 = false;
	if(newout) newout2 = true;
	return newout2;
}

/**
* Is Sabotaged
*
* @param ent			Entity Index
* @return				true if sabotaged, false if other
*/
stock bool:IsSabotaged(ent)
{
	if(!IsValidEntity(ent)) return false;
	new bool:newout = false;
	new out = GetEntProp(ent,Prop_Send,"m_bSabotaged");
	if(out == 1) newout = true;
	return newout;
}



 




/**********************
* --> Team Stocks <-- *
**********************/

/**
* Retrieves NF Resources.
*
* @return				NF Resources
*/
stock GetNFResources()
{
	new ent = FindEntityByClass("emp_info_params");
	new out = GetEntProp(ent,Prop_Data, "m_iNFResources");
	return out;
}

/**
* Sets NF Resources.
*
* @noreturn
*/
stock SetNFResources(amount)
{
	new ent = FindEntityByClass("emp_info_params");
	SetEntProp(ent,Prop_Data, "m_iNFResources", amount);
}

/**
* Retrieves BE Resources.
*
* @return				BE Resources
*/
stock GetBEResources()
{
	new ent = FindEntityByClass("emp_info_params");
	new out = GetEntProp(ent,Prop_Data, "m_iImpResources");
	return out;
}

/**
* Sets BE Resources.
*
* @noreturn
*/
stock SetBEResources(amount)
{
	new ent = FindEntityByClass("emp_info_params");
	SetEntProp(ent,Prop_Data, "m_iImpResources", amount);
}

/**
* Retrieves NF Reinforcements
*
* @return				NF Reinforcements
*/
stock GetNFReinforcements()
{
	new ent = FindEntityByClass("emp_info_params");
	new out = GetEntProp(ent,Prop_Data, "m_iNFReinforcements");
	out--;
	return out;
}

/**
* Sets NF Reinforcements
*
* @noreturn
*/
stock SetNFReinforcements(amount)
{
	new ent = FindEntityByClass("emp_info_params");
	amount++;
	SetEntProp(ent,Prop_Data, "m_iNFReinforcements", amount);
}

/**
* Retrieves BE Reinforcements
*
* @return				BE Reinforcements
*/
stock GetBEReinforcements()
{
	new ent = FindEntityByClass("emp_info_params");
	new out = GetEntProp(ent,Prop_Data, "m_iImpReinforcements");
	out--;
	return out;
}

/**
* Sets BE Reinforcements
*
* @noreturn
*/
stock SetBEReinforcements(amount)
{
	new ent = FindEntityByClass("emp_info_params");
	amount++;
	SetEntProp(ent,Prop_Data, "m_iImpReinforcements", amount);
}

/**
* Is Researched
*
* @param team			Team Index
* @param index			Research Index
* @return				1 if researched, 0 if not
*/
stock IsResearched(team, index)
{
	new ent = FindEntityByNetClass("CResearchResource");
	new bebool = FindSendPropOffs("CResearchResource", "m_bResearched_IMP");
	new nfbool = FindSendPropOffs("CResearchResource", "m_bResearched_NF");
	new out;
	if(team == 2){
		out = GetEntData(ent, nfbool+index, 4);
	}else if(team == 3){
		out = GetEntData(ent, bebool+index, 4);
	}
	return out;
}

/**
* Current Research
*
* @param team			Team Index
* @return				Research Index
*/
stock CurrentResearch(team)
{
	new ent = FindEntityByNetClass("CResearchResource");
	new out;
	if(team == 2){
		out = GetEntProp(ent,Prop_Send,"m_iResearchItem_NF");
	}else if(team == 3){
		out = GetEntProp(ent,Prop_Send,"m_iResearchItem_IMP");
	}
	return out;
}

/**
* Research Name
*
* @param research		Research Index
* @param buffer			Buffer to hold the research name
* @param size			Len of the buffer
* @noreturn
*/
stock ResearchName(research, String:buffer[], size){
	new Handle:ResearchNames = CreateTrie();
	SetTrieString(ResearchNames, "0", "None", true);
	SetTrieString(ResearchNames, "1", "Physics", true);
	SetTrieString(ResearchNames, "2", "Superheated Material Physics", true);
	SetTrieString(ResearchNames, "3", "Plasma Cannon Projectile", true);
	SetTrieString(ResearchNames, "4", "Plasma Bullet Projectile", true);
	SetTrieString(ResearchNames, "5", "Projectile Physics", true);
	SetTrieString(ResearchNames, "6", "Reflective Armor", true);
	SetTrieString(ResearchNames, "7", "Extended Range Cannon", true);
	SetTrieString(ResearchNames, "8", "Heavy Caliber Machine Gun", true);
	SetTrieString(ResearchNames, "9", "Nuclear Fission", true);
	SetTrieString(ResearchNames, "10", "Fission Reactor", true);
	SetTrieString(ResearchNames, "11", "HIT Warhead", true);
	SetTrieString(ResearchNames, "12", "Chemistry", true);
	SetTrieString(ResearchNames, "13", "Improved Flagration Compounds", true);
	SetTrieString(ResearchNames, "14", "Explosive Tipped Bullets", true);
	SetTrieString(ResearchNames, "15", "Improved Detonation Compounds", true);
	SetTrieString(ResearchNames, "16", "Upgraded Grenades", true);
	SetTrieString(ResearchNames, "17", "Explosive Shells", true);
	SetTrieString(ResearchNames, "18", "Improved Warhead Compounds", true);
	SetTrieString(ResearchNames, "19", "Upgraded Missile Warhead", true);
	SetTrieString(ResearchNames, "20", "Improved Heat Transfer Fluids", true);
	SetTrieString(ResearchNames, "21", "Advanced Coolant Engine", true);
	SetTrieString(ResearchNames, "22", "Absorbant Armor", true);
	SetTrieString(ResearchNames, "23", "Mechanical Engineering", true);
	SetTrieString(ResearchNames, "24", "Upgraded Chassis", true);
	SetTrieString(ResearchNames, "25", "Medium Tank Chassis", true);
	SetTrieString(ResearchNames, "26", "Artillery Tank Chassis", true);
	SetTrieString(ResearchNames, "27", "Advanced Chassis", true);
	SetTrieString(ResearchNames, "28", "Heavy Tank Chassis", true);
	SetTrieString(ResearchNames, "29", "Advanced Machining", true);
	SetTrieString(ResearchNames, "30", "Composite Armor", true);
	SetTrieString(ResearchNames, "31", "Gas Turbine Engine", true);
	SetTrieString(ResearchNames, "32", "Electrical Engineering", true);
	SetTrieString(ResearchNames, "33", "Advanced Magnet Research", true);
	SetTrieString(ResearchNames, "34", "Rail Gun", true);
	SetTrieString(ResearchNames, "35", "3 Phase Electric Motor", true);
	SetTrieString(ResearchNames, "36", "Reactive Armor", true);
	SetTrieString(ResearchNames, "37", "Tracking Systems", true);
	SetTrieString(ResearchNames, "38", "Homing Missiles", true);
	SetTrieString(ResearchNames, "39", "Guided Missiles", true);
	SetTrieString(ResearchNames, "40", "Upgraded Turrets Lvl 2", true);
	SetTrieString(ResearchNames, "41", "Upgraded Turrets Lvl 3", true);
	SetTrieString(ResearchNames, "42", "Biology", true);
	SetTrieString(ResearchNames, "43", "Regenerative Armor", true);
	SetTrieString(ResearchNames, "44", "Bio Diesel Engine", true);
	SetTrieString(ResearchNames, "45", "Biological Weaponry", true);
	SetTrieString(ResearchNames, "46", "Biological Warhead", true);
	SetTrieString(ResearchNames, "47", "Biological Projectile", true);
	decl String:research2[64], String:researchname[64];
	IntToString(research, research2 ,sizeof(research2));
	GetTrieString(ResearchNames, research2, researchname, sizeof(researchname));
	CloseHandle(ResearchNames);
	strcopy(buffer, size, researchname);
}

/**
* Set Research
*
* @param team			Team Index
* @param index			Research Index
* @param status			True to research, False to Unresearch
* @noreturn
*/
stock SetResearch(team, index, bool:status)
{
	new ent = FindEntityByNetClass("CResearchResource");
	new off;
	if(team == 2){
		off = FindSendPropOffs("CResearchResource", "m_bResearched_NF");
		SetEntData(ent, off+index, status, 4, true);
	}else if(team == 3){
		off = FindSendPropOffs("CResearchResource", "m_bResearched_IMP");
		SetEntData(ent, off+index, status, 4, true);
	}
}

/**
* Has Radar
*
* @param team			Team Index
* @return				True if has radar, false if other
*/
stock bool:HasRadar(team)
{
	new ent = FindEntityByNetClass("CResearchResource");
	new out;
	if(team == 2){
		out = GetEntProp(ent,Prop_Send,"m_bRadarBuilt_NF");
	}else if(team == 3){
		out = GetEntProp(ent,Prop_Send,"m_bRadarBuilt_IMP");
	}
	new bool:newout = false
	if(out == 1) newout = true;
	return newout;
}

/**
* Get Research Time
*
* @param team			Team Index
* @return				Time left in research
*/
stock GetResearchTime(team)
{
	new ent = FindEntityByNetClass("CResearchResource");
	new out;
	if(team == 2){
		out = GetEntProp(ent,Prop_Send,"m_iResearchTime_NF");
	}else if(team == 3){
		out = GetEntProp(ent,Prop_Send,"m_iResearchTime_IMP");
	}
	return out;
}

/**
* Get Entity Team
*
* @param ent			Entity Index
* @return				Team index, -1 on error
*/
stock GetEntityTeam(ent)
{
	if(!IsValidEntity(ent)) return -1;
	new out = -1;
	out = GetEntProp(ent,Prop_Send,"m_iTeamNum");
	return out;
}

/**
* Set Entity Team
*
* @param ent			Entity Index
* @param team			Team Index
* @return				True if on success, False if other
*/
stock bool:SetEntityTeam(ent, team)
{
	if(!IsValidEntity(ent)) return false;
	SetEntProp(ent,Prop_Send,"m_iTeamNum",team);
	return true;
}






/*************************
* --> Vehicle Stocks <-- *
*************************/

/**
* Get Vehicle Occupants
*
* @param ent			Vehicle Entity Index
* @return   			Amount of clients in vehicle
*/
stock GetVehicleOccupants(ent)
{
	if(!IsValidEntity(ent)) return -1;
	new String:class[256];
	GetEntityNetClass(ent, class, sizeof(class));
	if(!StrEqual(class, "CEmpTank", false)) return -1;
	new dat, out = 0;
	dat = GetEntPropEnt(ent,Prop_Send,"m_hPlayer");
	if(dat!=-1) out++;
	dat = GetEntPropEnt(ent,Prop_Send,"m_hPlayer2");
	if(dat!=-1) out++;
	dat = GetEntPropEnt(ent,Prop_Send,"m_hPlayer3");
	if(dat!=-1) out++;
	dat = GetEntPropEnt(ent,Prop_Send,"m_hPlayer4");
	if(dat!=-1) out++;
	dat = GetEntPropEnt(ent,Prop_Send,"m_hPlayer5");
	if(dat!=-1) out++;
	dat = GetEntPropEnt(ent,Prop_Send,"m_hPlayer6");
	if(dat!=-1) out++;
	dat = GetEntPropEnt(ent,Prop_Send,"m_hPlayer7");
	if(dat!=-1) out++;
	dat = GetEntPropEnt(ent,Prop_Send,"m_hPlayer8");
	if(dat!=-1) out++;
	return out;
}

/**
* Get Vehicle Driver
*
* @param ent			Vehicle Entity Index
* @return 				Client Index of Driver (0 if none, -1 if invalid entity)
*/
stock GetVehicleDriver(ent)
{
	if(!IsValidEntity(ent)) return -1;
	new String:class[256];
	GetEntityNetClass(ent, class, sizeof(class));
	if(!StrEqual(class, "CEmpTank", false)) return -1;
	new out=GetEntPropEnt(ent,Prop_Send,"m_hPlayer");
	return out;
}

/**
* Set Vehicle Armor
*
* @param ent			Vehicle Entity Index
* @param side			side of armor (1 is front, 2 is back, 3 is left, 4 is right)
* @param front			Health to set armor to
* @return				-1 on error, 0 on success
*/
stock SetVehicleArmor(ent, side, Float:health)
{
	if(!IsValidEntity(ent)) return -1;
	new String:class[256];
	GetEntityNetClass(ent, class, sizeof(class));
	if(!StrEqual(class, "CEmpTank", false)) return -1;
	new off = FindSendPropOffs("CEmpTank", "m_flVehicleArmor");
	if(side == 1){
		SetEntDataFloat(ent, off, health, true);
	}else if(side == 2){
		SetEntDataFloat(ent, off+4, health, true);
	}else if(side == 3){
		SetEntDataFloat(ent, off+8, health, true);
	}else if(side == 4){
		SetEntDataFloat(ent, off+12, health, true);
	}
	return 0;
}

/**
* Get Vehicle Armor
*
* @param ent			Vehicle Entity Index
* @param side			side of armor (1 is front, 2 is back, 3 is left, 4 is right)
* @return				Armor Health (-1.0 on error)
*/
stock Float:GetVehicleArmor(ent, side)
{
	if(!IsValidEntity(ent)) return -1.0;
	new String:class[256];
	GetEntityNetClass(ent, class, sizeof(class));
	if(!StrEqual(class, "CEmpTank", false)) return -1.0;
	new off = FindSendPropOffs("CEmpTank", "m_flVehicleArmor");
	new Float:dat = -1.0;
	if(side == 1){
		dat = GetEntDataFloat(ent, off);
	}else if(side == 2){
		dat = GetEntDataFloat(ent, off+4);
	}else if(side == 3){
		dat = GetEntDataFloat(ent, off+8);
	}else if(side == 4){
		dat = GetEntDataFloat(ent, off+12);
	}
	return dat;
}

/**
* Set Vehicle Hull
*
* @param ent			Vehicle Entity Index
* @param health			Health to set hull to
* @return				-1 on error, 0 on success
*/
stock SetVehicleHull(ent, Float:health)
{
	if(!IsValidEntity(ent)) return -1;
	new String:class[256];
	GetEntityNetClass(ent, class, sizeof(class));
	if(!StrEqual(class, "CEmpTank", false)) return -1;
	SetEntPropFloat(ent,Prop_Send,"m_flTotalHealth",health);
	return 0;
}

/**
* Get Vehicle Hull
*
* @param ent			Vehicle Entity Index
* @return				Hull Health (-1.0 on error)
*/
stock Float:GetVehicleHull(ent)
{
	if(!IsValidEntity(ent)) return -1.0;
	new String:class[256];
	GetEntityNetClass(ent, class, sizeof(class));
	if(!StrEqual(class, "CEmpTank", false)) return -1.0;
	new Float:dat = GetEntPropFloat(ent,Prop_Send,"m_flTotalHealth");
	return dat;
}

/**
* Set Vehicle Heat
*
* @param ent			Vehicle Entity Index
* @param heat			Heat to set for vehicle
* @return				-1 on error, 0 on success
*/
stock SetVehicleHeat(ent, Float:heat)
{
	if(!IsValidEntity(ent)) return -1;
	new String:class[256];
	GetEntityNetClass(ent, class, sizeof(class));
	if(!StrEqual(class, "CEmpTank", false)) return -1;
	SetEntPropFloat(ent,Prop_Send,"m_flVehicleHeat",heat);
	return 0;
}

/**
* Get Vehicle Heat
*
* @param ent			Vehicle Entity Index
* @return				Vehicle Heat (-1.0 on error)
*/
stock Float:GetVehicleHeat(ent)
{
	if(!IsValidEntity(ent)) return -1.0;
	new String:class[256];
	GetEntityNetClass(ent, class, sizeof(class));
	if(!StrEqual(class, "CEmpTank", false)) return -1.0;
	new Float:dat = GetEntPropFloat(ent,Prop_Send,"m_flVehicleHeat");
	return dat;
}

/**
* Get Vehicle Class
*
* @param ent			Vehicle Entity Index
* @return				Vehicle Class (-1 on error)
*/
stock GetVehicleClass(ent)
{
	if(!IsValidEntity(ent)) return -1;
	new String:class[256];
	GetEntityNetClass(ent, class, sizeof(class));
	if(!StrEqual(class, "CEmpTank", false)) return -1;
	new dat = GetEntProp(ent,Prop_Send,"m_iChassis");
	return dat;
}

/**
* Get Vehicle Class Name
*
* @param ent			Vehicle Entity Index
* @param buffer			Buffer to hold the vehicle class name
* @param size			Len of the buffer
* @return				Vehicle Class (-1 on error)
*/
stock GetVehicleClassName(ent, String:buffer[], size)
{
	if(!IsValidEntity(ent)) return -1;
	new String:class[256];
	GetEntityNetClass(ent, class, sizeof(class));
	if(!StrEqual(class, "CEmpTank", false)) return -1;
	new out = GetEntProp(ent,Prop_Send,"m_iChassis");
	new Handle:VehicleNames = CreateTrie();
	SetTrieString(VehicleNames, "0", "NF Jeep", true);
	SetTrieString(VehicleNames, "1", "NF APC", true);
	SetTrieString(VehicleNames, "2", "NF Light Tank", true);
	SetTrieString(VehicleNames, "3", "NF Med Tank", true);
	SetTrieString(VehicleNames, "4", "NF Heavy Tank", true);
	SetTrieString(VehicleNames, "5", "NF Arty Tank", true);
	SetTrieString(VehicleNames, "6", "BE Jeep", true);
	SetTrieString(VehicleNames, "7", "BE APC", true);
	SetTrieString(VehicleNames, "8", "BE AFV", true);
	SetTrieString(VehicleNames, "9", "BE Med Tank", true);
	SetTrieString(VehicleNames, "10", "BE Heavy Tank", true);
	SetTrieString(VehicleNames, "11", "BE Arty Tank", true);
	SetTrieString(VehicleNames, "12", "BE Commander", true);
	SetTrieString(VehicleNames, "13", "NF Commander", true);
	decl String:vehicle[64], String:vehiclename[64];
	IntToString(out, research ,sizeof(research));
	GetTrieString(VehicleNames, vehicle, vehiclename, sizeof(vehiclename));
	CloseHandle(VehicleNames);
	strcopy(buffer, size, vehiclename);
	return out;
}

/**
* Get Client Vehicle
*
* @param client			Client Index
* @return				Client Vehicle Entity Index (-1 is error, 0 is none)
*/
stock GetPlayerVehicle(client)
{
	new team = GetClientTeam(client);
	new ent, out = -1;
	if(team==2){
		ent = FindEntityByNetClass("CPlayerResource_NF");
		new offset = FindSendPropOffs("CPlayerResource_NF", "m_iVehicle_NF");
		out = GetEntData(ent, offset + (client*4), 4);
	}else if(team==3){
		ent = FindEntityByNetClass("CPlayerResource_IMP");
		new offset = FindSendPropOffs("CPlayerResource_IMP", "m_iVehicle_IMP");
		out = GetEntData(ent, offset + (client*4), 4);
	}
	if(IsComm(client)){
		if(team == 2){
			out = FindEntityByClass("emp_nf_commander");
		}else if(team == 3){
			out = FindEntityByClass("emp_imp_commander");
		}
	}
	return out;
}

/**
* Get Cannon Entity
*
* @param ent			Vehicle Entity Index
* @return				Cannon Entity Index
*/
stock GetCannonEnt(ent)
{
	if(!IsValidEntity(ent)) return -1;
	new String:class[256];
	GetEntityNetClass(ent, class, sizeof(class));
	if(!StrEqual(class, "CEmpTank", false)) return -1;
	new out = GetEntPropEnt(ent,Prop_Send,"m_hCannon");
	return out;
}

/**
* Get Turret Entity
*
* @param ent			Vehicle Entity Index
* @return				Turret Entity Index
*/
stock GetTurretEnt(ent)
{
	if(!IsValidEntity(ent)) return -1;
	new String:class[256];
	GetEntityNetClass(ent, class, sizeof(class));
	if(!StrEqual(class, "CEmpTank", false)) return -1;
	new out = GetEntPropEnt(ent,Prop_Send,"m_hTurret");
	return out;
}















/**********************
* --> Misc Stocks <-- *
**********************/

/**
* Retrieves a buildings health
*
* @param ent			Entity Index
* @return				Buildings Health(-1 on error)
*/
stock GetBuildingHealth(ent)
{
	if(IsValidEntity(ent)){
		new out = GetEntProp(ent, Prop_Data, "m_iHealth");
		return out;
	}else{
		return -1;
	}
}


/**
* Sets buildings health
*
* @param ent			Entity Index
* @param health			Health
* @noreturn
*/
stock SetBuildingHealth(ent, health)
{
	if(IsValidEntity(ent))SetEntProp(ent, Prop_Data, "m_iHealth", health);
}


/**
* Retrieves a player's squad number
*
* @param client			Client Index
* @return				Player squad index (0 is none)
*/
stock GetPlayerSquadNum(client)
{
	new ent = FindEntityByNetClass("CPlayerResource");
	new offset = FindSendPropOffs("CPlayerResource", "m_iSquad");
	new out = GetEntData(ent, offset + (client*4), 4);
	return out;
}


/**
* Retrieves a player's squad name
*
* @param client			Client Index
* @param buffer			Buffer to hold the squad name
* @param size			Len of the buffer
* @return				Player squad index
*/
stock GetPlayerSquadName(client, String:buffer[], size)
{
	new ent = FindEntityByNetClass("CPlayerResource");
	new offset = FindSendPropOffs("CPlayerResource", "m_iSquad");
	new out = GetEntData(ent, offset + (client*4), 4);
	new Handle:SquadNames = CreateTrie();
	SetTrieString(SquadNames, "0", "None", true);
	SetTrieString(SquadNames, "1", "Alpha", true);
	SetTrieString(SquadNames, "2", "Bravo", true);
	SetTrieString(SquadNames, "3", "Charlie", true);
	SetTrieString(SquadNames, "4", "Delta", true);
	SetTrieString(SquadNames, "5", "Echo", true);
	SetTrieString(SquadNames, "6", "Foxtrot", true);
	SetTrieString(SquadNames, "7", "Golf", true);
	SetTrieString(SquadNames, "8", "Hotel", true);
	SetTrieString(SquadNames, "9", "India", true);
	SetTrieString(SquadNames, "10", "Juliet", true);
	SetTrieString(SquadNames, "11", "Kilo", true);
	SetTrieString(SquadNames, "12", "Lima", true);
	SetTrieString(SquadNames, "13", "Mike", true);
	SetTrieString(SquadNames, "14", "November", true);
	SetTrieString(SquadNames, "15", "Oscar", true);
	SetTrieString(SquadNames, "16", "Papa", true);
	SetTrieString(SquadNames, "17", "Quebec", true);
	SetTrieString(SquadNames, "18", "Romeo", true);
	SetTrieString(SquadNames, "19", "Sierra", true);
	SetTrieString(SquadNames, "20", "Tango", true);
	SetTrieString(SquadNames, "21", "Uniform", true);
	SetTrieString(SquadNames, "22", "Victor", true);
	SetTrieString(SquadNames, "23", "Whiskey", true);
	SetTrieString(SquadNames, "24", "X-Ray", true);
	SetTrieString(SquadNames, "25", "Yankee", true);
	SetTrieString(SquadNames, "26", "Zulu", true);
	decl String:squad[64], String:squadname[64];
	IntToString(out, squad ,sizeof(squad));
	GetTrieString(SquadNames, squad, squadname, sizeof(squadname));
	CloseHandle(SquadNames);
	strcopy(buffer, size, squadname);
	return out;
}

/**
* Retrieves a player's score
*
* @param client			Client Index
* @return				Player score
*/
stock GetPlayerScore(client)
{
	new ent = FindEntityByNetClass("CPlayerResource");
	new offset = FindSendPropOffs("CPlayerResource", "m_iScore");
	new out = GetEntData(ent, offset + (client*4), 4);
	return out;
}


/**
* Retrieves a player's class
*
* @param client			Client Index
* @return				Player class (0 is scout, 1 is rifleman, 2 is gren, 3 is engy, 5 is spec)
*/
stock GetPlayerClassNum(client)
{
	new ent = FindEntityByNetClass("CPlayerResource");
	new offset = FindSendPropOffs("CPlayerResource", "m_iClass");
	new out = GetEntData(ent, offset + (client*4), 4);
	return out;
}

/**
* Retrieves a player's class
*
* @param client			Client Index
* @param buffer			Buffer to hold the class name
* @param size			Len of the buffer
* @return				Player class index
*/
stock GetPlayerClassName(client, String:buffer[], size)
{
	new ent = FindEntityByNetClass("CPlayerResource");
	new offset = FindSendPropOffs("CPlayerResource", "m_iClass");
	new out = GetEntData(ent, offset + (client*4), 4);
	new Handle:ClassNames = CreateTrie();
	SetTrieString(ClassNames, "0", "Scout", true);
	SetTrieString(ClassNames, "1", "Rifleman", true);
	SetTrieString(ClassNames, "2", "Grenadier", true);
	SetTrieString(ClassNames, "3", "Engineer", true);
	SetTrieString(ClassNames, "4", "Unknown", true);
	SetTrieString(ClassNames, "5", "None", true);
	decl String:class[64], String:classname2[64];
	IntToString(out, class ,sizeof(class));
	GetTrieString(ClassNames, class, classname2, sizeof(classname2));
	CloseHandle(ClassNames);
	strcopy(buffer, size, classname2);
	return out;
}















/*****************************
* --> Find Entity Stocks <-- *
*****************************/

/**
* Searches for an entity based on classname.
*
* @param classname			Classname to search for
* @param startpoint			Where to start the search
* @return					Entity index
*/
stock FindEntityByClass(String:classname[], startpoint=1){
	decl String:EntClassname[128];
	new ent = 0;
	for(new i=startpoint;i<=GetMaxEntities();i++){
        if(IsValidEntity(i)){
            GetEdictClassname(i,EntClassname,128);
            if(StrEqual(classname,EntClassname)){
                ent = i;
                break;
            }
        }
    }
	return ent;
}


/**
* Searches for an entity based on net class.
*
* @param netclass			Net Class to search for
* @param startpoint			Where to start the search
* @return					Entity index
*/
stock FindEntityByNetClass(String:netclass[], startpoint=1){
	decl String:EntClassname[128];
	new ent = 0;
	for(new i=startpoint;i<=GetMaxEntities();i++){
        if(IsValidEntity(i)){
            GetEntityNetClass(i,EntClassname,128);
            if(StrEqual(netclass,EntClassname)){
                ent = i;
                break;
            }
        }
    }
	return ent;
}