// player spawn script

if (not (local player)) exitwith {};
_player = player;
Sleep 0.1;

//jail script for teamkillers
if (jailparam == 1) then
{
	if (alive jailme) then
	{
		deletevehicle jailme;
	};
	myscore = score player;
	_jailpos = getmarkerpos "Respawn_West";
	jailme = createTrigger ["EmptyDetector", [_jailpos select 0, 	_jailpos select 1, _jailpos select 2]];
	jailme setTriggerActivation ["NONE", "PRESENT", false];
	jailme setTriggerStatements ["score player < myscore and score player < -1", "jailed = player execVM ""scripts\transfer\jail.sqf""", ""];
};


disableUserInput false;
waitUntil {(!(isNull player) and (EGG_pinit==1))}; // Wait for player to initialize
//waitUntil {!(isNull player)}; 
//normal loadout management if EWDB is OFF
if (EWDB_on < 1) then
{
	_weps = [player,loadout] spawn loadLoadout;
};
Sleep 0.2;
player setSkill EGG_EVO_PlayerSkill;

_player addEventHandler ["killed", {handle = [_this select 0] execVM "scripts\bury.sqf"}];

if (killcam ==1) then 
{
	_player addEventHandler ["killed", {handle = [(_this select 0),(_this select 1)] execVM "scripts\killed.sqf"}];
};

Sleep 0.2;
0 setFog 0;
0 setOvercast 0;
0 setRain 0;

//adding functions for each class
_playertype = typeOf (vehicle player);
Sleep 0.2;
if (perkparam == 1) then {_actionId8 = player addAction [("<t color='#855009'>" + "#Build Foxhole" + "</t>"), "actions\static\makestatic.sqf",[_this,9],0, false, true,"test2"]};
if (perkparam == 1) then {_actionId8 = player addAction [("<t color='#855009'>" + "#Place Obstacle" + "</t>"), "actions\static\makestatic.sqf",[_this,10],0, false, true,"test2"]};

if (_playertype in EGG_EVO_PlayerMedic) then {_actionId8 = player addAction [("<t color='#855009'>" + "#" + localize "STR_M04t52" + "</t>"), "actions\mtent.sqf",0,0, false, true,"test2"]};
if (_playertype in EGG_EVO_PlayerEng) then {_actionId8 = player addAction [("<t color='#855009'>" + "#" + localize "STR_M04t53" + "</t>"), "actions\etent.sqf",0,0, false, true,"test2"]};
if (_playertype in EGG_EVO_PlayerOff) then {_actionId8 = player addAction [("<t color='#855009'>" + "#Deploy Recon HQ" + "</t>"), "actions\ambtent.sqf",0,0, false, true,"test2"]};
if ((_playertype in EGG_EVO_PlayerOff) and (perkparam == 1)) then {_actionId8 = player addAction [("<t color='#855009'>" + "#Build Mortar" + "</t>"), "actions\static\makestatic.sqf",[_this,8],0, false, true,"test2"]};

if ((_playertype in EGG_EVO_PlayerGL) and (perkparam == 1)) then {_actionId8 = player addAction [("<t color='#855009'>" + "#Build GL Nest" + "</t>"), "actions\static\makestatic.sqf",[_this,2],0, false, true,"test2"]};
if ((_playertype in EGG_EVO_PlayerAA) and (perkparam == 1)) then {_actionId8 = player addAction [("<t color='#855009'>" + "#Build Anti-Air Nest" + "</t>"), "actions\static\makestatic.sqf",[_this,3],0, false, true,"test2"]};
if ((_playertype in EGG_EVO_PlayerAT) and (perkparam == 1)) then {_actionId8 = player addAction [("<t color='#855009'>" + "#Build Anti-Tank Nest" + "</t>"), "actions\static\makestatic.sqf",[_this,4],0, false, true,"test2"]};
if ((_playertype in EGG_EVO_PlayerMG) and (perkparam == 1)) then {_actionId8 = player addAction [("<t color='#855009'>" + "#Build HMG Nest" + "</t>"), "actions\static\makestatic.sqf",[_this,5],0, false, true,"test2"]};

_score = score _player;

//enable normal ammobox
if (EWDB_on <1) then
{
	if ((score player)<50) then 
	{
		hint "Remember: Save kit at an ammo crate, ReconHQ or Respawn flag.";
	};
	if ((score player)<1) then 
	{
		_loadout = [player] call saveLoadout;
	};
};

//_playerh = (getposASL player) select 2;
//if (_playerh < 1500) then 
//{
	//(FindDisplay 46) DisplaySetEventHandler ["keydown","if ((_this select 1) In actionKeys ""TeamSwitch"") then {a = createDialog 'evoUI'}"];
	setViewDistance EGG_EVO_vdist;
//};



//temp turned off
//if ((_playertype in EGG_EVO_PlayerSniper) and (perkparam == 1)) then {_actionId8 = player addAction [("<t color='#855009'>" + "#Short Ladder" + "</t>"), "actions\static\makestatic.sqf",[_this,0],0, false, true,"test2"]};
//if ((_playertype in EGG_EVO_PlayerSniper) and (perkparam == 1)) then {_actionId8 = player addAction [("<t color='#855009'>" + "#Long Ladder" + "</t>"), "actions\static\makestatic.sqf",[_this,1],0,false, true,"test2"]};
if ((_playertype in EGG_EVO_PlayerSniper) and (perkparam == 1)) then {_actionId8 = player addAction [("<t color='#855009'>" + "#Build Camo Net" + "</t>"), "actions\static\makestatic.sqf",[_this,6],0, false, true,"test2"]};

//if ((_playertype in EGG_EVO_PlayerPilot) and (perkparam == 1)) then {_actionId8 = player addAction [("<t color='#855009'>" + "#Build Refuel Point" + "</t>"), "actions\static\makestatic.sqf",[_this,7],0, false, true,"test2"]};
//if ((_playertype in EGG_EVO_PlayerPilot) and (perkparam == 1) and (gitsnades == 1)) then {_actionId8 = player addAction ["GPS/INS Menu", "actions\GPSINS.sqf",[],0, false, true,"test2"]};//_gpsd = createDialog 'glt_airgpsmfd';
//if ((_playertype in EGG_EVO_PlayerSniper) and (perkparam == 1) and (gitsnades == 1)) then {_actionId8 = player addAction ["GPS/INS Menu", "actions\GPSINS.sqf",[],0, false, true,"test2"]};
//if ((perkparam == 1) and (gitsnades == 1)) then {_monitor = [] execVM "Actions\EB_resources_scripts\killinit.sqf"};
//fix T menu for HALO user
